Skip to content

Commit 329eb59

Browse files
authored
Merge pull request #17781 from dstansby/lim-set
Fix limit setting after plotting empty data
2 parents 8d2c16b + a77bb03 commit 329eb59

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

lib/matplotlib/axes/_axes.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -5295,9 +5295,7 @@ def get_interp_point(idx):
52955295
np.column_stack([ind[where], dep2[where]])])
52965296
if ind_dir == "y":
52975297
pts = pts[:, ::-1]
5298-
self.dataLim.update_from_data_xy(pts, self.ignore_existing_data_limits,
5299-
updatex=True, updatey=True)
5300-
self.ignore_existing_data_limits = False
5298+
self.update_datalim(pts, updatex=True, updatey=True)
53015299
self.add_collection(collection, autolim=False)
53025300
self._request_autoscale_view()
53035301
return collection

lib/matplotlib/axes/_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2152,7 +2152,7 @@ def update_datalim(self, xys, updatex=True, updatey=True):
21522152
Whether to update the x/y limits.
21532153
"""
21542154
xys = np.asarray(xys)
2155-
if not len(xys):
2155+
if not np.any(np.isfinite(xys)):
21562156
return
21572157
self.dataLim.update_from_data_xy(xys, self.ignore_existing_data_limits,
21582158
updatex=updatex, updatey=updatey)

lib/matplotlib/tests/test_axes.py

+17
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,23 @@ def test_nonfinite_limits():
779779
ax.plot(x, y)
780780

781781

782+
@pytest.mark.style('default')
783+
@pytest.mark.parametrize('plot_fun',
784+
['scatter', 'plot', 'fill_between'])
785+
@check_figures_equal(extensions=["png"])
786+
def test_limits_empty_data(plot_fun, fig_test, fig_ref):
787+
# Check that plotting empty data doesn't change autoscaling of dates
788+
x = np.arange("2010-01-01", "2011-01-01", dtype="datetime64[D]")
789+
790+
ax_test = fig_test.subplots()
791+
ax_ref = fig_ref.subplots()
792+
793+
getattr(ax_test, plot_fun)([], [])
794+
795+
for ax in [ax_test, ax_ref]:
796+
getattr(ax, plot_fun)(x, range(len(x)), color='C0')
797+
798+
782799
@image_comparison(['imshow', 'imshow'], remove_text=True, style='mpl20')
783800
def test_imshow():
784801
# use former defaults to match existing baseline image

0 commit comments

Comments
 (0)