deepAgrawal
deepAgrawal

Reputation: 733

How to add vertical gridlines in seaborn catplot with multiple column plots

I want to plot a catplot using the following code.

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)

But this does not plot vertical gridlines. How can I add them?

Upvotes: 2

Views: 5074

Answers (2)

RH_cloudytoast
RH_cloudytoast

Reputation: 31

You could also simply use:

sns.set_style("whitegrid")

It works with other sns plotting functions as well.

Upvotes: 3

Diziet Asahi
Diziet Asahi

Reputation: 40667

It looks like seaborn actively turns off vertical grid lines (see here).

You have to re-enable them on each axes created by 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')

enter image description here

Upvotes: 7

Related Questions