savefig bbox_inches='tight' does not consider suptitle

>> > Is this a bug?
>>
>> Unfortunately, bbox_inches option is never meant to be complete in
>> figuring out the exact size of the figure area.
>
> Why not? What's the purpose of bbox_inches='tight' otherwise?

Figuring out enclosing bbox when arbitrary spline paths are involved
is difficult (I think there is no exact solution). So I only intended
to support common cases.

Ok, I can understand that, but shouldn't all artists used to construct the picture, as suptitle, be considered?

>> However, you can use "bbox_extra_artists" keyword argument to specify
>> additional artists that should be considered when dertermining the
>> plot size.
>>
>> mytitle = fig.suptitle("Horray!", fontsize=20)
>>
>> ...
>>
>> fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[mytitle])
>
> That doesn't work for me either.

Can you be more specific? Does it throw an exception? Or the code runs
without any error but the output is still wrong?

No error/exception are produced. The output is simply identical to the one without bbox_extra_artists.

This also works in my previous example:

import matplotlib as mpl
import matplotlib.figure
import matplotlib.backends.backend_agg

fig = mpl.figure.Figure()
cvs = mpl.backends.backend_agg.FigureCanvasAgg(fig)
fig.set_size_inches((20,20))
plot = fig.add_subplot(111)
plot.set_title("Subtitle")
plot.plot([1,2,3], [3,2,1])
st = fig.suptitle("Horray!", fontsize=20)
fig.savefig("out.png", bbox_inches='tight', bbox_extra_artists=[st])

···

On Wed, 2 Mar 2011 22:01:02 +0900 Jae-Joon Lee <lee.j.joon@...287...> wrote:

Which version of matplotlib are you using? This example works for me using the latest matplotlib from source. Also, why the awkward usage and imports? If you want to force the Agg backend to be used, you could just do:

import matplotlib
matplotlib.use(“Agg”)

before any other matplotlib imports.

Ben Root

···

On Wed, Mar 2, 2011 at 8:46 AM, Yuri D’Elia <wavexx@…120…3457…> wrote:

On Wed, 2 Mar 2011 22:01:02 +0900 > Jae-Joon Lee <lee.j.joon@…287…> wrote:

Is this a bug?

Unfortunately, bbox_inches option is never meant to be complete in

figuring out the exact size of the figure area.

Why not? What’s the purpose of bbox_inches=‘tight’ otherwise?

Figuring out enclosing bbox when arbitrary spline paths are involved

is difficult (I think there is no exact solution). So I only intended

to support common cases.

Ok, I can understand that, but shouldn’t all artists used to construct the picture, as suptitle, be considered?

However, you can use “bbox_extra_artists” keyword argument to specify

additional artists that should be considered when dertermining the

plot size.

mytitle = fig.suptitle(“Horray!”, fontsize=20)

fig.savefig(“out.png”, bbox_inches=‘tight’, bbox_extra_artists=[mytitle])

That doesn’t work for me either.

Can you be more specific? Does it throw an exception? Or the code runs

without any error but the output is still wrong?

No error/exception are produced. The output is simply identical to the one without bbox_extra_artists.

This also works in my previous example:

import matplotlib as mpl

import matplotlib.figure

import matplotlib.backends.backend_agg

fig = mpl.figure.Figure()

cvs = mpl.backends.backend_agg.FigureCanvasAgg(fig)

fig.set_size_inches((20,20))

plot = fig.add_subplot(111)

plot.set_title(“Subtitle”)

plot.plot([1,2,3], [3,2,1])

st = fig.suptitle(“Horray!”, fontsize=20)

fig.savefig(“out.png”, bbox_inches=‘tight’, bbox_extra_artists=[st])