23

I am trying to make a violinplot using only the y and hue parameters in seaborn (x data variable is defined as None). Using a similar example as in the documentation I have done:

tips = sns.load_dataset("tips")
sns.violinplot(y="total_bill", hue="sex", data=tips, split=True)

And the resulting figure is not split according to the hue variable.

enter image description here

When the x variable is defined the plot is split. Is there any way to have a split plot in seaborn without x input?

gypaetus
  • 6,873
  • 3
  • 35
  • 45

1 Answers1

42

Simply add a variable that is the same for all entries and use it as x:

tips = sns.load_dataset("tips")
tips["all"] = ""
ax = sns.violinplot(x="all", y="total_bill", hue="sex", data=tips, split=True)
ax.set_xlabel("")

enter image description here

mwaskom
  • 46,693
  • 16
  • 125
  • 127
  • 2
    This long article is not able to explain, what you have explained in 2 lines. https://seaborn.pydata.org/generated/seaborn.violinplot.html – Deepak May 27 '20 at 21:31