Width of axes tick labels

Hello,

I'm new to matplotlib, but have made great progress in using it over
the past few days (thanks in no small part to this list). However, I
am stuck on trying to determine the width of a y tick label (either in
inches or figure space). I know I can get 'Text instances' of the tick
labels using 'get_yticklabels'. However, a Text object doesn't appear
to have a width field. Now, it would make sense that the width of a
label depends on the rendered so I expect I need to take my text
string and pass it through an appropriate transformation using
something like 'get_yaxis_text1_transform'. Can anyone point me to an
example of obtaining the width of a label and/or some code indicating
how this can be done?

I realize I can approximate the width of a label simply by considering
how many characters it contains, the font size, and the DPI of the
figure, but this will be rather crude as I am not using a fixed-width
font.

Much thanks.

Cheers,
Donovan

Text instances have "get_window_extent" method. However, it requires a
renderer instance (because the size of the text depends on the
backend), i.e., the size of the text is only known during the drawing
time.

The easiest ways is to call get_window_extent without any argument,
but after figure is already drawn. However, it depends on why you need
the size of the text.

Regards,

-JJ

ยทยทยท

On Tue, Oct 6, 2009 at 9:54 AM, Donovan Parks <donovan.parks@...287...> wrote:

Hello,

I'm new to matplotlib, but have made great progress in using it over
the past few days (thanks in no small part to this list). However, I
am stuck on trying to determine the width of a y tick label (either in
inches or figure space). I know I can get 'Text instances' of the tick
labels using 'get_yticklabels'. However, a Text object doesn't appear
to have a width field. Now, it would make sense that the width of a
label depends on the rendered so I expect I need to take my text
string and pass it through an appropriate transformation using
something like 'get_yaxis_text1_transform'. Can anyone point me to an
example of obtaining the width of a label and/or some code indicating
how this can be done?

I realize I can approximate the width of a label simply by considering
how many characters it contains, the font size, and the DPI of the
figure, but this will be rather crude as I am not using a fixed-width
font.

Much thanks.

Cheers,
Donovan

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users