SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Eugen W. <eug...@jk...> - 2007年08月13日 09:42:47
Attachments: test.py
Hi there
 I have some problem with accessing ticklabels in a script (see
attachment). The output of the script looks pretty strange to me:
<a list of 1 Text ticklabel objects>
<a list of 7 Text ticklabel objects>
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 would like to access the labels before the final show command in a
script. But how is this possible with this behavior? 
Best regards 
 Eugen
-- 
--------------------------------------------
| |
| Dipl. Ing. Eugen Wintersberger |
| Department of semicondutor physics |
| University of Linz |
| Altenbergerstrasse 69 |
| A-4040 Linz |
| Austria |
| |
| Mobile.: +43 664 3112861 |
| Tel.: +43 732 2468 9605 |
| E-Mail.: eug...@jk... |
| Skype: eugen20056221 |
| ICQ: 214418739, nickname: thot |
| |
--------------------------------------------
From: <jk...@ik...> - 2007年08月13日 12:21:40
Eugen Wintersberger <eug...@jk...>
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()
-- 
Jouni K. Seppänen
http://www.iki.fi/jks
From: Charles S. <cs...@st...> - 2007年09月27日 23:25:42
Looking back through the archives, I found this discussion of manipulating
ticklabels.
Jouni K. Sepp=C3=A4nen wrote:
>=20
> Eugen Wintersberger <eug...@jk...>
> writes:
>=20
>> 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()?
>=20
> 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.
>=20
>> I would like to access the labels before the final show command in a
>> script. But how is this possible with this behavior?=20
>=20
> 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:
>=20
> a.xaxis.get_major_locator().refresh()
>=20
I am having the same problem as Eugen, and the suggested solution of using=
=20
a.xaxis.get_major_locator().refresh()
to force the creation of the full set of ticklabels doesn't seem to work fo=
r
me.
Sample script:
from pylab import *
#ion()
a =3Daxes([0.2,0.2,0.7,0.7])
t =3D arange(0.0, 2.0, 0.01)
s =3D sin(2*pi*t)
a.plot(t, s)
a.grid(True)
# matlab handle graphics style
a.xaxis.get_major_locator().refresh()
xticklabels =3D getp(a, 'xticklabels')
setp(xticklabels, 'color', 'r', fontsize=3D'medium')
setp(xticklabels, dashdirection=3D0, dashlength=3D10, dashrotation=3D90)
#savefig('axprops_demo')
show()
even with a.xaxis.get_major_locator().refresh(), only the first ticklabel
has its position adjusted.
replacing=20
setp(xticklabels, dashdirection=3D0, dashlength=3D10, dashrotation=3D90)
with code modifying the position
for i in range(len(xticklabels)):
 xtp =3D getp(xticklabels[i],'position')
 setp(xticklabels[i],position=3D(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.=20
Uncommenting ion() at the beginning of the script generates the desired
image with offset ticklabels, but requires using interactive mode.
Any help either getting=20
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.=20
thanks,
Charles Seaton
Research Associate
STC-CMOP
www.stccmop.org
--=20
View this message in context: http://www.nabble.com/Problem-with-tick-label=
s-in-scripts-tf4260235.html#a12932137
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: John H. <jd...@gm...> - 2007年09月28日 12:41:43
On 9/27/07, Charles Seaton <cs...@st...> wrote:
> 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.
matplotlib creates a prototypical tick (the prototick) and then
creates new ones on as as needed basis, copying properties from the
prototick. Of course, position is one of the properties that cannot
be copied, which is why you are having trouble in your example.
Fortunately, there is an easy solution.
Call ax.xaxis.get_major_ticks() and access the label attribute:
for tick in ax.xaxis.get_major_ticks():
 label = tick.label1
Axis.get_major_ticks will force a call to the locator and update the
tick list. The Axes methods like get_xticklabels are just working on
the existing tick list rather than calling the get_major_ticks method
which is why you are not getting the full list. This is a bug. I
just made changes in svn so that all the accessor methods
(ax.get_xticklines, ax.get_yticklabels, and friends) all trigger a
call to axis.get_major_ticks rather so they should give the same
results going forward.
JDH
FYI, the Tick attributes are:
 tick1line : a Line2D instance
 tick2line : a Line2D instance
 gridline : a Line2D instance
 label1 : a Text instance
 label2 : a Text instance
 gridOn : a boolean which determines whether to draw the tickline
 tick1On : a boolean which determines whether to draw the 1st tickline
 tick2On : a boolean which determines whether to draw the 2nd tickline
 label1On : a boolean which determines whether to draw tick label
 label2On : a boolean which determines whether to draw tick label
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /