Automatically make room for my tick labels without GUI ?

Hi all,
I am trying to automatically adjust margins with the SVG backend.

The FAQ example :
http://matplotlib.sourceforge.net/doc/html/faq/howto_faq.html#how-do-i-automatically-make-room-for-my-tick-labels
only works with GUI backends.
May it come from get_window_extent() call ?

How could I modify this snipplet so that it works with SVG (or PDF) backends ?

Thank you for your support.

While I don't know much about how callbacks work in matplotlib,
looking at the source code of figure.draw() method, it seems that
call_back functions connected with the "draw_event" are called after a
figure is drawn. Therefore, you need a second draw. My guess is that
this second draw is somehow automagically done in gui backends.
So, a quick and easy solution would be to save the same figure twice.
First one will have a figure before the adjustment, but the second one
will have a figure after the adjustment.

Or, you may create a custom figure class which overrides the draw()
method to adjust the margins before you draw the actual figure.
Attached is an example of such custom figure class. I slightly
modified the original example.

-JJ

myfigure.py (1.51 KB)

···

On Thu, Aug 21, 2008 at 12:53 PM, Mathieu Leplatre <leplatre@...287...> wrote:

Hi all,
I am trying to automatically adjust margins with the SVG backend.

The FAQ example :
http://matplotlib.sourceforge.net/doc/html/faq/howto_faq.html#how-do-i-automatically-make-room-for-my-tick-labels
only works with GUI backends.
May it come from get_window_extent() call ?

How could I modify this snipplet so that it works with SVG (or PDF) backends ?

Thank you for your support.

-------------------------------------------------------------------------
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
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

While I don't know much about how callbacks work in matplotlib,
looking at the source code of figure.draw() method, it seems that
call_back functions connected with the "draw_event" are called after a
figure is drawn. Therefore, you need a second draw. My guess is that
this second draw is somehow automagically done in gui backends.
So, a quick and easy solution would be to save the same figure twice.
First one will have a figure before the adjustment, but the second one
will have a figure after the adjustment.

This works as you expected :slight_smile:

Or, you may create a custom figure class which overrides the draw()
method to adjust the margins before you draw the actual figure.
Attached is an example of such custom figure class. I slightly
modified the original example.

The solution is nice, I'll go for this one !
I don't feel confident enough yet to look inside the library's code, I
definitely should !

Thank you very much Jae-Joon !

···

On Thu, Aug 21, 2008 at 7:50 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

-JJ

On Thu, Aug 21, 2008 at 12:53 PM, Mathieu Leplatre <leplatre@...287...> wrote:

Hi all,
I am trying to automatically adjust margins with the SVG backend.

The FAQ example :
http://matplotlib.sourceforge.net/doc/html/faq/howto_faq.html#how-do-i-automatically-make-room-for-my-tick-labels
only works with GUI backends.
May it come from get_window_extent() call ?

How could I modify this snipplet so that it works with SVG (or PDF) backends ?

Thank you for your support.

-------------------------------------------------------------------------
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
https://lists.sourceforge.net/lists/listinfo/matplotlib-users