Python 为什么不出现小网格线

Python 为什么不出现小网格线,python,python-2.7,matplotlib,Python,Python 2.7,Matplotlib,我很难让小网格线出现在绘图上。在这方面,我看到了几个这样的问题,建议使用两个网格对象(一个用于大调,一个用于小调),并建议在上添加minorticks\u 由于某些原因,当我使用下面的代码时,小网格线仍然没有出现,请任何人解释一下: from __future__ import division from matplotlib import pyplot as plt from math import log, sqrt x = range(1, 20) x_lin = x x_log = [

我很难让小网格线出现在绘图上。在这方面,我看到了几个这样的问题,建议使用两个网格对象(一个用于大调,一个用于小调),并建议在上添加
minorticks\u

由于某些原因,当我使用下面的代码时,小网格线仍然没有出现,请任何人解释一下:

from __future__ import division
from matplotlib import pyplot as plt
from math import log, sqrt

x = range(1, 20)
x_lin = x
x_log = [log(i) for i in x]

x2 = [sqrt(i) for i in x]
x2_exp = x

ax = plt.subplot(1,1,1)
p1 = ax.plot(x, x_lin, 'g--', label='linear', linewidth=2)
p2 = ax.plot(x, x_log, 'b-', label='log', linewidth=3)
p3 = ax.plot(x2, x2_exp, 'r-', label='exp', linewidth=3)
l1 = ax.legend()
g1 = ax.grid(b=True, which='both', color='k', linestyle='-')
g2 = ax.grid(b=True, which='minor', color='k', linestyle='--')
ax.minorticks_on
plt.show()
以下是我得到的:


更改:
ax.minorticks\u on
ax.minorticks\u on()
更改:
ax.minorticks\u on
ax.minorticks\u on()
以下是@M4rtini给出的答案,下面是更正后的代码和新图像:

from __future__ import division
from matplotlib import pyplot as plt
from math import log, sqrt

x = range(1, 20)
x_lin = x
x_log = [log(i) for i in x]

x2 = [sqrt(i) for i in x]
x2_exp = x

ax = plt.subplot(1,1,1)
p1 = ax.plot(x, x_lin, 'g--', label='linear', linewidth=2)
p2 = ax.plot(x, x_log, 'b-', label='log', linewidth=3)
p3 = ax.plot(x2, x2_exp, 'r-', label='exp', linewidth=3)
l1 = ax.legend()
g1 = ax.grid(b=True, which='major', color='k', linestyle='-', linewidth=0.5)
g2 = ax.grid(b=True, which='minor', color='k', linestyle='-', linewidth=0.2)
ax.minorticks_on()
plt.show()

根据@M4rtini给出的答案,这里是更正后的代码和新图像:

from __future__ import division
from matplotlib import pyplot as plt
from math import log, sqrt

x = range(1, 20)
x_lin = x
x_log = [log(i) for i in x]

x2 = [sqrt(i) for i in x]
x2_exp = x

ax = plt.subplot(1,1,1)
p1 = ax.plot(x, x_lin, 'g--', label='linear', linewidth=2)
p2 = ax.plot(x, x_log, 'b-', label='log', linewidth=3)
p3 = ax.plot(x2, x2_exp, 'r-', label='exp', linewidth=3)
l1 = ax.legend()
g1 = ax.grid(b=True, which='major', color='k', linestyle='-', linewidth=0.5)
g2 = ax.grid(b=True, which='minor', color='k', linestyle='-', linewidth=0.2)
ax.minorticks_on()
plt.show()