相关疑难解决方法(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
查看次数

如何向Pandas分组barplot添加非对称错误栏?

根据对此问题的接受答案,我能够为自己的数据重现相同的结果.但是,我需要绘制不对称误差条.

dfdict = {'ID': ['A', 'A', 'B', 'B', 'C', 'C', 'D', 'D'],
      'quarter': ['2015 2Q', '2016 1Q', '2015 2Q', '2016 1Q', '2015 2Q',
                  '2016 1Q', '2015 2Q', '2016 1Q'],
      'Percent': [0.851789, 0.333333, 0.355240, 0.167224, 1.533220,
                  0.333333, 0.170358, 0.000000],
      'AgrCoullLower': [ 0.378046, 0.057962,  0.061850, -0.027515,
                         0.866025, 0.057962, -0.028012, -0.092614],
      'AgrCoullUpper': [1.776511, 1.054612, 1.123492, 0.810851,
                        2.645141, 1.054612, 0.825960, 0.541513]}
df = pd.DataFrame(dfdict)
df
  ID  quarter   Percent  AgrCoullLower  AgrCoullUpper
0  A  2015 2Q  0.851789       0.378046       1.776511
1  A  2016 …
Run Code Online (Sandbox Code Playgroud)

python asymmetric bar-chart pandas errorbar

6
推荐指数
1
解决办法
1483
查看次数

如何在 Seaborn catplot 中指定自定义误差线?

我正在尝试使用 Python 中的 Seaborn 包来可视化一些数据。特别是,我想使用该catplot(kind='bar')函数(以前命名为factorplot())。我的数据框看起来像这样(列'x''col''row'并且'hue'是绝对的):

   x  y        dy col row hue
0  4  9  0.766591   1   0   2
1  5  9  0.688683   0   1   0
2  0  7  0.707982   0   0   1
3  3  6  0.767210   2   1   0
4  3  8  0.287153   0   1   0
Run Code Online (Sandbox Code Playgroud)

我想使用不确定性列'dy'来表示'y'. Seaborn catplots 执行的默认引导或标准偏差误差条不能为我提供令人满意的解决方案。

在这里,我提供了最小完全可验证的示例:

import pandas as pd
import numpy.random as npr
import seaborn as sns

npr.seed(seed=0) …
Run Code Online (Sandbox Code Playgroud)

python seaborn errorbar

6
推荐指数
1
解决办法
1882
查看次数

标签 统计

python ×3

errorbar ×2

pandas ×2

seaborn ×2

asymmetric ×1

bar-chart ×1

matplotlib ×1

plot ×1