Skip to content

Commit 9bd176d

Browse files
committed
FIX: make sticky edge tolerance relative to data range
1 parent 9b8a8c7 commit 9bd176d

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2962,22 +2962,16 @@ def handle_single_axis(
29622962

29632963
# Prevent margin addition from crossing a sticky value. A small
29642964
# tolerance must be added due to floating point issues with
2965-
# streamplot; it is defined relative to x0, x1, x1-x0 but has
2965+
# streamplot; it is defined relative to x1-x0 but has
29662966
# no absolute term (e.g. "+1e-8") to avoid issues when working with
29672967
# datasets where all values are tiny (less than 1e-8).
2968-
tol = 1e-5 * max(abs(x0), abs(x1), abs(x1 - x0))
2968+
tol = 1e-5 * abs(x1 - x0)
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
29752972
# Index of smallest element > x1 - tol, if any.
29762973
i1 = stickies.searchsorted(x1 - tol)
29772974
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
29812975

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

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,16 @@ def test_sticky_tolerance():
701701
axs.flat[3].barh(y=1, width=width, left=-20000.1)
702702

703703

704+
@image_comparison(['sticky_tolerance_cf.png'], remove_text=True, style="mpl20")
705+
def test_sticky_tolerance_contourf():
706+
fig, ax = plt.subplots()
707+
708+
x = y = [14496.71, 14496.75]
709+
data = [[0, 1], [2, 3]]
710+
711+
ax.contourf(x, y, data)
712+
713+
704714
def test_nargs_stem():
705715
with pytest.raises(TypeError, match='0 were given'):
706716
# stem() takes 1-3 arguments.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy