diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index eaf94407e1ea..251cc32f362a 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5291,9 +5291,7 @@ def get_interp_point(idx): np.column_stack([ind[where], dep2[where]])]) if ind_dir == "y": pts = pts[:, ::-1] - self.dataLim.update_from_data_xy(pts, self.ignore_existing_data_limits, - updatex=True, updatey=True) - self.ignore_existing_data_limits = False + self.update_datalim(pts, updatex=True, updatey=True) self.add_collection(collection, autolim=False) self._request_autoscale_view() return collection diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index e83f69f54445..90e14580bfc2 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2144,7 +2144,7 @@ def update_datalim(self, xys, updatex=True, updatey=True): Whether to update the x/y limits. """ xys = np.asarray(xys) - if not len(xys): + if not np.any(np.isfinite(xys)): return self.dataLim.update_from_data_xy(xys, self.ignore_existing_data_limits, updatex=updatex, updatey=updatey) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 33a4fe2914f9..1d50b1bf2cf0 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -779,6 +779,23 @@ def test_nonfinite_limits(): ax.plot(x, y) +@pytest.mark.style('default') +@pytest.mark.parametrize('plot_fun', + ['scatter', 'plot', 'fill_between']) +@check_figures_equal(extensions=["png"]) +def test_limits_empty_data(plot_fun, fig_test, fig_ref): + # Check that plotting empty data doesn't change autoscaling of dates + x = np.arange("2010-01-01", "2011-01-01", dtype="datetime64[D]") + + ax_test = fig_test.subplots() + ax_ref = fig_ref.subplots() + + getattr(ax_test, plot_fun)([], []) + + for ax in [ax_test, ax_ref]: + getattr(ax, plot_fun)(x, range(len(x)), color='C0') + + @image_comparison(['imshow', 'imshow'], remove_text=True, style='mpl20') def test_imshow(): # use former defaults to match existing baseline image