-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: constrained_layout and repeated calls to suptitle #11035
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,3 +344,43 @@ def test_constrained_layout20(): | |
ax = fig.add_axes([0, 0, 1, 1]) | ||
mesh = ax.pcolormesh(gx, gx, img) | ||
fig.colorbar(mesh) | ||
|
||
|
||
def test_constrained_layout21(): | ||
'#11035: repeated calls to suptitle should not alter the layout' | ||
fig, ax = plt.subplots(constrained_layout=True) | ||
|
||
fig.suptitle("Suptitle0") | ||
fig.canvas.draw() | ||
extents0 = np.copy(ax.get_position().extents) | ||
|
||
fig.suptitle("Suptitle1") | ||
fig.canvas.draw() | ||
extents1 = np.copy(ax.get_position().extents) | ||
|
||
np.testing.assert_allclose(extents0, extents1) | ||
|
||
|
||
def test_constrained_layout22(): | ||
'#11035: suptitle should not be include in CL if manually positioned' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. included? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to proofread the test comment strings! 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should have written "... very (very) minor comments..." in my review ^^. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your help on this! Great that someone (other than me) is using CL. BTW< don't be shy about making more bug reports if you have them. |
||
fig, ax = plt.subplots(constrained_layout=True) | ||
|
||
fig.canvas.draw() | ||
extents0 = np.copy(ax.get_position().extents) | ||
|
||
fig.suptitle("Suptitle", y=0.5) | ||
fig.canvas.draw() | ||
extents1 = np.copy(ax.get_position().extents) | ||
|
||
np.testing.assert_allclose(extents0, extents1) | ||
|
||
|
||
def test_constrained_layout23(): | ||
''' | ||
Comment in #11035: suptitle used to cause an exception when | ||
reusing a figure w/ CL with ``clear=True``. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Being there, a better phrasing might be "... a figure with CL and |
||
''' | ||
|
||
for i in range(2): | ||
fig, ax = plt.subplots(num="123", constrained_layout=True, clear=True) | ||
fig.suptitle("Suptitle{}".format(i)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these two lines really work? I may be naive, but neither 'x' nor 'y' belong to
**kwargs
, do they not?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blame @anntzer 😉 The new signature is
def suptitle(self, t, *, x=.5, y=.98, **kwargs):
The little star in there means everything past the star is a kwarg;x
andy
are explicit kwargs...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, actually, I think see what happened. @anntzer put the new signature in, and I put the pop back in. OTOH, now I'm confused if manual position ever comes back false now....
EDIT: no, it works... Thanks for catching this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, neat ^^, but even if 'x' or 'y' are keyword-only arguments, do they belong to the special dictionary
**kwargs
?Edit: yes, I think that the popping just makes it to always default to (0.5, 0.98) I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ping @anntzer is this OK, or is there a better way to check if
x
ory
have been set?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you have to use kwargs-popping in that case.
I'm a bit confused though (haven't followed the issue at all): if x and y are not set, are they always going to be 0.5 and 0.98, or is it that the constrained layout manager will move them around? If the latter, then perhaps the default should just be x=y=None, as 0.5/0.98 don't really mean anything? Although I guess they are still meaningful if the constrained layout manager is not in use...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If x and y are not set, then they start life as 0.5 and 0.98. If constrained layout is called, they will move. If the user does set x or y then constrained_layout ignites the suptitle