10000 Merge pull request #13588 from jklymak/fix-fallback-viewlim · matplotlib/matplotlib@0f31612 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f31612

Browse files
authored
Merge pull request #13588 from jklymak/fix-fallback-viewlim
FIX: fallback to viewlims if no data
2 parents 4e51619 + 740dda5 commit 0f31612

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
@@ -6295,3 +6295,16 @@ def test_axis_bool_arguments(fig_test, fig_ref):
62956295
ax.axis(False)
62966296
ax.axis(True)
62976297
fig_ref.add_subplot(212).axis("on")
6298+
6299+
6300+
def test_datetime_masked():
6301+
# make sure that all-masked data falls back to the viewlim
6302+
# set in convert.axisinfo....
6303+
x = np.array([datetime.datetime(2017, 1, n) for n in range(1, 6)])
6304+
y = np.array([1, 2, 3, 4, 5])
6305+
m = np.ma.masked_greater(y, 0)
6306+
6307+
fig, ax = plt.subplots()
6308+
ax.plot(x, m)
6309+
# these are the default viewlim
6310+
assert ax.get_xlim() == (730120.0, 733773.0)

0 commit comments

Comments
 (0)
0