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

bbox_inches='tight' clips figure.suptitle #688

Closed
fperez opened this issue Jan 29, 2012 · 3 comments
Closed

bbox_inches='tight' clips figure.suptitle #688

fperez opened this issue Jan 29, 2012 · 3 comments
Assignees
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: confirmed bug

Comments

@fperez
Copy link
Member

fperez commented Jan 29, 2012

In ipython for the qtconsole and notebook, we send inline figures using

fig.canvas.print_figure(bytes_io, format=fmt, bbox_inches='tight')

as seen here.

However, this produces truncated figure titles. Consider this code:

f, ax = plt.subplots()
ax.plot(rand(100))
ax.set_title('Axis title')
f.suptitle('Figure title');

which produces this in the notebook:

A slightly more complicated example, using basemap, not only truncates the title but also all the x and y labels. We show it here for reference, but as @jswhit (basemap author) pointed out over email, basemap labels are located at arbitrary positions and so it's harder for matplotlib to take them into consideration.

from mpl_toolkits.basemap import Basemap

lon0, lat0, lon1, lat1 = (84.38, 26.22, 88.9, 29.8)
resolution = 'i'

parallels = np.linspace(lat0, lat1, 5)
meridians = np.linspace(lon0, lon1, 5)

f, ax = plt.subplots()
m = Basemap(lon0, lat0, lon1, lat1, resolution=resolution, ax=ax)
m.drawcountries(color=(1,1,0))  # country boundaries in pure yellow
m.drawrivers(color=(0,1,1))  # rivers in cyan
m.bluemarble()  # NASA bluemarble image
m.drawmeridians(meridians, labels=[0,0,0,1], fmt='%.2f')
m.drawparallels(parallels, labels=[1,0,0,0], fmt='%.2f')
f.suptitle('The Himalayas');

While we noticed this in the notebook, the problem will be present for any figure saving operation that supports bbox_inches='tight'.

As discussed in the mailing list thread about this problem, mpl should probably use the position of 'official' artists such figure suptitles in the computation of the bounding box.

@ibomash
Copy link

ibomash commented Jan 30, 2012

I noticed another case of clipping with bbox_inches='tight'. I have some code in which I create a legend outside of its associated axes using the bbox_to_anchor keyword argument; in IPython, this legend gets clipped out. Example:
Clipping example
Not sure if the submitted patch fixes this issue, too….

@leejjoon
Copy link
Contributor

The legend issue should be fixed with 565efe4.

@pelson
Copy link
Member

pelson commented Nov 3, 2012

I'm not sure if this issue was closed prematurely or not, but I expect all of the above cases to work as a result of #1448.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: confirmed bug
Projects
None yet
Development

No branches or pull requests

5 participants