Looking at the documentation about violon plots with seaborn, I would like to know how to plot two series of violin plots on the same axis (point 1) and that they are comparable (point 2).
About point 1, I would like to reproduce that plot for each sex :
fig, ax = plt.subplots()
sns.violinplot(x="day", y="total_bill", hue="smoker",
data=tips, split=True, ax=ax)
I could do it on two subplots:
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(211)
sns.violinplot(x="day", y="total_bill", hue="smoker",
data=tips[tips.sex == "Female"], split=True, ax=ax)
ax = fig.add_subplot(212)
sns.violinplot(x="day", y="total_bill", hue="smoker",
data=tips[tips.sex == "Male"], split=True, ax=ax)
I would like to plot the two violin plot series on the same matplotlib axes.
Another point is about the width of the violin plot. I do not clearly understand if the violins are normalized or not and how ? I assume that the width is computed for each plot. On the example above the width is computed for Female for the first subplot and for Male for the second subplot. Thus can I compare directly the densities ? I suppose that I can compare the shapes but, for example, I cannot compare the amount of Male smoker on Monday and Female ones ? Is there a way to manage the normalization of the violins ?
positions
argument, this becomes quite convoluted. You could add new categoricalday
values that are unique for each sex (e.g. females getSun
and males ofSun_
). Then you can order these along the x-axis and change the xticklabels manually. As I said, not very convenient. – Calculable