Skip to content

Fix limit setting after plotting empty data #17781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

@jklymak jklymak Jun 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this method get a comment that its usually meant to be called by Axes.update_datalim? We need more breadcrumbs for developers so they don't get lost amongst the many levels of redirection....

Ooops scrub that, I see that is a bbox method so general enough that folks shouldn't be looking there for axes-specific methods.

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
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,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)
Expand Down
17 changes: 17 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down