FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

FIX: ignore non-finite bbox by jklymak · Pull Request #12651 · matplotlib/matplotlib · GitHub

Repository navigation

FIX: ignore non-finite bbox - #12651

Merged
anntzer merged 2 commits into
matplotlib:masterfrom
jklymak:fix-ignore-non-finite-bbox
Oct 29, 2018
Merged

anntzer merged 2 commits into
matplotlib:masterfrom
jklymak:fix-ignore-non-finite-bbox

Conversation

jklymak commented Oct 27, 2018 •
edited
Loading

Copy link
Copy Markdown
Member

PR Summary

closes #12648

def test_gettightbbox_ignoreNaN():
     fig, ax = plt.subplots()
     t = ax.text(np.NaN, 1, 'Boo')
     renderer = fig.canvas.get_renderer()
     np.testing.assert_allclose(ax.get_tightbbox(renderer).width, 532.13194)

Previously, ax.get_tightbbox would find a non-finite bbox because text's bbox was not defined. This ignores such bbox's when getting the axes bbox.

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 added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Oct 27, 2018

Copy link
Copy Markdown
Contributor

Why not let get_tightbox return None instead working around the non-finite bbox?

jklymak commented Oct 27, 2018

Copy link
Copy Markdown
Member Author

@Tillsten you mean get_tightbbox of the axes children? I think thats a good idea as well, but I wasn't sure I'd be able to squash all possible get_tightbbox implementations.

I think I'll do that for the base Artist.get_tightbbox, but maybe keep this check too in case someone has done something special.

jklymak force-pushed the fix-ignore-non-finite-bbox branch from b8ba0c0 to 927b7c6 Compare October 27, 2018 20:50

jklymak commented Oct 27, 2018

Copy link
Copy Markdown
Member Author

@Tillsten added the check in both places now. The one in Axes._get_tightbbox can't hurt (except maybe the eyes for the long if-statement).

jklymak force-pushed the fix-ignore-non-finite-bbox branch from 927b7c6 to 07ac112 Compare October 28, 2018 02:34
jklymak added this to the v3.0.x milestone Oct 28, 2018

timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Returning None instead of an infinite BBox is an API change. I'm -1 on that as I don't see any benefit. In contrast, it obscures information. An infinite BBox is a defined object. You can e.g. still find out if the width or height is infinite.

jklymak commented Oct 28, 2018 •
edited by timhoffm
Loading

Copy link
Copy Markdown
Member Author

Yeah I’m flexible about that. The original PR didn’t have this - it just checked for finite bbox widths and heights.

OTOH it’s not necessarily a bad idea to invalidate things we know we can’t do anything with. A NaN bbox width is not going to mean anything and pushing all the checks to a higher level just means more checks at a higher level.

timhoffm commented Oct 28, 2018 •
edited
Loading

Copy link
Copy Markdown
Member

A NaN bbox width is not going to mean anything and pushing all the checks to a higher level just means more checks at a higher level.

You'll have a new bbox is None check to do anyway at the higher level. If desired you could alternatively add an is_finite() method and check bbox.is_finite(). (Or maybe is_valid() - Qt uses this naming convention.)

Edit: Would need careful consideration on the actual naming of such a method.

jklymak commented Oct 28, 2018

Copy link
Copy Markdown
Member Author

Right but we already check for None. Not sure why, though.

jklymak force-pushed the fix-ignore-non-finite-bbox branch from 07ac112 to d2523e0 Compare October 29, 2018 16:31
jklymak force-pushed the fix-ignore-non-finite-bbox branch from d2523e0 to 49570b4 Compare October 29, 2018 16:32

jklymak commented Oct 29, 2018

Copy link
Copy Markdown
Member Author

Removed artist.get_tightbbox returning None if non-finite bbox.

tacaswell dismissed timhoffm’s stale review October 29, 2018 19:34

Has been addressed and API is not changed.

anntzer merged commit 41f72fb into matplotlib:master Oct 29, 2018
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Oct 29, 2018
jklymak deleted the fix-ignore-non-finite-bbox branch October 29, 2018 19:37
jklymak added a commit that referenced this pull request Oct 29, 2018
…651-on-v3.0.x

Backport PR #12651 on branch v3.0.x (FIX: ignore non-finite bbox)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: geometry manager LayoutEngine, Constrained layout, Tight layout

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression when calling annotate with nan values for the position

5 participants


Back | FazBrowse Home | New Git URL