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

Skip to content

Commit 475d5b7

Browse files
QuLogicmeeseeksmachine
authored andcommitted
Backport PR #28487: Fix autoscaling with axhspan
1 parent 51decc5 commit 475d5b7

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
@@ -8195,10 +8195,10 @@ def test_relative_ticklabel_sizes(size):
81958195
def test_multiplot_autoscale():
81968196
fig = plt.figure()
81978197
ax1, ax2 = fig.subplots(2, 1, sharex='all')
8198-
ax1.scatter([1, 2, 3, 4], [2, 3, 2, 3])
8198+
ax1.plot([18000, 18250, 18500, 18750], [2, 3, 2, 3])
81998199
ax2.axhspan(-5, 5)
82008200
xlim = ax1.get_xlim()
8201-
assert np.allclose(xlim, [0.5, 4.5])
8201+
assert np.allclose(xlim, [18000, 18800])
82028202

82038203

82048204
def test_sharing_does_not_link_positions():

0 commit comments

Comments
 (0)