From: John Hunter <jdhunter@ac...> - 2006-03-30 21:05:37
>>>>> "Caleb" == Caleb Hattingh <caleb.hattingh@...> writes:
Caleb> Hi John I posted the following item on comp.lang.python,
Caleb> but actually you're exactly who I was looking for, and I
Caleb> could your address off one of your responses to another's
Caleb> question (I didn't know you read news). By the way,
Caleb> Matplotlib is one of the best python addons I have ---no
Caleb> more printing Excel graphs to postscript files :)
Caleb> I tried several Google searches to no avail. I read
Caleb> through pretty much most of the online docs at the
Caleb> matplotlib sourceforge site, but didn't find what I was
Caleb> looking for. I went through the axis.py and ticker.py code
Caleb> today, trying to find out how to set the number of points
Caleb> (ticks) on an axis in Matplotlib.
Caleb> I know that something like
Caleb> will make the x-axis have the values specified, but
Caleb> Matplotlib appears to have a very nice way of setting axis
Caleb> ticks with human-friendly values that round in just the
Caleb> right way for a given set of data. I still want that
Caleb> functionality, but I want to set how many ticks are on a
Caleb> given axis.
Caleb> It seems that the locater() classes are where I should
Caleb> look, and there seem to be some defaults in ticker.py:
Caleb> class AutoLocator(MaxNLocator): def __init__(self):
Caleb> MaxNLocator.__init__(self, nbins=9, steps=[1, 2, 5, 10])
Caleb> I don't understand what this means :)
Caleb> I would prefer not to hack this directly in the matplotlib
Caleb> code. How can I change the number of ticks on an axis
Caleb> programmatically without messing with the other ticklabel
Caleb> functionality? Caleb
Caleb> You probably know exactly what I need to do?
Yes, you will want to use a MaxNLocator. Note that the MaxNLocator
sets the maximum number of *intervals* so the maxnumber of ticks will
be the max number of intervals plus one. You could probably adapt
this code to make an ExactNLocator. If you do, please send it our way.
from matplotlib.ticker import MaxNLocator
from pylab import figure, show, nx
fig = figure()
ax = fig.add_subplot(111)
Also, please post questions to the matplotlib-users mailing list
rather than to me directly, as there are plenty of experts there
(unlink on c.l.python) who can help you.
Glad you're enjoying matplotlib!