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

Skip to content

Commit a067fc4

Browse files
committed
Make sticky edges only apply if the sticky edge is the most extream limit point
1 parent 54729db commit a067fc4

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,9 +2942,15 @@ def handle_single_axis(
29422942
# Index of largest element < x0 + tol, if any.
29432943
i0 = stickies.searchsorted(x0 + tol) - 1
29442944
x0bound = stickies[i0] if i0 != -1 else None
2945+
# Ensure the boundary acts only if the sticky is the extreme value
2946+
if x0bound is not None and x0bound > x0:
2947+
x0bound = None
29452948
# Index of smallest element > x1 - tol, if any.
29462949
i1 = stickies.searchsorted(x1 - tol)
29472950
x1bound = stickies[i1] if i1 != len(stickies) else None
2951+
# Ensure the boundary acts only if the sticky is the extreme value
2952+
if x1bound is not None and x1bound < x1:
2953+
x1bound = None
29482954

29492955
# Add the margin in figure space and then transform back, to handle
29502956
# non-linear scales.
3.85 KB
Loading

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)