Skip to content

Commit 04ff86e

Browse files
committed
FIX: fallback to viewlims if no data
1 parent 7875bc5 commit 04ff86e

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
@@ -2430,6 +2430,16 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
24302430
dl.extend(y_finite)
24312431

24322432
bb = mtransforms.BboxBase.union(dl)
2433+
# fall back on the viewlimits if this is not finite:
2434+
vl = None
2435+
if not np.isfinite(bb.intervalx).all():
2436+
vl = mtransforms.BboxBase.union([ax.viewLim for ax in shared])
2437+
bb.intervalx = vl.intervalx
2438+
if not np.isfinite(bb.intervaly).all():
2439+
if vl is None:
2440+
vl = mtransforms.BboxBase.union(
2441+
[ax.viewLim for ax in shared])
2442+
bb.intervaly = vl.intervaly
24332443
x0, x1 = getattr(bb, interval)
24342444
locator = axis.get_major_locator()
24352445
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
@@ -6270,3 +6270,16 @@ def test_minor_accountedfor():
62706270
targetbb = mtransforms.Bbox.from_bounds(*targets[n])
62716271
assert_allclose(bbspines[n * 2].bounds, targetbb.bounds,
62726272
atol=1e-2)
6273+
6274+
6275+
def test_datetime_masked():
6276+
# make sure that all-masked data falls back to the viewlim
6277+
# set in convert.axisinfo....
6278+
x = np.array([datetime.datetime(2017, 1, n) for n in range(1, 6)])
6279+
y = np.array([1, 2, 3, 4, 5])
6280+
m = np.ma.masked_greater(y, 0)
6281+
6282+
fig, ax = plt.subplots()
6283+
ax.plot(x, m)
6284+
# these are the default viewlim
6285+
assert ax.get_xlim() == (730120.0, 733773.0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy