matplotlib中的网格

matplotlib中的网格,matplotlib,plot,grid,Matplotlib,Plot,Grid,在matplotlib中,如何使绘图显示更多网格线。它很宽 可以启用次刻度,然后为这些刻度指定“次”栅格: from matplotlib import pyplot import matplotlib import numpy as np t = np.arange(0.0, 2.0, 0.01) s = np.sin(2 * np.pi * t) fig, ax = pyplot.subplots() ax.plot(t, s) # Major ticks -- these are t

在matplotlib中,如何使绘图显示更多网格线。它很宽

可以启用次刻度,然后为这些刻度指定“次”栅格:

from matplotlib import pyplot
import matplotlib
import numpy as np

t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2 * np.pi * t)

fig, ax = pyplot.subplots()
ax.plot(t, s)

# Major ticks -- these are the ones that will show up on the plot
ax.set_xticks([0.25, 0.75, 1.25, 1.75])
ax.grid()

# Turn on minor ticks, this turns on minor grid
ax.minorticks_on()

# Change style of major and minor grids
# Major grid style
ax.grid(which='major', linestyle='-', linewidth='1.', color='red')

# Minor grid style
ax.grid(which='minor', linestyle=':', linewidth='0.5', color='black')

pyplot.show()
结果:


您可以在x轴上添加更多记号吗?或者您希望保持[10,20,30,40,50]滴答声?