ticklabels

Dear all,

None of the obvious ways for changing ticklabels seem to work for the current version of Matplotlib (1.2.0 for me). At present, ax.yaxis.get_ticklabels().get_text() returns empty strings, as does ax.get_yticklabels(), and the equivalent set_* functions don't seem to have any effect.

So: help!

Yours,

Andrew

2013/3/14 Andrew H. Jaffe <a.h.jaffe@...287...>:

Dear all,

None of the obvious ways for changing ticklabels seem to work for the current version of Matplotlib (1.2.0 for me). At present, ax.yaxis.get_ticklabels().get_text() returns empty strings, as does ax.get_yticklabels(), and the equivalent set_* functions don't seem to have any effect.

It seems to be working for me. I'm using a development version but I
don't thing this has changed.

In [1]: import matplotlib.pyplot as plt

In [2]: plt.get_backend()
Out[2]: 'TkAgg'

In [3]: plt.plot([1, 2])
Out[3]: [<matplotlib.lines.Line2D at 0x424c310>]

In [4]: plt.draw()

In [5]: labels = plt.gca().get_yticklabels()

In [6]: map(lambda x: x.get_text(), labels)
Out[6]: [u'1.0', u'1.2', u'1.4', u'1.6', u'1.8', u'2.0', u'2.2', '']

In [7]: plt.gca().set_yticklabels(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])
Out[7]:
[<matplotlib.text.Text at 0x3e97bd0>,
<matplotlib.text.Text at 0x3ea2390>,
<matplotlib.text.Text at 0x42bed90>,
<matplotlib.text.Text at 0x42c0390>,
<matplotlib.text.Text at 0x42c05d0>,
<matplotlib.text.Text at 0x42c0c50>,
<matplotlib.text.Text at 0x42c1310>,
<matplotlib.text.Text at 0x42c1990>]

In [8]: map(lambda x: x.get_text(), labels)
Out[8]: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']

Goyo

it also works for me for 1.2.0
In [1]: mat.__version__
Out[1]: '1.2.0'

In [2]: plot(np.arange(5),'ro')
Out[2]: [<matplotlib.lines.Line2D at 0xc88262c>]

In [3]: ax = gca()

In [4]: ax.set_xticklabels('abcdefghij')
Out[4]:
[<matplotlib.text.Text at 0xbbb048c>,
<matplotlib.text.Text at 0xbbb0c8c>,
<matplotlib.text.Text at 0xc88780c>,
<matplotlib.text.Text at 0xc887e2c>,
<matplotlib.text.Text at 0xc88b4cc>,
<matplotlib.text.Text at 0xc88bb4c>,
<matplotlib.text.Text at 0xc8911ec>,
<matplotlib.text.Text at 0xc89186c>,
<matplotlib.text.Text at 0xc891eec>]

In [5]: [t.get_text() for t in ax.get_xticklabels()]
Out[5]: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']

ยทยทยท

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/ticklabels-tp40656p40663.html
Sent from the matplotlib - users mailing list archive at Nabble.com.