I have a problem with changing the ticklabels text. In fact I am aware of the
method which is explained by the matplotlib help center. But I need more
flexibility with ticklabels text.
For example, I want to add an "a" before every tick label of the xaxis. So I
wrote the following sample code:
···
#----------------------------------------------------------------
from pylab import *
#
t = arange(0.0, 100.0, 0.1)
s = sin(0.1*pi*t)*exp(-t*0.01)
#
ax = subplot(111)
plot(t,s)
#
for label1 in ax.xaxis.get_majorticklabels():
label1.set_weight('bold')
label1._text="a"+label1._text
#
show() #----------------------------------------------------------------
It seems to me that `` label1._text="a"+label1._text ' ' should do this
job, but it does nothing. The only way I found was using something like
this:
which I would rather not to use, because there are lots of graphs in my
project and I do not want to this process manually. So, my question is which
property or method would set (and also get) the ticklabel text?
Why not use get_ticklabels() to get the list of strings, modify that, and call set_ticklabels() with the modified list?
Ben Root
···
On Friday, August 26, 2011, a.sam <a.samii@…287…> wrote:
I have a problem with changing the ticklabels text. In fact I am aware of the
method which is explained by the matplotlib help center. But I need more
flexibility with ticklabels text.
For example, I want to add an “a” before every tick label of the xaxis. So I
wrote the following sample code: #----------------------------------------------------------------
from pylab import *
t = arange(0.0, 100.0, 0.1)
s = sin(0.1pit)exp(-t0.01)
which I would rather not to use, because there are lots of graphs in my
project and I do not want to this process manually. So, my question is which
property or method would set (and also get) the ticklabel text?
I have a problem with changing the ticklabels text. In fact I am aware of the
method which is explained by the matplotlib help center. But I need more
flexibility with ticklabels text.
You could set the formatter yourself instead of manipulating strings or
setting the ticklabels by hand. IE:
a = plt.gca()
a.xaxis.set_major_formatter(my_formatter)
plt.draw()
Regards,
Sebastian
···
On Fri, 2011-08-26 at 06:09 -0700, a.sam wrote:
For example, I want to add an "a" before every tick label of the xaxis. So I
wrote the following sample code: #----------------------------------------------------------------
from pylab import *
#
t = arange(0.0, 100.0, 0.1)
s = sin(0.1*pi*t)*exp(-t*0.01)
#
ax = subplot(111)
plot(t,s)
#
for label1 in ax.xaxis.get_majorticklabels():
label1.set_weight('bold')
label1._text="a"+label1._text
#
show() #----------------------------------------------------------------
It seems to me that `` label1._text="a"+label1._text ' ' should do this
job, but it does nothing. The only way I found was using something like
this:
which I would rather not to use, because there are lots of graphs in my
project and I do not want to this process manually. So, my question is which
property or method would set (and also get) the ticklabel text?