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

Skip to content

Make API of get_tightbbox more consistent between Axes and Axis. #17287

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 2 commits into from
May 8, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Apr 30, 2020

Instead of having Axes trying to figure out what direction to ignore,
let the Axis handle that. This keeps the signature of get_tightbbox
consistent between Axes and Axis.

Also fix a typo bb_xaxis -> bb_yaxis.

Followup to #17222; was discussed briefly in #17222 (comment) though not acted upon. Even if we decide not to go that route at least the bb_xaxis->bb_yaxis change should be split out and merged for 3.3.

Marked as release critical so that we don't change the API after the release, if we decide to go this route.

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

@anntzer anntzer added Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: geometry manager LayoutEngine, Constrained layout, Tight layout labels Apr 30, 2020
@anntzer anntzer added this to the v3.3.0 milestone Apr 30, 2020
@QuLogic QuLogic requested a review from jklymak May 1, 2020 00:58
try:
bb_yaxis = self.yaxis.get_tightbbox(renderer, ignore_label=igl)
bb_yaxis = self.yaxis.get_tightbbox(
Copy link
Member

Choose a reason for hiding this comment

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

Oops!

@@ -1079,15 +1079,15 @@ def _get_tick_bboxes(self, ticks, renderer):
[tick.label2.get_window_extent(renderer)
for tick in ticks if tick.label2.get_visible()])

def get_tightbbox(self, renderer, *, ignore_label=None):
def get_tightbbox(self, renderer, *, for_layout_only=False):
Copy link
Member

Choose a reason for hiding this comment

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

I'm 50/50 on this change. Consistency is nice, OTOH, the kwarg name doesn't make a lot of sense at this level. But since the docs refer to *_layout maybe its OK.

bb.y0 = (bb.y0 + bb.y1) / 2 - 0.5
bb.y1 = bb.y0 + 1.0
if for_layout_only:
if self.axis_name == "x" and bb.width > 0:
Copy link
Member

Choose a reason for hiding this comment

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

... and I guess I still don't particularly like the introspection. But, again if other folks think the consistency is more important than explicitness I won't block.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe a bit of paranoia here with axis_name = getattr(self, 'axis_name', '')?

Instead of having Axes trying to figure out what direction to ignore,
let the Axis handle that.  This keeps the signature of get_tightbbox
consistent between Axes and Axis.

Also fix a typo bb_xaxis -> bb_yaxis.
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

I guess this is fine.

@tacaswell
Copy link
Member

The axis_name attribute has been on the Axis sub-classes from ~2007 (426eabc) but we don't seem to use it in the codebase.

I am 👍 on making more use of that introspection.

I'm +0.75 on the new name. It is less explicit about what it is doing, but it is more explicit about why it is doing it.

@anntzer
Copy link
Contributor Author

anntzer commented May 7, 2020

Added the change in #16981 (comment) as a separate commit.

@QuLogic QuLogic merged commit fbbc84f into matplotlib:master May 8, 2020
@anntzer anntzer deleted the tbb branch May 8, 2020 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants