Matplotlib axes label

attn.steven.kuo at gmail.com attn.steven.kuo at gmail.com
Fri Mar 2 16:22:05 CET 2007


On Mar 2, 7:02 am, "John Henry" <john106he... at hotmail.com> wrote:
> On Mar 1, 10:07 pm, "John Henry" <john106he... at hotmail.com> wrote:
>
>
>
> > On Mar 1, 9:53 pm, attn.steven.... at gmail.com wrote:
>

(snipped)

> > > You can try adjusting the labels and ticks
> > > using matplotlib.ticker.
>
> > > To the example you cited, one can add
>
> > > from matplotlib.ticker import MultipleLocator, FormatStrFormatter
>
> > > # ...
>
> > > minorLocator = MultipleLocator(0.1)
> > > minorFormattor = FormatStrFormatter('%0.1f')
> > > ax.yaxis.set_minor_locator(minorLocator)
> > > ax.yaxis.set_minor_formatter(minorFormattor)
>
> > > show()
>
>
> > Thank you for the response.  Yes, adding those lines did work.
>
> > But what exactly is going on here?  Why would adding these two lines
> > works?
>
> > Thanks,
>
> Okay, I played with the ticker formater and locator routines.
> Unfortunately, it doesn't help.  The locator sets the major value and
> the formatter determines how the axes label is formatted.  It doesn't
> gurantee that the first label starts at the origin.  Half of my plots
> works, and half of them doesn't.





As default, matplotlib places labels and tick marks
at major ticks.  Minor ticks are invisible as
a default.

The lines that I added turned on *minor*
ticks and their labels; I set them to appear
at integer multiples of 0.1 and I
formatted them as floating point numbers.

There's nothing to prevent you from
having minor ticks appear at intervals
that exceed those of major ticks.  E.g.,

minorLocator = MultipleLocator(1.1)

# etc.

--
Hope this helps,
Steven




More information about the Python-list mailing list