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

Skip to content

Remove duplicated computations in Axes.get_tightbbox. #16309

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
Jan 25, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 23, 2020

We previously called _update_title_position and ax.get_window_extent
twice. Don't do that.
(I labeled this as "performance" even though I doubt it is really significant.)

Small additional cleanups.

PR Summary

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

We previously called _update_title_position and ax.get_window_extent
twice.  Don't do that.

Small additional cleanups.
@@ -4388,18 +4387,13 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
bb.append(bb_yaxis)

self._update_title_position(renderer)

axbbox = self.get_window_extent(renderer)
bb.append(axbbox)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this already adds self.get_window_extent(), so we don't need to add it again below.

@jklymak
Copy link
Member

jklymak commented Jan 23, 2020

This might be OK, but you should be sure to test by resizing a window...

@anntzer
Copy link
Contributor Author

anntzer commented Jan 23, 2020

What case are you worried about?

@jklymak
Copy link
Member

jklymak commented Jan 23, 2020

Constrained_layout needs to be called a couple of times, the first time gets everything close, but you need the second call because if you change the size of the axes the tick labels can change. Wasn't sure if something similar is needed here.

@anntzer
Copy link
Contributor Author

anntzer commented Jan 23, 2020

I mean, sure I can do interactive tests, but I have no intuition what kind of setup/plots could trigger buggy behavior where the duplicate call is needed.

@jklymak
Copy link
Member

jklymak commented Jan 23, 2020

One on the border of 7 ticks versus 6 or where the number of decimal places in the ticks will change? I know thats vague.

But looking at this more carefully, its calling getting the extent twice in the same loop, so I agree thats redundant.

bb.append(self._right_title.get_window_extent(renderer))

bb.append(self.get_window_extent(renderer))
for title in [self.title, self._left_title, self._right_title]:
Copy link
Member

@timhoffm timhoffm Jan 24, 2020

Choose a reason for hiding this comment

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

Could extend bb with a list comprehension, if you‘re up to it.

@tacaswell tacaswell added this to the v3.3.0 milestone Jan 25, 2020
@tacaswell tacaswell merged commit 3ee0219 into matplotlib:master Jan 25, 2020
@anntzer anntzer deleted the doubletight branch January 25, 2020 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants