在Seaborn小提琴图上绘制额外的分位数

2024-04-19 17:49:34 发布

您现在位置:Python中文网/ 问答频道 /正文

使用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
(来源:pydata.org

2.97的水平分布线和两个百分数的水平线怎样才能画出呢?在


Tags: orgimporthttp示例stylehtmlasseaborn
1条回答
网友
1楼 · 发布于 2024-04-19 17:49:34

这里有一个相当老套的解决方案:

在你的小提琴图上再画一个方块图怎么样?(并在方框图中隐藏方框。)

以下是使用2.5和97.5的输出:

enter image description here

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()

相关问题 更多 >