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

include overspilling axes legends in ax.get_tightbbox by jklymak · Pull Request #9164 · matplotlib/matplotlib · GitHub

Repository navigation

include overspilling axes legends in ax.get_tightbbox - #9164

Merged
choldgraf merged 1 commit into
matplotlib:masterfrom
jklymak:fixgettightbox
Oct 21, 2017
Merged

choldgraf merged 1 commit into
matplotlib:masterfrom
jklymak:fixgettightbox

Conversation

jklymak commented Sep 7, 2017 •
edited
Loading

Copy link
Copy Markdown
Member

PR Summary

Expands ax.get_tightbbox to include legends.

Now something like

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(tight_layout=True)
ax.plot(range(10), label="Plot 1")
ax.plot(range(10, 0, -1), label="Plot 2")
ax.legend(loc='center right', bbox_to_anchor=(1.20, 0.5))
plt.show()

will automatically make room for the legend (via tight_layout).

#9163
#9130

PR Checklist

  • Code is PEP 8 compliant

choldgraf commented Oct 17, 2017 •
edited
Loading

Copy link
Copy Markdown
Contributor

any idea why appveyor isn't happy?

IMO this is a super useful fix. This is an issue that is constantly coming up. I'd be +1 on backporting to the latest release since it's so simple...

quick other thought: another common "cut off" situation is when you add a figure title that's outside of the figure bounds...is there a straightforward way to capture that situation w/ a similar fix as you've got here?

jklymak commented Oct 17, 2017

Copy link
Copy Markdown
Member Author

@choldgraf The apveyor prob was just the same apveyor problem everyone has had. I'll rebase and resubmit. Its pretty trivial, and works fine w/ tight_layout...

jklymak commented Oct 17, 2017 •
edited
Loading

Copy link
Copy Markdown
Member Author

@choldgraf This modifies the tight box for an axes. A suptitle isn't attached to an axes, so tight_layout can't know where it is trivially. However, #9082 does handle suptitle.

jklymak requested a review from choldgraf October 17, 2017 19:00

dstansby 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

👍 (does this count as an API change? maybe something should go in what's new?)

choldgraf left a comment

Copy link
Copy Markdown
Contributor

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

LGTM as it's quite a simple fix, though perhaps @dstansby should merge as they probably know more about the tight-layout machinery than I do

jklymak commented Oct 19, 2017

Copy link
Copy Markdown
Member Author

I suppose its an API change. However, I would expect the number of folks using tight_layout and a legend that is supposed to spill out the axis is vanishingly small since it didn’t work before ;-). The only situation I can see is where someone set up the legend to overspill the axis, it didn’t work when they called tight_layout, but they left the legend position in there anyway.

I will add a what’s new entry, but I don’t think this will break much real-life usage.

jklymak commented Oct 19, 2017

Copy link
Copy Markdown
Member Author

jklymak commented Oct 21, 2017

Copy link
Copy Markdown
Member Author

@choldgraf Thanks for your help! Am I allowed to self-merge, or can you do it if you get a minute?

choldgraf merged commit d4ebfe4 into matplotlib:master Oct 21, 2017

Copy link
Copy Markdown
Contributor

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL