I am working with tips data set, and here is the head of data set.
JavaScript
x
7
1
total_bill tip sex smoker day time size
2
0 16.99 1.01 Female No Sun Dinner 2
3
1 10.34 1.66 Male No Sun Dinner 3
4
2 21.01 3.50 Male No Sun Dinner 3
5
3 23.68 3.31 Male No Sun Dinner 2
6
4 24.59 3.61 Female No Sun Dinner 4
7
My code is
JavaScript
1
2
1
sns.violinplot(x='day',y='total_bill',data=tips, hue=['sex','smoker'])
2
I want a violinplot of day with total_bill in which hue is sex and smoker, but I can not find any option to set multiple values of hue
. Is there any way?
Advertisement
Answer
You could use a seaborn.catplot
in order to use 'sex'
as hue
and 'smoker'
as column for generating two side by side violinplot.
Check this code:
JavaScript
1
16
16
1
import seaborn as sns
2
import matplotlib.pyplot as plt
3
sns.set()
4
5
tips = sns.load_dataset("tips")
6
7
sns.catplot(x = "day",
8
y = "total_bill",
9
hue = "sex",
10
col = "smoker",
11
data = tips,
12
kind = "violin",
13
split = True)
14
15
plt.show()
16
which gives me this plot: