Search code examples
pythonseabornviolin-plot

How to split violin plot with separate confidence interval


How could I make violin figures like this. I want to include confidence interval enter image description here I can use the following code to plot split figures with quadrilles, but not mean and confidence. The data can be found here. https://drive.google.com/file/d/18GrncA2GmJd38tVGZZ5yylR6Cf61XsGp/view?usp=sharing

import matplotlib.pyplot as plt
import seaborn as sns

sns.violinplot(x="six.categories", y="non_poor", hue="year", data=df, split=True,
               inner="quart", palette={"2019": "b", "2020": "y"})
sns.despine(left=True)

plt.xticks(np.arange(6),["Nonpoor\nWhite", "Poor\nWhite", "Poor\nBlack", "Nonpoor\nBlack", "Poor\nHispanic", "Nonpoor\nHispanic"])

Solution

  • You can combine a violinplot and a pointplot for the desired result:

    tips = sns.load_dataset('tips')
    ax = sns.violinplot(x="day", y="total_bill", hue="smoker",
                        data=tips, palette="muted", split=True, inner=None)
    sns.pointplot(x="day", y="total_bill", hue="smoker",
                        data=tips, dodge=0.2, join=False, palette=['white'], ax=ax)
    

    enter image description here