Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2545,15 +2545,17 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
locator = axis.get_major_locator()
x0, x1 = locator.nonsingular(x0, x1)

# Prevent margin addition from crossing a sticky value. Small
# tolerances (whose values come from isclose()) must be used due to
# floating point issues with streamplot.
def tol(x): return 1e-5 * abs(x) + 1e-8
# Prevent margin addition from crossing a sticky value. A small
# tolerance must be added due to floating point issues with
# streamplot; it is defined relative to x0, x1, x1-x0 but has
# no absolute term (e.g. "+1e-8") to avoid issues when working with
# datasets where all values are tiny (less than 1e-8).
tol = 1e-5 * max(abs(x0), abs(x1), abs(x1 - x0))
# Index of largest element < x0 + tol, if any.
i0 = stickies.searchsorted(x0 + tol(x0)) - 1
i0 = stickies.searchsorted(x0 + tol) - 1
x0bound = stickies[i0] if i0 != -1 else None
# Index of smallest element > x1 - tol, if any.
i1 = stickies.searchsorted(x1 - tol(x1))
i1 = stickies.searchsorted(x1 - tol)
x1bound = stickies[i1] if i1 != len(stickies) else None

# Add the margin in figure space and then transform back, to handle
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6314,3 +6314,11 @@ def test_polar_interpolation_steps_variable_r(fig_test, fig_ref):
l.get_path()._interpolation_steps = 100
fig_ref.add_subplot(projection="polar").plot(
np.linspace(0, np.pi/2, 101), np.linspace(1, 2, 101))


@pytest.mark.style('default')
def test_autoscale_tiny_sticky():
fig, ax = plt.subplots()
ax.bar(0, 1e-9)
fig.canvas.draw()
assert ax.get_ylim() == (0, 1.05e-9)