From: Jeff W. <js...@fa...> - 2012-01-29 16:32:58
|
On 1/29/12 8:42 AM, Benjamin Root wrote: > > > On Sunday, January 29, 2012, Fernando Perez <fpe...@gm... > <mailto:fpe...@gm...>> wrote: > > Hi all, > > > > 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: > > > > > https://github.com/ipython/ipython/blob/master/IPython/core/pylabtools.py#L104 > > > > 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: > > > > http://img546.imageshack.us/img546/5448/selection001c.png > > > > As you can see, the figure title gets truncated. > > > > We started using bbox_inches='tight' because otherwise in many cases > > the images were coming back with insane amounts of white padding, and > > Stefan vdW suggested this fix. But it seems that in other cases it > > actually loses data, which is even worse... > > > > A slightly more complicated example, using basemap, not only truncates > > the title but also all the x and y labels: > > > > 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'); > > > > ##### > > > > produces: > > > > http://img192.imageshack.us/img192/986/selection002e.png > > > > > > This looks like a matplotlib bug, but I have no idea how easy it is to > > fix. In the meantime, should we in ipython just revert back to not > > using bbox_inches, or is there an alternative? > > > > Thanks! > > > > f > > > > Not a bug. There are only so many artist objects we assume for > determining the tight bbox. Suptitle is not one of them. However, If > you collect all of the artists that you want considered, you can pass > in a list of them to bbox_artists (IIRC) to have them considered as well. > > Now, with respect to the Basemap example, there might be a bug there, > but it can still be worked around by passing in the list of labels to > the kwarg. > > Cheers! > Ben Root The lat and lon labels in Basemap are axes.text objects, which apparently are not considered when computing the bbox either. -Jeff |