Seaborn:在直方图上用误差条覆盖箱形图或均值 [英] Seaborn: Overlaying a box plot or mean with error bars on a histogram

查看:237
本文介绍了Seaborn:在直方图上用误差条覆盖箱形图或均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以非常标准的方式在Seaborn中创建数据的直方图,即:

I am creating a histogram in Seaborn of my data in a pretty standard way, ie:

rc = {'font.size': 32, 'axes.labelsize': 28.5, 'legend.fontsize': 32.0, 
    'axes.titlesize': 32, 'xtick.labelsize': 31, 'ytick.labelsize': 12}
sns.set(style="ticks", color_codes=True, rc = rc)
plt.figure(figsize=(25,20),dpi=300)

ax = sns.distplot(synData['SYNERGY_SCORE'])
print (np.mean(synData['SYNERGY_SCORE']), np.std(synData['SYNERGY_SCORE']))
# ax = sns.boxplot(synData['SYNERGY_SCORE'], orient = 'h') 

ax.set(xlabel = 'Synergy Score', ylabel = 'Frequency', title = 'Aggregate Synergy Score Distribution')

这将产生以下输出:

我还想在同一图中可视化此数据集的平均值+标准差在x轴上(或x轴正上方)有一个均值点和带缺口的误差棒显示标准偏差。另一种选择是包围x轴的箱线图。我尝试仅添加注释掉的行(sns.boxplot()),但它看起来非常丑陋,根本不符合我的要求。有建议吗?

I also want to visualize the mean + standard deviation of this dataset on the same plot, ideally by having a point for the mean on the x-axis (or right above the x-axis) and notched error bars showing the standard deviation. Another option is a boxplot hugging the x-axis. I tried just adding the line which is commented out (sns.boxplot()), but it looks super ugly and not at all what I'm looking for. Any suggestions?

推荐答案

箱线图是在分类轴上绘制的,不会与直方图的密度轴很好地共存,但可以使用x轴双轴图来完成:

The boxplot is drawn on a categorical axis and won't coexist nicely with the density axis of the histogram, but it's possible to do it with a twin x axis plot:

import numpy as np
import seaborn as sns

x = np.random.randn(300)
ax = sns.distplot(x)
ax2 = ax.twinx()
sns.boxplot(x=x, ax=ax2)
ax2.set(ylim=(-.5, 10))

这篇关于Seaborn:在直方图上用误差条覆盖箱形图或均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆