Skip to content

Commit 4881020

Browse files
authored
Merge pull request matplotlib#24181 from meeseeksmachine/auto-backport-of-pr-24177-on-v3.6.x
Backport PR matplotlib#24177 on branch v3.6.x (Don't simplify paths used for autoscaling)
2 parents 2ca3410 + 9696aeb commit 4881020

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2434,7 +2434,7 @@ def _update_patch_limits(self, patch):
24342434
# Get all vertices on the path
24352435
# Loop through each segment to get extrema for Bezier curve sections
24362436
vertices = []
2437-
for curve, code in p.iter_bezier():
2437+
for curve, code in p.iter_bezier(simplify=False):
24382438
# Get distance along the curve of any extrema
24392439
_, dzeros = curve.axis_aligned_extrema()
24402440
# Calculate vertices of start, end and any extrema in between

lib/matplotlib/tests/test_axes.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8114,6 +8114,58 @@ def test_bezier_autoscale():
81148114
assert ax.get_ylim()[0] == -0.5
81158115

81168116

8117+
def test_small_autoscale():
8118+
# Check that paths with small values autoscale correctly #24097.
8119+
verts = np.array([
8120+
[-5.45, 0.00], [-5.45, 0.00], [-5.29, 0.00], [-5.29, 0.00],
8121+
[-5.13, 0.00], [-5.13, 0.00], [-4.97, 0.00], [-4.97, 0.00],
8122+
[-4.81, 0.00], [-4.81, 0.00], [-4.65, 0.00], [-4.65, 0.00],
8123+
[-4.49, 0.00], [-4.49, 0.00], [-4.33, 0.00], [-4.33, 0.00],
8124+
[-4.17, 0.00], [-4.17, 0.00], [-4.01, 0.00], [-4.01, 0.00],
8125+
[-3.85, 0.00], [-3.85, 0.00], [-3.69, 0.00], [-3.69, 0.00],
8126+
[-3.53, 0.00], [-3.53, 0.00], [-3.37, 0.00], [-3.37, 0.00],
8127+
[-3.21, 0.00], [-3.21, 0.01], [-3.05, 0.01], [-3.05, 0.01],
8128+
[-2.89, 0.01], [-2.89, 0.01], [-2.73, 0.01], [-2.73, 0.02],
8129+
[-2.57, 0.02], [-2.57, 0.04], [-2.41, 0.04], [-2.41, 0.04],
8130+
[-2.25, 0.04], [-2.25, 0.06], [-2.09, 0.06], [-2.09, 0.08],
8131+
[-1.93, 0.08], [-1.93, 0.10], [-1.77, 0.10], [-1.77, 0.12],
8132+
[-1.61, 0.12], [-1.61, 0.14], [-1.45, 0.14], [-1.45, 0.17],
8133+
[-1.30, 0.17], [-1.30, 0.19], [-1.14, 0.19], [-1.14, 0.22],
8134+
[-0.98, 0.22], [-0.98, 0.25], [-0.82, 0.25], [-0.82, 0.27],
8135+
[-0.66, 0.27], [-0.66, 0.29], [-0.50, 0.29], [-0.50, 0.30],
8136+
[-0.34, 0.30], [-0.34, 0.32], [-0.18, 0.32], [-0.18, 0.33],
8137+
[-0.02, 0.33], [-0.02, 0.32], [0.13, 0.32], [0.13, 0.33], [0.29, 0.33],
8138+
[0.29, 0.31], [0.45, 0.31], [0.45, 0.30], [0.61, 0.30], [0.61, 0.28],
8139+
[0.77, 0.28], [0.77, 0.25], [0.93, 0.25], [0.93, 0.22], [1.09, 0.22],
8140+
[1.09, 0.19], [1.25, 0.19], [1.25, 0.17], [1.41, 0.17], [1.41, 0.15],
8141+
[1.57, 0.15], [1.57, 0.12], [1.73, 0.12], [1.73, 0.10], [1.89, 0.10],
8142+
[1.89, 0.08], [2.05, 0.08], [2.05, 0.07], [2.21, 0.07], [2.21, 0.05],
8143+
[2.37, 0.05], [2.37, 0.04], [2.53, 0.04], [2.53, 0.02], [2.69, 0.02],
8144+
[2.69, 0.02], [2.85, 0.02], [2.85, 0.01], [3.01, 0.01], [3.01, 0.01],
8145+
[3.17, 0.01], [3.17, 0.00], [3.33, 0.00], [3.33, 0.00], [3.49, 0.00],
8146+
[3.49, 0.00], [3.65, 0.00], [3.65, 0.00], [3.81, 0.00], [3.81, 0.00],
8147+
[3.97, 0.00], [3.97, 0.00], [4.13, 0.00], [4.13, 0.00], [4.29, 0.00],
8148+
[4.29, 0.00], [4.45, 0.00], [4.45, 0.00], [4.61, 0.00], [4.61, 0.00],
8149+
[4.77, 0.00], [4.77, 0.00], [4.93, 0.00], [4.93, 0.00],
8150+
])
8151+
8152+
minx = np.min(verts[:, 0])
8153+
miny = np.min(verts[:, 1])
8154+
maxx = np.max(verts[:, 0])
8155+
maxy = np.max(verts[:, 1])
8156+
8157+
p = mpath.Path(verts)
8158+
8159+
fig, ax = plt.subplots()
8160+
ax.add_patch(mpatches.PathPatch(p))
8161+
ax.autoscale()
8162+
8163+
assert ax.get_xlim()[0] <= minx
8164+
assert ax.get_xlim()[1] >= maxx
8165+
assert ax.get_ylim()[0] <= miny
8166+
assert ax.get_ylim()[1] >= maxy
8167+
8168+
81178169
def test_get_xticklabel():
81188170
fig, ax = plt.subplots()
81198171
ax.plot(np.arange(10))

0 commit comments

Comments
 (0)