rotating labels, what is wrong?!

I am trying simply to shrink the font size and rotate xaxis labels:

fig1 = plt.figure()
ax1 = fig1.add_subplot(211)
ax2 = fig1.add_subplot(212)
ax1.plot_date(x,y,'r')
ax1.set_xticklabels(plt.gca().get_xmajorticklabels(),
                    size=6,rotation=30)
ax2.plot_date(o_X['time'],o_X['CO'],'y')
ax2.set_xticklabels(plt.gca().get_xmajorticklabels(),
                     size=6,rotation=30)

I end up with labels as: ("Text(0,0"Text(0,0,"")")

???

···

--
View this message in context: http://www.nabble.com/rotating-labels%2C-what-is-wrong-!-tp24572302p24572302.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

get_xmajorticklabels() returns a list of matplotlib's "Text" objects,
not python strings.

http://matplotlib.sourceforge.net/api/axes_api.html?highlight=get_xmajorticklabels#matplotlib.axes.Axes.get_xmajorticklabels

On the other hand, set_xticklabels() takes a list of python strings.

http://matplotlib.sourceforge.net/api/axes_api.html?highlight=set_xticklabels#matplotlib.axes.Axes.set_xticklabels

Something like below will work.

plt.setp(plt.gca().get_xmajorticklabels(),
         size=6,rotation=30)

-JJ

···

On Mon, Jul 20, 2009 at 11:48 AM, John [H2O]<washakie@...287...> wrote:

I am trying simply to shrink the font size and rotate xaxis labels:

fig1 = plt.figure()
ax1 = fig1.add_subplot(211)
ax2 = fig1.add_subplot(212)
ax1.plot_date(x,y,'r')
ax1.set_xticklabels(plt.gca().get_xmajorticklabels(),
size=6,rotation=30)
ax2.plot_date(o_X['time'],o_X['CO'],'y')
ax2.set_xticklabels(plt.gca().get_xmajorticklabels(),
size=6,rotation=30)

I end up with labels as: ("Text(0,0"Text(0,0,"")")

???

View this message in context: http://www.nabble.com/rotating-labels%2C-what-is-wrong-!-tp24572302p24572302.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Jae-Joon Lee wrote:

get_xmajorticklabels() returns a list of matplotlib's "Text" objects,
not python strings.

This is what I've now come to understand, but it seems very odd. Why
wouldn't it return the list of strings, or alternatively, how can you get
the list of strings? I guess you have to use the pyplot tools, but I was
trying to use so called 'fine grain' control and do everything at the axes
level.

plt.setp(plt.gca().get_xmajorticklabels(),
         size=6,rotation=30)

In fact, what you show is how I was testing in ipython and it does worked,
it just seemed in a script it would be better to use the axis method, but
apparently it is different from the gca() method. This is what I don't
understand.

Thanks!

···

On Mon, Jul 20, 2009 at 11:48 AM, John [H2O]<washakie@...287...> wrote:

I am trying simply to shrink the font size and rotate xaxis labels:

fig1 = plt.figure()
ax1 = fig1.add_subplot(211)
ax2 = fig1.add_subplot(212)
ax1.plot_date(x,y,'r')
ax1.set_xticklabels(plt.gca().get_xmajorticklabels(),
size=6,rotation=30)
ax2.plot_date(o_X['time'],o_X['CO'],'y')
ax2.set_xticklabels(plt.gca().get_xmajorticklabels(),
size=6,rotation=30)

I end up with labels as: ("Text(0,0"Text(0,0,"")")

???

View this message in context:
http://www.nabble.com/rotating-labels%2C-what-is-wrong-!-tp24572302p24572302.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full
prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
View this message in context: http://www.nabble.com/rotating-labels%2C-what-is-wrong-!-tp24572302p24577287.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Jae-Joon Lee wrote:

get_xmajorticklabels() returns a list of matplotlib's "Text" objects,
not python strings.

This is what I've now come to understand, but it seems very odd. Why
wouldn't it return the list of strings, or alternatively, how can you get
the list of strings? I guess you have to use the pyplot tools, but I was
trying to use so called 'fine grain' control and do everything at the axes
level.

Why it does not return a list of strings? Because the documentation
says it does not. Well, I acknowledge the asymetry in the API, but
this is how things are.

How to get the list of strings? Use the "get_text" method of the "Text" object.

http://matplotlib.sourceforge.net/api/artist_api.html?#matplotlib.text.Text.get_text

I used pyplot function because you were calling plt.gca(). If you
don't like it, you can explicitly go over the for loop with
appropriate methods.

for t in ax1.get_xmajorticklabels():
    t.set(size=6,rotation=30)

or use set_size and set_rotation if you prefer.

See the documentation for more details.

Regards,

-JJ

···

On Mon, Jul 20, 2009 at 4:48 PM, John [H2O]<washakie@...287...> wrote:

plt.setp(plt.gca().get_xmajorticklabels(),
size=6,rotation=30)

In fact, what you show is how I was testing in ipython and it does worked,
it just seemed in a script it would be better to use the axis method, but
apparently it is different from the gca() method. This is what I don't
understand.

Thanks!

On Mon, Jul 20, 2009 at 11:48 AM, John [H2O]<washakie@...287...> wrote:

I am trying simply to shrink the font size and rotate xaxis labels:

fig1 = plt.figure()
ax1 = fig1.add_subplot(211)
ax2 = fig1.add_subplot(212)
ax1.plot_date(x,y,'r')
ax1.set_xticklabels(plt.gca().get_xmajorticklabels(),
size=6,rotation=30)
ax2.plot_date(o_X['time'],o_X['CO'],'y')
ax2.set_xticklabels(plt.gca().get_xmajorticklabels(),
size=6,rotation=30)

I end up with labels as: ("Text(0,0"Text(0,0,"")")

???

View this message in context:
http://www.nabble.com/rotating-labels%2C-what-is-wrong-!-tp24572302p24572302.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full
prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
View this message in context: http://www.nabble.com/rotating-labels%2C-what-is-wrong-!-tp24572302p24577287.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users