Yannick Copin wrote:
> Hi,
> 
> I take the opportunity of a recent thread about axes label to reiterate 
> a question I posted some time ago:
> 
> Is there a way (best would be a default parameters in matplotlibrc) to 
> automagically plot minor ticks?

I think that what you need to do is to explicitly set both the major and 
the minor locator to a MultipleLocator, but with different bases:

ax.xaxis.set_major_locator(MultipleLocator(base=1))
ax.xaxis.set_minor_locator(MultipleLocator(base=0.5))

This assumes you know enough about the range to know what suitable bases 
are.  If this is not the case, then you could use an explicit call to 
MaxNLocator(nminor).bin_boundaries(xmin, xmax) to help you select the 
minor base, and multiply it by 2, or 4, or 5, or whatever you like to 
get the major base.  This will work if xmax-xmin is not too far removed 
from xmax and xmin.

Eric

> 
> I *thought* I knew how to add them manually using e.g.
> ax.xaxis.set_minor_locator, but I dont know how to handle them 
> automatically. E.g. my simplest guest was to use LinearLocator:
> 
> x = randn(100)
> y = randn(100)
> plot(x,y,'bo')
> ax = gca()
> ax.xaxis.set_minor_locator(LinearLocator())
> 
> But these minor ticks wont (necessarily) be coherent with the automatic 
> major ticks:
> 
> L = ax.xaxis.get_major_locator()
> l = ax.xaxis.get_minor_locator()
> 
> print L()
> [-4. -3. -2. -1.  0.  1.  2.  3.  4.]
> 
> print l()
> [-4.  -3.2 -2.4 -1.6 -0.8  0.   0.8  1.6  2.4  3.2  4. ]
> 
> (see, it will look like |.......:.|.....:...|...:.....|.:...)
> 
> How could I do to have some minor ticks automagically coherent with the 
> automated major ticks?
> 
> Cheers.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to