相关疑难解决方法(0)

Seaborn:使用不对称的自定义误差条按组制作条形图

我有一个 Pandas 数据框,它有几个组列,如下所示。

gr1 grp2 variables  lb     m       ub
 A   A1      V1     1.00   1.50    2.5           
 A   A2      V2     1.50   2.50    3.5         
 B   A1      V1     3.50   14.50   30.5           
 B   A2      V2     0.25   0.75    1.0
Run Code Online (Sandbox Code Playgroud)

我正在尝试为variables使用中的每个变量获得一个单独的子条形图FacetGrid。我正在尝试构建我需要的最终图,如下所示。

使用 FacetGrid 和多个分类变量绘图

这是我到目前为止。

g = sns.FacetGrid(df, col="variables", hue="grp1")
g.map(sns.barplot, 'grp2', 'm', order=times)
Run Code Online (Sandbox Code Playgroud)

但不幸的是,这堆积了我所有的数据点。

我该Seaborn怎么做呢?

更新:以下代码在很大程度上完成了我所追求的但目前不显示yerr.

g = sns.factorplot(x="Grp2", y="m", hue="Grp1", col="variables", data=df, kind="bar", size=4, aspect=.7, sharey=False)
Run Code Online (Sandbox Code Playgroud)

如何将lbub作为误差线合并到因子图上?

python plot data-visualization matplotlib seaborn

3
推荐指数
1
解决办法
2778
查看次数

将错误栏添加到pandas中的分组条形图中

我首先生成以下DataFrame,在pandas中生成一个图:

plotData=resultData.groupby(['student_model','lo_id']).describe().nShots.unstack().reset_index()
plotData['se'] = plotData['std']/np.sqrt(plotData['count'])
Run Code Online (Sandbox Code Playgroud)

结果数据框如下所示: 在此输入图像描述

然后我像这样转动和绘图:

plotData.pivot(index='student_model',columns='lo_id',values='mean').plot(kind='bar')
Run Code Online (Sandbox Code Playgroud)

导致以下结果:

在此输入图像描述

这一切都很好,但我需要将"se"列中的值作为错误栏添加到绘图中,并且无法使其工作.我知道我可以添加一个参数来调用plot(即...plot(kind='bar', yerr=???)),但我不知道如何正确格式化它以使其正常工作.有任何想法吗?

python matplotlib pandas

2
推荐指数
1
解决办法
2978
查看次数

标签 统计

matplotlib ×2

python ×2

data-visualization ×1

pandas ×1

plot ×1

seaborn ×1