如何在带有多列图的seaborn catplot中添加垂直网格线

dee*_*wal 2 matplotlib python-3.x seaborn

我想使用以下代码绘制猫图。

import seaborn as sns
sns.set_theme(style="ticks")
exercise = sns.load_dataset("exercise")
sns.set_style({'axes.grid': True})
g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise)
Run Code Online (Sandbox Code Playgroud)

但这不会绘制垂直网格线。我怎样才能添加它们?

Diz*_*ahi 7

看起来seaborn主动关闭了垂直网格线(参见此处)。

您必须在创建的每个轴上重新启用它们catplot

sns.set_style("ticks")
exercise = sns.load_dataset("exercise")
g = sns.catplot(x="time", y="pulse", hue="kind", data=exercise)
for ax in g.axes.flat:
    ax.grid(True, axis='both')
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述