reducing number of plot ticks


I have too many ticks on my graph and they are running into each other.

How can I reduce the number of ticks?

For example, I have ticks:

1E-6, 1E-5, 1E-4, ... 1E6, 1E7

And I only want:

1E-5, 1E-3, ... 1E5, 1E7

I've tried playing with the LogLocator, but I haven't been able to figure this out.

2/13/2019 12:03:55 AM

Accepted Answer

Alternatively, if you want to simply set the number of ticks while allowing matplotlib to position them (currently only with MaxNLocator), there is pyplot.locator_params,


You can specify specific axis in this method as mentioned below, default is both:

# To specify the number of ticks on both or any single axes
pyplot.locator_params(axis='y', nbins=6)
pyplot.locator_params(axis='x', nbins=10)
5/11/2018 7:59:42 AM

If somebody still gets this page in search results:

fig, ax = plt.subplots()


every_nth = 4
for n, label in enumerate(ax.xaxis.get_ticklabels()):
    if n % every_nth != 0:

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow