How to change tick labels?

Hi,

I have a very crowded plot with lots of subplots, and tick labels tend to overlap. I wanted to drop e.g. the 1st and last x-tick labels for each subplot, doing something like:

ax = P.subplot(1,1,1)
ax.plot([1,2,3,2,1,2,3])
ax.set_xticklabels(['']+
                    [ lbl.get_text() for lbl in ax.get_xticklabels()[1:-1] ]+
                    [''])

This works in interactive 'ipython -pylab', but this does not work anymore in a script: in my script, the tick label returned by ax.get_xticklabels() are all empty strings:

print [ lbl.get_text() for lbl in ax.get_xticklabels() ]

returns

['', '', '', '', '', '', '']

It seems the tick text strings are filled in only at the very last moment (at show() time?).

Any help out there?

Cheers,

···

--
    .~. Yannick COPIN (o:>* Doctus cum libro
    /V\ Institut de physique nucléaire de Lyon
   // \\ Université de Lyon - CNRS-IN2P3
  /( )\ AIM: YnCopin ICQ: 236931013
   ^`~'^ http://snovae.in2p3.fr/ycopin/

If the plots share the same x and y axis, look at creating an axisGrid with
share_all=True, label_mode = "L",

see
http://http://matplotlib.sourceforge.net/examples/axes_grid/simple_axesgrid.html
http://matplotlib.sourceforge.net/examples/axes_grid/simple_axesgrid.html
for a simple example

Cheers

Yannick Copin-2 wrote:

···

Hi,

I have a very crowded plot with lots of subplots, and tick labels tend to
overlap. I wanted to drop e.g. the 1st and last x-tick labels for each
subplot, doing something like:

ax = P.subplot(1,1,1)
ax.plot([1,2,3,2,1,2,3])
ax.set_xticklabels(['']+
                    [ lbl.get_text() for lbl in ax.get_xticklabels()[1:-1]
]+
                    [''])

This works in interactive 'ipython -pylab', but this does not work anymore
in
a script: in my script, the tick label returned by ax.get_xticklabels()
are
all empty strings:

print [ lbl.get_text() for lbl in ax.get_xticklabels() ]

returns

['', '', '', '', '', '', '']

It seems the tick text strings are filled in only at the very last moment
(at
show() time?).

Any help out there?

Cheers,
--
    .~. Yannick COPIN (o:>* Doctus cum libro
    /V\ Institut de physique nucléaire de Lyon
   // \\ Université de Lyon - CNRS-IN2P3
  /( )\ AIM: YnCopin ICQ: 236931013
   ^`~'^ http://snovae.in2p3.fr/ycopin/

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the
business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


View this message in context: http://old.nabble.com/How-to-change-tick-labels--tp27340373p29057393.html
Sent from the matplotlib - users mailing list archive at Nabble.com.