Automatic margins

Is there a way to automatically guess margins according to chart content ?

Like, in this small example :

import pylab
fig = pylab.figure()
pylab.plot([1,2,3])
pylab.title('Big One', fontsize=72)

topmargin = 0.2 # Auto ?

fig.subplots_adjust(top=1.0-topmargin)
pylab.show()

Mathieu Leplatre wrote:

Is there a way to automatically guess margins according to chart content ?

There is nothing like that built into mpl. It is not an easy thing to do in general--that is, for an arbitrary set of axes, labels, widgets, etc.

Eric

···

Like, in this small example :

import pylab
fig = pylab.figure()
pylab.plot([1,2,3])
pylab.title('Big One', fontsize=72)

topmargin = 0.2 # Auto ?

fig.subplots_adjust(top=1.0-topmargin)
pylab.show()

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

There is a FAQ showing how to do this for tick labels using the
bounding boxes of the labels. You could do something similar with the
title bounding box

http://matplotlib.sourceforge.net/doc/html/faq/howto_faq.html#how-do-i-automatically-make-room-for-my-tick-labels

JDH

···

On Wed, Aug 13, 2008 at 12:40 PM, Eric Firing <efiring@...202...> wrote:

Mathieu Leplatre wrote:

Is there a way to automatically guess margins according to chart content ?

There is nothing like that built into mpl. It is not an easy thing to
do in general--that is, for an arbitrary set of axes, labels, widgets, etc.

There is a FAQ showing how to do this for tick labels using the
bounding boxes of the labels. You could do something similar with the
title bounding box

http://matplotlib.sourceforge.net/doc/html/faq/howto_faq.html#how-do-i-automatically-make-room-for-my-tick-labels

JDH

Thank you very much for pointing me this out. I must confess I hadn't seen it.

I am trying to modify the given snipplet so that it could work with
something more general like :

for label in fig.findobj(matplotlib.text.Text):

Apart from the missing renderer exceptions that are raised, I can't
figure out how to split the resulting union box into left, right,
bottom, top as required by fig.subplots_adjust()

If this is obvious, I am very sorry to be tiresome...

Thanks a lot for your help.

I figured it out, just had to test xmin/ymin < 0.0 and xmax/ymax > 1.0.
I could compute easily the new margins values and it works well.

*However*, I noticed that the SVG renderer does not take in account
the self.fig.subplots_adjust() commands called within on_draw(self,
event).

The FAQ example mentionned above does not work when invoking
matplotlib.use("svg").

I am using matplotlib 0.98.3, it could be a bug ?

Thanks for your feedback ! (should I start a new thread ?)

···

On Fri, Aug 15, 2008 at 1:52 PM, Mathieu Leplatre <leplatre@...287...> wrote:

There is a FAQ showing how to do this for tick labels using the
bounding boxes of the labels. You could do something similar with the
title bounding box

http://matplotlib.sourceforge.net/doc/html/faq/howto_faq.html#how-do-i-automatically-make-room-for-my-tick-labels

JDH

Thank you very much for pointing me this out. I must confess I hadn't seen it.

I am trying to modify the given snipplet so that it could work with
something more general like :

for label in fig.findobj(matplotlib.text.Text):

Apart from the missing renderer exceptions that are raised, I can't
figure out how to split the resulting union box into left, right,
bottom, top as required by fig.subplots_adjust()

If this is obvious, I am very sorry to be tiresome...

Thanks a lot for your help.