Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5067c1

Browse files
authored
Fix autoscaling with axhspan (#28487)
This only triggers when the normal (without an `axhspan` call) autolimits are far from 0, so modify a test to match that.
1 parent 00cbd9c commit f5067c1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs):
10281028
# For Rectangles and non-separable transforms, add_patch can be buggy
10291029
# and update the x limits even though it shouldn't do so for an
10301030
# yaxis_transformed patch, so undo that update.
1031-
ix = self.dataLim.intervalx
1031+
ix = self.dataLim.intervalx.copy()
10321032
mx = self.dataLim.minposx
10331033
self.add_patch(p)
10341034
self.dataLim.intervalx = ix

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8250,10 +8250,10 @@ def test_relative_ticklabel_sizes(size):
82508250
def test_multiplot_autoscale():
82518251
fig = plt.figure()
82528252
ax1, ax2 = fig.subplots(2, 1, sharex='all')
8253-
ax1.scatter([1, 2, 3, 4], [2, 3, 2, 3])
8253+
ax1.plot([18000, 18250, 18500, 18750], [2, 3, 2, 3])
82548254
ax2.axhspan(-5, 5)
82558255
xlim = ax1.get_xlim()
8256-
assert np.allclose(xlim, [0.5, 4.5])
8256+
assert np.allclose(xlim, [18000, 18800])
82578257

82588258

82598259
def test_sharing_does_not_link_positions():

0 commit comments

Comments
 (0)