Don't fallback to view limits when autoscale()ing no data. by anntzer · Pull Request #15258 · matplotlib/matplotlib · GitHub
Skip to content
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
32 changes: 18 additions & 14 deletions lib/matplotlib/axes/_base.py
8 changes: 8 additions & 0 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,10 @@ def nonsingular(self, vmin, vmax):
Given the proposed upper and lower extent, adjust the range
if it is too close to being singular (i.e. a range of ~0).
"""
if not np.isfinite(vmin) or not np.isfinite(vmax):
# Except if there is no data, then use 2000-2010 as default.
return (date2num(datetime.date(2000, 1, 1)),
date2num(datetime.date(2010, 1, 1)))
if vmax < vmin:
vmin, vmax = vmax, vmin
unit = self._get_unit()
Expand Down Expand Up @@ -1337,6 +1341,10 @@ def tick_values(self, vmin, vmax):
def nonsingular(self, vmin, vmax):
# whatever is thrown at us, we can scale the unit.
# But default nonsingular date plots at an ~4 year period.
if not np.isfinite(vmin) or not np.isfinite(vmax):
# Except if there is no data, then use 2000-2010 as default.
return (date2num(datetime.date(2000, 1, 1)),
date2num(datetime.date(2010, 1, 1)))
if vmax < vmin:
vmin, vmax = vmax, vmin
if vmin == vmax:
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,13 @@ def test_log_scales():
ax.set_xscale('log', basex=9.0)


def test_log_scales_no_data():
_, ax = plt.subplots()
ax.set(xscale="log", yscale="log")
ax.xaxis.set_major_locator(mticker.MultipleLocator(1))
assert ax.get_xlim() == ax.get_ylim() == (1, 10)


def test_log_scales_invalid():
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
Expand Down
14 changes: 13 additions & 1 deletion lib/matplotlib/ticker.py