long legend gets truncated if put outside

Hello,

please try this.

from matplotlib.pyplot import *
plot([1,2,3], label="very loooooooong label")
plot([3,2,1], label="very loooooooong label2")
legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
show()

The code puts a legend with very long label text outside the figure.
When drawing only the beginning of the legend is visible.
Is there a way to automatically correct the area of figure and resize it
such that every box drawn is visible?
I know I can overcome this issue by using subplots. But this would only
work to a certain extend of the problem.

Regards
Eymen

Things like axes position is given in normalized figure coordinates,
thus while you can change the figure size but it is quite hard to keep
things in place. And, no, current mpl does not support that.

If you're only interested in the saved ouput, you may use
"bbox_inches" option of "savefig". It does not change the size of the
figure currently displayed, but it does change the size of the figure
that is to be saved. Unfortunately, the released version of mpl will
not work. With svn version, you can do

l = legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
savefig("a.eps", bbox_inches="tight", bbox_extra_artists=[l.legendPatch])

Regards,

-JJ

···

On Fri, Feb 5, 2010 at 10:10 AM, Eymen Alyaz <ealyaz@...2957...> wrote:

Is there a way to automatically correct the area of figure and resize it
such that every box drawn is visible?

Thank you for this quick reply. Your suggestion matched my intention of
plotting/ saving the figure. I will give the svn version a shot and try it
out.

Regards,
Eymen

···

On Fri, Feb 5, 2010 at 10:10 AM, Eymen Alyaz <ealyaz@...2957...> > wrote:

Is there a way to automatically correct the area of figure and resize it
such that every box drawn is visible?

If you're only interested in the saved ouput, you may use
"bbox_inches" option of "savefig". It does not change the size of the
figure currently displayed, but it does change the size of the figure
that is to be saved. Unfortunately, the released version of mpl will
not work. With svn version, you can do
...