Looking back through the archives, I found this discussion of manipulating
ticklabels.
Jouni K. Seppänen wrote:
Eugen Wintersberger <eugen.wintersberger@...499...>
writes:
The first line is the printing of the ticklabel list before the
pylab.show() command. The second after pylab.show(). Why the list
contains 1 entry before and 7 (as is should) after pylab.show()?
I think matplotlib is deferring the creation of the tick labels because
for all it knows, you might be going to plot something that will cause
the axes to be rescaled and change the tick locations and labels.
I would like to access the labels before the final show command in a
script. But how is this possible with this behavior?
You could set the tick positions and labels explicitly, or if you like
the default tick locator, add the following before getting the ticklabel
objects:
a.xaxis.get_major_locator().refresh()
I am having the same problem as Eugen, and the suggested solution of using
a.xaxis.get_major_locator().refresh()
to force the creation of the full set of ticklabels doesn't seem to work for
me.
Sample script:
from pylab import *
#ion()
a =axes([0.2,0.2,0.7,0.7])
t = arange(0.0, 2.0, 0.01)
s = sin(2*pi*t)
a.plot(t, s)
a.grid(True)
# matlab handle graphics style
a.xaxis.get_major_locator().refresh()
xticklabels = getp(a, 'xticklabels')
setp(xticklabels, 'color', 'r', fontsize='medium')
setp(xticklabels, dashdirection=0, dashlength=10, dashrotation=90)
#savefig('axprops_demo')
show()
even with a.xaxis.get_major_locator().refresh(), only the first ticklabel
has its position adjusted.
replacing
setp(xticklabels, dashdirection=0, dashlength=10, dashrotation=90)
with code modifying the position
for i in range(len(xticklabels)):
xtp = getp(xticklabels[i],'position')
setp(xticklabels[i],position=(xtp[0],-0.05))
also only effects the first ticklabel.
changes to color and fontsize of the first ticklabel do carry over the full
set of ticklabels, but TextWithDash properties do not carry over.
Uncommenting ion() at the beginning of the script generates the desired
image with offset ticklabels, but requires using interactive mode.
Any help either getting
a.xaxis.get_major_locator().refresh()
to work properly, or to get TextWithDash properties to carry over from the
initial single ticklabel to the full set of ticklabels would be greatly
appreciated.
thanks,
Charles Seaton
Research Associate
STC-CMOP
www.stccmop.org
···
--
View this message in context: http://www.nabble.com/Problem-with-tick-labels-in-scripts-tf4260235.html#a12932137
Sent from the matplotlib - users mailing list archive at Nabble.com.