★ wanayoo — archive 1999 https://github.com/matplotlib/matplotlib/issues/5355Nouvelle recherche | Portail wanayoo
Skip to content
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

fig.suptitle() still scrambled with ax.title when using tight_layout() #5355

Closed
michaelaye opened this issue Oct 30, 2015 · 10 comments
Closed
Labels
topic: geometry manager LayoutEngine, Constrained layout, Tight layout

Comments

@michaelaye
Copy link

I don't know if the suptitle() is implemented via OffsetBoxes, but the What's New text mentioning this:

When tight_layout() or Figure.tight_layout() or GridSpec.tight_layout() is called, OffsetBoxes that are anchored outside the axes will not get chopped out. The OffsetBoxes will also not get overlapped by other axes in case of multiple subplots.

made me hope that I could finally use fig.suptitle() with ax.title and fig.tight_layout() without manually adapting the margins. Alas, this still seems to be an issue:

screenshot 2015-10-29 22 55 08

Version: '1.5.0rc3+207.g54ead93' on OSX, self compiled using python setup.py install with conda's Python 3.5

Code:

fig, ax = plt.subplots()
fig.suptitle('suptitle')
ax.plot(range(10))
ax.set_title('title')
fig.tight_layout()
@daeyun
Copy link

daeyun commented Nov 23, 2018

Any update on this?

@jklymak
Copy link
Member

jklymak commented Nov 23, 2018

This doesn't work in tight_layout, but it does work in constrained_layout...

import matplotlib.pyplot as plt

fig, ax = plt.subplots(constrained_layout=True)
fig.suptitle('suptitle')
ax.plot(range(10))
ax.set_title('title')

suptitle

@jklymak
Copy link
Member

jklymak commented Nov 23, 2018

My guess is that there is no good reason this could not be made to work in tight_layout, except tha tight_layout would need a good overhaul to include other artists not in the direct gridspec of the subplots. #6914 was a partial solution to this, but what is really needed is for gridspecs to follow a proper nested hierarchy. Given that constrained_layout works for all but the most complicated layouts, I'm not sure there is strong demand to do the extra work on tight_layout which is more modest in what it can accomplish.

@jklymak jklymak added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Nov 23, 2018
@jklymak
Copy link
Member

jklymak commented Jan 30, 2019

I'm going to close this as fixed in constraind_layout and I doubt anyone is going to fix in tight_layout. But feel free to re-open if that's not the case....

@jklymak jklymak closed this as completed Jan 30, 2019
@asteppke
Copy link

asteppke commented Mar 14, 2019 •

Unfortunately this is still not working in matplotlib 3.0.2 using constrained_layout. Under certain circumstances the layout still overlaps as shown in the following examples in the Jupyter notebook (with different backends):

%matplotlib notebook 
import numpy as np
from matplotlib import pyplot as plt

# example with low height
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(6, 3), constrained_layout=True)
axes[0,0].plot([0,1,2], label='test')
axes[1,0].plot([0,1,2], label='test 2')
fig.suptitle('a longer title') 

This results in
image

But now increasing the plot height using the modified example

[...]
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(6, 12), constrained_layout=True)
[...]

shows the following overlapping title:

image

Is there anything that can be done here to find out why this is not taking into account the larger plot dimensions?

@jklymak
Copy link
Member

jklymak commented Mar 14, 2019

I can reproduce that. Basically the baseline of the subtitle is being aligned properly, but its overlapping the tick label and the descending "g" is going too deep. I think its all fixable.

However, I do have to make the figure quite large for this to happen.

@jklymak
Copy link
Member

jklymak commented Mar 14, 2019

Can you open a new issue? This is really a refinement of the old one...

@RylanSchaeffer
Copy link

what's the solution to this?

@jklymak
Copy link
Member

jklymak commented Jan 29, 2020

suptitle is not compatible with tight_layout. The solution is to use constrained_layout or place manually.

@timhoffm
Copy link
Member

timhoffm commented Feb 1, 2020

Can/should we warn if tight_layout is used with suptitle?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

No branches or pull requests

6 participants