相关疑难解决方法(0)

Seaborn因子图自定义误差条

我想在seaborn中绘制一个factorplot但是手动提供误差条而不是让seaborn计算它们.

我有一个大致如下的pandas数据框:

     model output feature  mean   std
0    first    two       a  9.00  2.00
1    first    one       b  0.00  0.00
2    first    one       c  0.00  0.00
3    first    two       d  0.60  0.05
...
77   third   four       a  0.30  0.02
78   third   four       b  0.30  0.02
79   third   four       c  0.10  0.01
Run Code Online (Sandbox Code Playgroud)

我正在输出一个看起来大致如下的情节: seaborn bar情节

我正在使用这个seaborn命令来生成图:

g = sns.factorplot(data=pltdf, x='feature', y='mean', kind='bar',
                   col='output', col_wrap=2, sharey=False, hue='model')
g.set_xticklabels(rotation=90)
Run Code Online (Sandbox Code Playgroud)

但是,我无法弄清楚如何让seaborn使用'std'列作为错误栏.不幸的是,重新计算相关数据框的输出将非常耗时.

这有点类似于这个问题: 使用Seaborn FacetGrid从数据框中绘制错误条

除了我无法弄清楚如何使用matplotlib.pyplot.bar函数.

有没有办法使用seaborn factorplotFacetGrid与matplotlib结合使用?

谢谢!

python plot matplotlib pandas seaborn

13
推荐指数
1
解决办法
8231
查看次数

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
查看次数

标签 统计

matplotlib ×2

plot ×2

python ×2

seaborn ×2

data-visualization ×1

pandas ×1