Skip to content

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Oct 27, 2018

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 jklymak added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Oct 27, 2018
@Tillsten
Copy link
Contributor

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

@jklymak
Copy link
Member Author

jklymak commented Oct 27, 2018

@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 jklymak force-pushed the fix-ignore-non-finite-bbox branch from b8ba0c0 to 927b7c6 Compare October 27, 2018 20:50
@jklymak
Copy link
Member Author

jklymak commented Oct 27, 2018

@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 jklymak force-pushed the fix-ignore-non-finite-bbox branch from 927b7c6 to 07ac112 Compare October 28, 2018 02:34
@jklymak jklymak added this to the v3.0.x milestone Oct 28, 2018
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

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
Copy link
Member Author

jklymak commented Oct 28, 2018

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
Copy link
Member

timhoffm commented Oct 28, 2018

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
Copy link
Member Author

jklymak commented Oct 28, 2018

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

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

jklymak commented Oct 29, 2018

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

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

Has been addressed and API is not changed.

@anntzer 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 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)
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