如何使用Seaborn通过分组条形图添加错误条形图

2024-05-14 09:22:53 发布

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

我已经计算了数据帧的95%置信区间。使用Seaborn将其添加到分组条形图时,我收到一个错误yerr must be a scalar or a 1D or (2, n) array-like

   Linguistic Measure   ML Models   score   ci-b    ci-t    se
0     a                  RF         0.855   0.763   0.946   0.091
1     b                  RF         0.830   0.763   0.898   0.067
2     c                  RF         0.830   0.796   0.864   0.034
3     a                  SVM        0.841   0.823   0.860   0.018
4     b                  SVM        0.831   0.812   0.851   0.019
5     c                  SVM        0.835   0.820   0.850   0.015
6     a                  MLP        0.837   0.801   0.874   0.036
7     b                  MLP        0.810   0.721   0.900   0.089
8     c                  MLP        0.798   0.702   0.894   0.096

我使用下面的代码试图将错误条添加到分组的条形图中

# Draw a nested barplot 
g = sns.catplot(
    data=sample, kind="bar", #update df
    x="Linguistic Measure", y="score", hue="ML Models",
    yerr=sample.pivot(index='Linguistic Measure',columns='ML Models',values='se').values,
    ci=None, palette="BuPu", alpha=.6, height=5)

g.despine(left=True)
g.set_axis_labels("", "score")
g.legend.set_title("")

然后我得到下面的错误消息:enter image description here

没有添加错误条,图形看起来很好enter image description here


Tags: orsamplecimodels错误mlscore条形图

热门问题