Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 740dda5

Browse files
committed
FIX: fallback to viewlims if no data
1 parent 22bbbae commit 740dda5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/matplotlib/axes/_base.py

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

24412441
bb = mtransforms.BboxBase.union(dl)
2442+
# fall back on the viewlimits if this is not finite:
2443+
vl = None
2444+
if not np.isfinite(bb.intervalx).all():
2445+
vl = mtransforms.BboxBase.union([ax.viewLim for ax in shared])
2446+
bb.intervalx = vl.intervalx
2447+
if not np.isfinite(bb.intervaly).all():
2448+
if vl is None:
2449+
vl = mtransforms.BboxBase.union(
2450+
[ax.viewLim for ax in shared])
2451+
bb.intervaly = vl.intervaly
24422452
x0, x1 = getattr(bb, interval)
24432453
locator = axis.get_major_locator()
24442454
x0, x1 = locator.nonsingular(x0, x1)

lib/matplotlib/tests/test_axes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6281,3 +6281,16 @@ def test_axis_bool_arguments(fig_test, fig_ref):
62816281
ax.axis(False)
62826282
ax.axis(True)
62836283
fig_ref.add_subplot(212).axis("on")
6284+
6285+
6286+
def test_datetime_masked():
6287+
# make sure that all-masked data falls back to the viewlim
6288+
# set in convert.axisinfo....
6289+
x = np.array([datetime.datetime(2017, 1, n) for n in range(1, 6)])
6290+
y = np.array([1, 2, 3, 4, 5])
6291+
m = np.ma.masked_greater(y, 0)
6292+
6293+
fig, ax = plt.subplots()
6294+
ax.plot(x, m)
6295+
# these are the default viewlim
6296+
assert ax.get_xlim() == (730120.0, 733773.0)

0 commit comments

Comments
 (0)