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

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Mar 4, 2019

PR Summary

Closes #11337

The following test would fail because the view limit was set from 0-1:

    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 = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(x, m)
    # these are the default viewlim
    assert ax.get_xlim() == (730120.0, 733773.0)

The issue was in autoscale_view, which never checked the axes.viewLim, even if the data lim came back undefined. This PR checks the viewlim and uses that if the datalim is not finite.

Note this issue is more generic than dates, but is most easily seen there because we can't have dates with ordinal values <1, and the default behaviour made it so such dates were the datalim.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak jklymak added this to the v3.1.1 milestone Mar 4, 2019
@jklymak
Copy link
Member Author

jklymak commented Mar 4, 2019

This is a bug fix. Could be re-milestoned to 3.1 if it gets in soon...

@@ -2430,6 +2430,12 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
dl.extend(y_finite)

bb = mtransforms.BboxBase.union(dl)
vl = mtransforms.BboxBase.union([ax.viewLim for ax in shared])
Copy link
Member

Choose a reason for hiding this comment

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

Optional: Could maybe go into the if.

Disadvantage: Would be duplicated for both ifs.
Advantage: Closer to the place of use. Gets only computed in the rare case that we need it (not that it would be a performance bottle neck.

Copy link
Member Author

Choose a reason for hiding this comment

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

Put it in the if and will only get computed once!

@timhoffm
Copy link
Member

timhoffm commented Mar 4, 2019

Flake8:

./lib/matplotlib/axes/_base.py:2436:18: E117 over-indented
./lib/matplotlib/axes/_base.py:2438:18: E117 over-indented
./lib/matplotlib/tests/test_axes.py:6278:20: E231 missing whitespace after ','
./lib/matplotlib/tests/test_axes.py:6278:22: E231 missing whitespace after ','
./lib/matplotlib/tests/test_axes.py:6278:24: E231 missing whitespace after ','
./lib/matplotlib/tests/test_axes.py:6278:26: E231 missing whitespace after ','
2     E117 over-indented
4     E231 missing whitespace after ','

@jklymak jklymak force-pushed the fix-fallback-viewlim branch 2 times, most recently from 5c2d2f3 to 04ff86e Compare March 4, 2019 23:09
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.

@jklymak jklymak force-pushed the fix-fallback-viewlim branch from 04ff86e to 740dda5 Compare March 8, 2019 18:03
@jklymak
Copy link
Member Author

jklymak commented Mar 8, 2019

Rebased on master...

Copy link
Member

@efiring efiring left a comment

Choose a reason for hiding this comment

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

I don't like the amount of code, both old and new, required in this function to handle odd cases; but it looks like the new part here does what's needed, so it's better than nothing. Maybe @anntzer will see a way to clean it all up and replace a dozen lines with a pair.

@anntzer
Copy link
Contributor

anntzer commented Mar 18, 2019

Sorry, no magic available for you on this snippet right now :)

@efiring efiring merged commit 0f31612 into matplotlib:master Mar 18, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Mar 18, 2019
jklymak added a commit that referenced this pull request Mar 18, 2019
…588-on-v3.1.x

Backport PR #13588 on branch v3.1.x (FIX: fallback to viewlims if no data)
@tacaswell tacaswell modified the milestones: v3.1.1, v3.1.0 Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot plot fully masked array against datetimes
5 participants