How to select ticks at n-positions in the log chart?

In matplotlib, once the main ticks are too close to each other on the chart loglog. Instead of installing them manually, is it possible to use something similar MaxNLocatorto setting ticks at n-places in the log scale?

import numpy as np
import pylab as p

x=np.logspace(1,20,10)

fig=p.figure()
ax1=fig.add_subplot(121)
ax1.loglog(x,x,'o')
ax2=fig.add_subplot(122)
ax2.loglog(x,x,'o')
fig.show()

Figure

+5
source share
2 answers

For each axis, you can set LogLocator :

ax.xaxis.set_major_locator(ticker.LogLocator(base = 1000.0))

enter image description here

+3
source

In the latest version of matplotlib (1.2.0), to get something more like MaxNLocator you can also use @unutbu's solution with

ax.xaxis.set_major_locator(ticker.LogLocator(numticks=6))
+4
source

All Articles