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

Skip to content

FIX/ENH: include text in ax.get_tightbbox #10678

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

Closed
wants to merge 1 commit into from

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Mar 4, 2018

PR Summary

If text overflows an axes, ax.get_tightbbox doesn't include it.

Note this doesn't require constrained_layout to be a problem. Saving with bbox_inches='tight' will also cut the extra text off.. EDIT: This wasn't true - bbox_inches='tight' renders the figure and then figures out the bbox. But, I don't see why we wouldn't include over-spilling text in the tight bbox for an axes.

import matplotlib.pyplot as plt

fig, ax = plt.subplots(constrained_layout=True)
ax.set_xlim([0, 1])
ax.text(1, 0.5, 'This is a long overflow')
plt.show()

Before

fig2

After

fig1

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 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

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.

Looks good, subject to tests passing.

@jklymak
Copy link
Member Author

jklymak commented Mar 5, 2018

OK, actually, I'm a little confused now about the API for ax.get_tightbbox.

def get_tightbbox(self, renderer, call_axes_locator=True):

It says that it will Return the tight bounding box of the axes.. It gets its own window_extent and the extent of labels (i.e. titles, and the axises). I added Legend and someone else added OffsetBox. However, none of the other artists are part of the bbox. This PR adds text, but none of the other artists.

the tight_bbox for savefig is implemented in

for a in bbox_artists:

where all the artists are iterated through and added to the bbox. I guess I don't see why this functionality isn't moved into ax.get_tightbbox so other functions can take advantage? The only places this function get used (jnternally) is tight_layout and _constrained_layout.

Pros: are that dangling artists get counted for layout easily.

Cons: its possible that the user would want the layout to ignore some artists when making a layout. savefig(bbox_inches='tight)actually has another kwarg to take care of this: bbox_extra_artists`.

Comments?

@jklymak
Copy link
Member Author

jklymak commented Mar 5, 2018

Closing in lieu of #10682, which I think is a more comprehensive solution.

@jklymak jklymak closed this Mar 5, 2018
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.

2 participants