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

Skip to content

FIX: fallback to viewlims if no data #13588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2439,6 +2439,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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have just stupidly recalculated vl. 😄 This only happens for the degenerate case that bb.intevalx and bb.intervaly contain non-finite values. IMHO preferable due to symmetry and simpler logic of the code.

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)
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6281,3 +6281,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)