Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select ticks at n-positions in a log plot?

In matplotlib, sometime the major-ticks are too close to each other in a loglog plot. Instead of setting them manually, can one use something similar to MaxNLocator to put ticks at n-locations in a 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

like image 787
imsc Avatar asked Feb 14 '12 10:02

imsc


1 Answers

In the newest version of matplotlib (1.2.0), to get something more similar to MaxNLocator you could also use @unutbu 's solution with

ax.xaxis.set_major_locator(ticker.LogLocator(numticks=6))
like image 93
jarondl Avatar answered Oct 22 '22 04:10

jarondl