且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-21 14:50:34

结合朱卓恩的答案和tcaswell的提示:

Wound up combining CT Zhu's answer with tcaswell's hint:

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)