From 56b791be322723f20f90bfd6632862624eed3eda Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 28 Jun 2024 07:02:52 -0400 Subject: [PATCH] Fix autoscaling with axhspan This only triggers when the normal (without an `axhspan` call) autolimits are far from 0, so modify a test to match that. --- lib/matplotlib/axes/_axes.py | 2 +- lib/matplotlib/tests/test_axes.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 328dda4a6a71..5e69bcb57d7f 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -1028,7 +1028,7 @@ def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs): # For Rectangles and non-separable transforms, add_patch can be buggy # and update the x limits even though it shouldn't do so for an # yaxis_transformed patch, so undo that update. - ix = self.dataLim.intervalx + ix = self.dataLim.intervalx.copy() mx = self.dataLim.minposx self.add_patch(p) self.dataLim.intervalx = ix diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 48121ee04939..13c181b68492 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -8250,10 +8250,10 @@ def test_relative_ticklabel_sizes(size): def test_multiplot_autoscale(): fig = plt.figure() ax1, ax2 = fig.subplots(2, 1, sharex='all') - ax1.scatter([1, 2, 3, 4], [2, 3, 2, 3]) + ax1.plot([18000, 18250, 18500, 18750], [2, 3, 2, 3]) ax2.axhspan(-5, 5) xlim = ax1.get_xlim() - assert np.allclose(xlim, [0.5, 4.5]) + assert np.allclose(xlim, [18000, 18800]) def test_sharing_does_not_link_positions():