diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index f83999436cbb..17feef5b2105 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2962,22 +2962,16 @@ def handle_single_axis( # 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 + # streamplot; it is defined relative to 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)) + tol = 1e-5 * abs(x1 - x0) # 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. diff --git a/lib/matplotlib/tests/baseline_images/test_axes/sticky_tolerance_cf.png b/lib/matplotlib/tests/baseline_images/test_axes/sticky_tolerance_cf.png new file mode 100644 index 000000000000..a2e185c2769d Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/sticky_tolerance_cf.png differ diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 3c0407ee4098..f18e05dc2f1e 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -701,6 +701,16 @@ def test_sticky_tolerance(): axs.flat[3].barh(y=1, width=width, left=-20000.1) +@image_comparison(['sticky_tolerance_cf.png'], remove_text=True, style="mpl20") +def test_sticky_tolerance_contourf(): + fig, ax = plt.subplots() + + x = y = [14496.71, 14496.75] + data = [[0, 1], [2, 3]] + + ax.contourf(x, y, data) + + def test_nargs_stem(): with pytest.raises(TypeError, match='0 were given'): # stem() takes 1-3 arguments.