matplotlib globaly set spacing/ number of ticks/ tickslabels

matplotlib

Solution

You can change the `__init__` method of AutoLocator to your function, before any plot:

import pylab as pl
from matplotlib import ticker

def AutoLocatorInit(self):
    ticker.MaxNLocator.__init__(self, nbins=4, steps=[1, 2, 5, 10])
ticker.AutoLocator.__init__ = AutoLocatorInit

pl.plot(pl.randn(100))
pl.figure()
pl.hist(pl.randn(1000), bins=40)
pl.show()

Problem

In my plots the yticks are much too close to each other(since I changed the yticks font). So I'd like to limit/fix the number of yticks. Since I have hundreds of plots I would like to change that "globaly" (in matplotlibrc or using a dictionary etc.) Any ideas out there? Something like `ax.xaxis.set_major_locator(MaxNLocator(4))` but globally BTW: I cannot find how to reference the axes without using a subplot. Any hints?

Original source