diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 0acba3e6044b..26d8df32e396 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2440,6 +2440,16 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval, dl.extend(y_finite) bb = mtransforms.BboxBase.union(dl) + # fall back on the viewlimits if this is not finite: + vl = None + if not np.isfinite(bb.intervalx).all(): + vl = mtransforms.BboxBase.union([ax.viewLim for ax in shared]) + bb.intervalx = vl.intervalx + if not np.isfinite(bb.intervaly).all(): + if vl is None: + vl = mtransforms.BboxBase.union( + [ax.viewLim for ax in shared]) + bb.intervaly = vl.intervaly x0, x1 = getattr(bb, interval) locator = axis.get_major_locator() x0, x1 = locator.nonsingular(x0, x1) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 8a46794ad304..9109740d415f 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -6296,3 +6296,16 @@ def test_axis_bool_arguments(fig_test, fig_ref): ax.axis(False) ax.axis(True) fig_ref.add_subplot(212).axis("on") + + +def test_datetime_masked(): + # make sure that all-masked data falls back to the viewlim + # set in convert.axisinfo.... + x = np.array([datetime.datetime(2017, 1, n) for n in range(1, 6)]) + y = np.array([1, 2, 3, 4, 5]) + m = np.ma.masked_greater(y, 0) + + fig, ax = plt.subplots() + ax.plot(x, m) + # these are the default viewlim + assert ax.get_xlim() == (730120.0, 733773.0)