matplotlib中的网格

问题描述 投票:0回答:1

在matplotlib中,如何制作图以显示更多的网格线。非常宽。 enter image description here

matplotlib plot grid
1个回答
1
投票

您可以打开较小的刻度线,然后为这些刻度线指定一个“较小的”网格:

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()

结果:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.