31

Here is a simple plot:

enter image description here

1) How to disable the ticks? 2) How to reduce their number?

Here is a sample code:

from pylab import *
import numpy as np

x = [5e-05, 5e-06, 5e-07, 5e-08, 5e-09, 5e-10]
y = [-13, 14, 100, 120, 105, 93]

def myfunc(x,p):
    sl,yt,yb,ec=p    
    y = yb + (yt-yb)/(1+np.power(10, sl*(np.log10(x)-np.log10(ec))))
    return y

xp = np.power(10, np.linspace(np.log10(min(x)/10), np.log10(max(x)*10), 100))

pxp=myfunc(xp, [1,100,0,1e-6])
subplot(111,axisbg="#dfdfdf")
plt.plot(x, y, '.', xp, pxp, 'g-', linewidth=1)   
plt.xscale('log')

plt.grid(True,ls="-", linewidth=0.4, color="#ffffff", alpha=0.5)


plt.draw()
plt.show()

Which produces: enter image description here

Danial Tz
  • 1,884
  • 1
  • 15
  • 20
  • For more control: [how to turn on minor ticks only on y axis matplotlib](https://stackoverflow.com/questions/12711202/how-to-turn-on-minor-ticks-only-on-y-axis-matplotlib) – Herpes Free Engineer Jul 06 '18 at 08:34

3 Answers3

52
plt.minorticks_off()

Turns em off!

To change the number of them/position them, you can use the subsx parameter. like this:

plt.xscale('log', subsx=[2, 3, 4, 5, 6, 7, 8, 9])

From the docs:

subsx/subsy: Where to place the subticks between each major tick. Should be a sequence of integers. For example, in a log10 scale: [2, 3, 4, 5, 6, 7, 8, 9]

will place 8 logarithmically spaced minor ticks between each major tick.

fraxel
  • 34,470
  • 11
  • 98
  • 102
  • 2
    Well, this is one reason that I can not use the matplotlib's documentation nicely. One huge help file without separation. I still cannot find the documentation for this function. Many thanks! – Danial Tz May 28 '12 at 09:11
  • @Danial Tz - yeah the volume of documentation is nuts! – fraxel May 28 '12 at 09:18
33

Calling plt.minorticks_off() will apply this to the current axis. (The function is actually a wrapper to gca().minorticks_off().)

You can also apply this to an individual axis in the same way:

import matplotlib.pyplot as plt
fig, ax = plt.subplots()

ax.minorticks_off()
marshall.ward
  • 6,758
  • 8
  • 35
  • 50
1
from pylab import *
import numpy as np


x = [5e-05, 5e-06, 5e-07, 5e-08, 5e-09, 5e-10]
y = [-13, 14, 100, 120, 105, 93]

def myfunc(x,p):
    sl,yt,yb,ec=p    
    y = yb + (yt-yb)/(1+np.power(10, sl*(np.log10(x)-np.log10(ec))))
    return y

xp = np.power(10, np.linspace(np.log10(min(x)/10), np.log10(max(x)*10), 100))

pxp=myfunc(xp, [1,100,0,1e-6])
ax=subplot(111,axisbg="#dfdfdf")
plt.plot(x, y, '.', xp, pxp, 'g-', linewidth=1)   
plt.xscale('log')
plt.grid(True,ls="-", linewidth=0.4, color="#ffffff", alpha=0.5)
plt.minorticks_off() # turns off minor ticks

plt.draw()
plt.show()
FakeDIY
  • 1,425
  • 2
  • 14
  • 23