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

tight_layout: take suptitle into account? #829

Closed
birkenfeld opened this issue Apr 14, 2012 · 3 comments
Closed

tight_layout: take suptitle into account? #829

birkenfeld opened this issue Apr 14, 2012 · 3 comments
Labels
MEP: MEP needed New feature topic: geometry manager LayoutEngine, Constrained layout, Tight layout

Comments

@birkenfeld
Copy link

The tight_layout function is very useful.

In one of the common use cases, a figure with a few subplots, it would be nice if a figure title could be taken into account; otherwise it will overlap the top subplots.

I can see from the code that the suptitle is just a simple Text; maybe the figure could keep track of the last Text object that got created using suptitle(), and so be able to take it into account when calculating the tight layout params.

@leejjoon
Copy link
Contributor

This has been discussed in the mailing list.

http://www.mail-archive.com/matplotlib-devel@lists.sourceforge.net/msg08971.html

I'll just copy my answer (with slight modification) for the record.


I'm afraid that, unfortunately, it won't be fixed soon (if ever, as far as I can tell).
What "tight_layout" does is to adjust the subplot parameters of the
figure so that the "subplots" fit in. Artists whose position is set in the figure coordinate (e.g., texts created with figtext, suptitle, etc) therefore are not affected by the subplot parameters, i.e. there is not
much thing we can do for these artists within the current
implementation. It would be better if some warning is printed in such
case (there are lots of cases that tight_layout will fail), but this
is not currently done.

Depending on your need, you may leave out some area for figtext (or suptitle) when
you call "tight_layout". This is only supported for gridspec though.

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec

fig = plt.figure()

gs1 = gridspec.GridSpec(2, 2)
ax_list = [fig.add_subplot(ss) for ss in gs1]

fig.text (02, 0, "test", horizontalalignment='left',
         verticalalignment='bottom', size=5)
fig.text (0.5, 1, "01", horizontalalignment='left',
         verticalalignment='top', size='x-small')

gs1.tight_layout(fig, rect=[0, 0.03, 1, 0.97]) # adjust rect parameter while leaving some room for figtext.

@pelson
Copy link
Member

pelson commented Aug 19, 2012

I don't know the details of tight_layout, but thinking a little bigger, a full blown geometry manager would be the best possible solution here... MEP (matplotlib enhancement proposal) required.

@tacaswell
Copy link
Member

Related to #1109

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

No branches or pull requests

4 participants