Is there an easy way to turn on automatic subticks?

I am making regular Cartesian coordinate graphs with linear scales on the axis. I would really like to have automatic subticks to make reading data easier. Is there an easy way to do this?

Thanks
-mike w.

Yes, you just need to set a locator for the minor ticks, which is set
to NullLocator by default.

import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
plt.plot([1,2,3])
ax = plt.gca()
ax.xaxis.set_minor_locator(MaxNLocator(nbins=30, steps=[1, 2, 5, 10]))
plt.show()

You might also want to look at:

http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo1.html?highlight=codex%20minor

Ryan

···

On Fri, Oct 16, 2009 at 12:23 PM, Michael Waters <mjwaters@...243...> wrote:

I am making regular Cartesian coordinate graphs with linear scales on
the axis. I would really like to have automatic subticks to make reading
data easier. Is there an easy way to do this?

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

Ryan May wrote:

···

On Fri, Oct 16, 2009 at 12:23 PM, Michael Waters <mjwaters@...243...> wrote:
  

I am making regular Cartesian coordinate graphs with linear scales on
the axis. I would really like to have automatic subticks to make reading
data easier. Is there an easy way to do this?
    
Yes, you just need to set a locator for the minor ticks, which is set
to NullLocator by default.

import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
plt.plot([1,2,3])
ax = plt.gca()
ax.xaxis.set_minor_locator(MaxNLocator(nbins=30, steps=[1, 2, 5, 10]))
plt.show()

You might also want to look at:

http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo1.html?highlight=codex%20minor

Ryan

That does it! Thanks a bunch.

-mike w.