matplotlib 添加次要网格线

zbq4xfa0  于 2023-10-24  发布在  其他
关注(0)|答案(2)|浏览(101)

但我似乎不知道如何显示小网格线在我的情节与海运风格。

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sbn

x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)

fig, ax = plt.subplots(1, 1)
ax.scatter(x, y)

ax.grid(b=True, which='major')
ax.grid(b=True, which='minor')

有什么想法吗?也有任何关于如何调整海上网格线的风格的想法,特别是,我想让他们更窄。

fbcarpbf

fbcarpbf1#

最后,我把朱兆强的回答和卡斯韦尔的暗示结合起来:

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sbn

x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)

fig, ax = plt.subplots(1, 1)

ax.scatter(x, y)
ax.get_xaxis().set_minor_locator(mpl.ticker.AutoMinorLocator())
ax.get_yaxis().set_minor_locator(mpl.ticker.AutoMinorLocator())
ax.grid(b=True, which='major', color='w', linewidth=1.0)
ax.grid(b=True, which='minor', color='w', linewidth=0.5)

a0x5cqrl

a0x5cqrl2#

这是因为次要tick还没有定义,所以我们需要添加例如:

ax.set_xticks(np.arange(0,8)-0.5, minor=True)
ax.set_yticks([-1.25, -0.75, -0.25,0.24,0.75,1.25], minor=True)

相关问题