gpt4 book ai didi

python - 使用 seaborn 将次要网格线添加到 matplotlib 图

转载 作者:IT老高 更新时间:2023-10-28 20:52:10 26 4
gpt4 key购买 nike

我是 Seaborn 软件包的粉丝,它使用 Matplotlib 制作漂亮的绘图。但我似乎无法弄清楚如何在我的图中显示次要网格线。

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

给予:

enter image description here

这里有什么想法吗?还有关于如何调整确实出现的 Seaborn 网格线样式的任何想法……特别是,我想让它们更窄。

最佳答案

将 CT Zhu 的回答与 tcaswell 的提示结合起来:

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)

enter image description here

关于python - 使用 seaborn 将次要网格线添加到 matplotlib 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21923463/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com