简体   繁体   中英

Plot Additional Quantiles on Seaborn Violin Plots

Using the example on http://seaborn.pydata.org/generated/seaborn.violinplot.html :

import seaborn as sns
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.violinplot(x="day", y="total_bill", data=tips)

Violin plot http://seaborn.pydata.org/_images/seaborn-violinplot-2.png

How can I draw two small horizontal lines on top of each violin (like the caps of error bars indicating the 2.5 percentile and the 97.5 percentile of the distribution?

Here is a rather hacky solution:

What about drawing another boxplot on top of your Violin plot? (And hiding the box in the box plot.)

Here is the output using 2.5 and 97.5:

在此处输入图片说明

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_style("whitegrid")
tips = sns.load_dataset("tips")

sns.boxplot(x="day", y="total_bill", data=tips, showfliers=False, showbox=False, whis=[2.5,97.5])
sns.violinplot(x="day", y="total_bill", data=tips)

plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM