Skip to content

Commit

Permalink
Backport PR matplotlib#28393: Make sticky edges only apply if the sti…
Browse files Browse the repository at this point in the history
…cky edge is the most extreme limit point
  • Loading branch information
QuLogic authored and meeseeksmachine committed Jun 27, 2024
1 parent 452626f commit c7997be
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2969,9 +2969,15 @@ def handle_single_axis(
# Index of largest element < x0 + tol, if any.
i0 = stickies.searchsorted(x0 + tol) - 1
x0bound = stickies[i0] if i0 != -1 else None
# Ensure the boundary acts only if the sticky is the extreme value
if x0bound is not None and x0bound > x0:
x0bound = None
# Index of smallest element > x1 - tol, if any.
i1 = stickies.searchsorted(x1 - tol)
x1bound = stickies[i1] if i1 != len(stickies) else None
# Ensure the boundary acts only if the sticky is the extreme value
if x1bound is not None and x1bound < x1:
x1bound = None

# Add the margin in figure space and then transform back, to handle
# non-linear scales.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,25 @@ def test_sticky_shared_axes(fig_test, fig_ref):
ax0.pcolormesh(Z)


@image_comparison(['sticky_tolerance.png'], remove_text=True, style="mpl20")
def test_sticky_tolerance():
fig, axs = plt.subplots(2, 2)

width = .1

axs.flat[0].bar(x=0, height=width, bottom=20000.6)
axs.flat[0].bar(x=1, height=width, bottom=20000.1)

axs.flat[1].bar(x=0, height=-width, bottom=20000.6)
axs.flat[1].bar(x=1, height=-width, bottom=20000.1)

axs.flat[2].barh(y=0, width=-width, left=-20000.6)
axs.flat[2].barh(y=1, width=-width, left=-20000.1)

axs.flat[3].barh(y=0, width=width, left=-20000.6)
axs.flat[3].barh(y=1, width=width, left=-20000.1)


def test_nargs_stem():
with pytest.raises(TypeError, match='0 were given'):
# stem() takes 1-3 arguments.
Expand Down

0 comments on commit c7997be

Please sign in to comment.