8000 Don't fallback to view limits when autoscale()ing no data. · matplotlib/matplotlib@84448ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 84448ca

Browse files
committed
Don't fallback to view limits when autoscale()ing no data.
1 parent bebb206 commit 84448ca

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,16 +2409,6 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
24092409
dl.extend(y_finite)
24102410

24112411
bb = mtransforms.BboxBase.union(dl)
2412-
# fall back on the viewlimits if this is not finite:
2413-
vl = None
2414-
if not np.isfinite(bb.intervalx).all():
2415-
vl = mtransforms.BboxBase.union([ax.viewLim for ax in shared])
2416-
bb.intervalx = vl.intervalx
2417-
if not np.isfinite(bb.intervaly).all():
2418-
if vl is None:
2419-
vl = mtransforms.BboxBase.union(
2420-
[ax.viewLim for ax in shared])
2421-
bb.intervaly = vl.intervaly
24222412
x0, x1 = getattr(bb, interval)
24232413
locator = axis.get_major_locator()
24242414
x0, x1 = locator.nonsingular(x0, x1)

lib/matplotlib/dates.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,10 @@ def nonsingular(self, vmin, vmax):
11181118
Given the proposed upper and lower extent, adjust the range
11191119
if it is too close to being singular (i.e. a range of ~0).
11201120
"""
1121+
if not np.isfinite(vmin) or not np.isfinite(vmax):
1122+
# Except if there is no data, then use 2000-2010 as default.
1123+
return (date2num(datetime.date(2000, 1, 1)),
1124+
date2num(datetime.date(2010, 1, 1)))
11211125
if vmax < vmin:
11221126
vmin, vmax = vmax, vmin
11231127
unit = self._get_unit()
@@ -1337,6 +1341,10 @@ def tick_values(self, vmin, vmax):
13371341
def nonsingular(self, vmin, vmax):
13381342
# whatever is thrown at us, we can scale the unit.
13391343
# But default nonsingular date plots at an ~4 year period.
1344+
if not np.isfinite(vmin) or not np.isfinite(vmax):
1345+
# Except if there is no data, then use 2000-2010 as default.
1346+
return (date2num(datetime.date(2000, 1, 1)),
1347+
date2num(datetime.date(2010, 1, 1)))
13401348
if vmax < vmin:
13411349
vmin, vmax = vmax, vmin
13421350
if vmin == vmax:

lib/matplotlib/tests/test_axes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,12 @@ def test_log_scales():
21702170
ax.set_xscale('log', basex=9.0)
21712171

21722172

2173+
def test_log_scales_no_data():
2174+
_, ax = plt.subplots()
2175+
ax.set(xscale="log", yscale="log")
2176+
assert ax.get_xlim() == ax.get_ylim() == (1, 10)
2177+
2178+
21732179
def test_log_scales_invalid():
21742180
fig = plt.figure()
21752181
ax = fig.add_subplot(1, 1, 1)

lib/matplotlib/ticker.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,19 @@ def raise_if_exceeds(self, locs):
17101710
return locs
17111711

17121712
def nonsingular(self, v0, v1):
1713-
"""Expand a range as needed to avoid singularities."""
1713+
"""
1714+
Adjust a range as needed to avoid singularities.
1715+
1716+
This method gets called during autoscaling, with ``(v0, v1)`` set to
1717+
the data limits on the axes if the axes contains any data, or
1718+
``(-inf, +inf)`` if not.
1719+
1720+
- If ``v0 == v1`` (possibly up to some floating point slop), this
1721+
method returns an expanded interval around this value.
1722+
- If ``(v0, v1) == (-inf, +inf)``, this method returns appropriate
1723+
default view limits.
1724+
- Otherwise, ``(v0, v1)`` is returned without modification.
1725+
"""
17141726
return mtransforms.nonsingular(v0, v1, expander=.05)
17151727

17161728
def view_limits(self, vmin, vmax):

0 commit comments

Comments
 (0)
0