Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51decc5

Browse files
authored
Merge pull request #28483 from meeseeksmachine/auto-backport-of-pr-28393-on-v3.9.x
Backport PR #28393 on branch v3.9.x (Make sticky edges only apply if the sticky edge is the most extreme limit point)
2 parents 97b3b54 + c7997be commit 51decc5

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,9 +2969,15 @@ def handle_single_axis(
29692969
# Index of largest element < x0 + tol, if any.
29702970
i0 = stickies.searchsorted(x0 + tol) - 1
29712971
x0bound = stickies[i0] if i0 != -1 else None
2972+
# Ensure the boundary acts only if the sticky is the extreme value
2973+
if x0bound is not None and x0bound > x0:
2974+
x0bound = None
29722975
# Index of smallest element > x1 - tol, if any.
29732976
i1 = stickies.searchsorted(x1 - tol)
29742977
x1bound = stickies[i1] if i1 != len(stickies) else None
2978+
# Ensure the boundary acts only if the sticky is the extreme value
2979+
if x1bound is not None and x1bound < x1:
2980+
x1bound = None
29752981

29762982
# Add the margin in figure space and then transform back, to handle
29772983
# non-linear scales.

lib/matplotlib/tests/test_axes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,25 @@ def test_sticky_shared_axes(fig_test, fig_ref):
682682
ax0.pcolormesh(Z)
683683

684684

685+
@image_comparison(['sticky_tolerance.png'], remove_text=True, style="mpl20")
686+
def test_sticky_tolerance():
687+
fig, axs = plt.subplots(2, 2)
688+
689+
width = .1
690+
691+
axs.flat[0].bar(x=0, height=width, bottom=20000.6)
692+
axs.flat[0].bar(x=1, height=width, bottom=20000.1)
693+
694+
axs.flat[1].bar(x=0, height=-width, bottom=20000.6)
695+
axs.flat[1].bar(x=1, height=-width, bottom=20000.1)
696+
697+
axs.flat[2].barh(y=0, width=-width, left=-20000.6)
698+
axs.flat[2].barh(y=1, width=-width, left=-20000.1)
699+
700+
axs.flat[3].barh(y=0, width=width, left=-20000.6)
701+
axs.flat[3].barh(y=1, width=width, left=-20000.1)
702+
703+
685704
def test_nargs_stem():
686705
with pytest.raises(TypeError, match='0 were given'):
687706
# stem() takes 1-3 arguments.

0 commit comments

Comments
 (0)