python-显示条形图标准偏差的Seaborn错误

python-显示条形图标准偏差的Seaborn错误,python,pandas,seaborn,Python,Pandas,Seaborn,这是我的密码 我想使用seaborn软件包添加误差条作为数据的标准偏差。但是我得到了类型错误 import pandas as pd %matplotlib inline import seaborn as sns import matplotlib.pyplot as plt example = pd.DataFrame({"value": [2,3,4,5,6,7], "category":[1,2,1,2,1,2]}) sns.barpl

这是我的密码

我想使用seaborn软件包添加误差条作为数据的标准偏差。但是我得到了类型错误

    import pandas as pd
    %matplotlib inline
    import seaborn as sns
    import matplotlib.pyplot as plt

    example = pd.DataFrame({"value": [2,3,4,5,6,7], "category":[1,2,1,2,1,2]})

    sns.barplot(data= example, x='category', y= 'value', ci = 'sd')
像这样的错误

    ------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-73-d39dbb59d2cc> in <module>()
    ----> 1 sns.barplot(data= example, x='category', y= 'value', ci = 'sd')

    C:\Users\SamSung\Anaconda3\lib\site-packages\seaborn\categorical.py in barplot(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, orient, color, palette, saturation, errcolor, errwidth, capsize, ax, **kwargs)
       2897                           estimator, ci, n_boot, units,
       2898                           orient, color, palette, saturation,
    -> 2899                           errcolor, errwidth, capsize)
       2900 
       2901     if ax is None:

    C:\Users\SamSung\Anaconda3\lib\site-packages\seaborn\categorical.py in __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, orient, color, palette, saturation, errcolor, errwidth, capsize)
       1543                                  order, hue_order, units)
       1544         self.establish_colors(color, palette, saturation)
    -> 1545         self.estimate_statistic(estimator, ci, n_boot)
       1546 
       1547         self.errcolor = errcolor

    C:\Users\SamSung\Anaconda3\lib\site-packages\seaborn\categorical.py in estimate_statistic(self, estimator, ci, n_boot)
       1450                                       n_boot=n_boot,
       1451                                       units=unit_data)
    -> 1452                     confint.append(utils.ci(boots, ci))
       1453 
       1454             # Option 2: we are grouping by a hue layer

    C:\Users\SamSung\Anaconda3\lib\site-packages\seaborn\utils.py in ci(a, which, axis)
        341 def ci(a, which=95, axis=None):
        342     """Return a percentile range from an array of values."""
    --> 343     p = 50 - which / 2, 50 + which / 2
        344     return percentiles(a, p, axis)
        345 

    TypeError: unsupported operand type(s) for /: 'str' and 'int'
------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在()
---->1 sns.barplot(数据=示例,x='category',y='value',ci='sd')
C:\Users\SamSung\Anaconda3\lib\site packages\seaborn\category.py条形图(x、y、色调、数据、顺序、色调顺序、估计器、ci、n\u引导、单位、方向、颜色、调色板、饱和度、errcolor、errwidth、翻转、ax、**kwargs)
2897估算器,ci,n_引导,单位,
2898方向、颜色、调色板、饱和度、,
->2899 errcolor、errwidth、倾覆)
2900
2901如果ax为无:
C:\Users\SamSung\Anaconda3\lib\site packages\seaborn\category.py in\uuuuuuuu init\uuuuuuuuuu(self、x、y、色调、数据、顺序、色调顺序、估计器、ci、n\u引导、单位、方向、颜色、调色板、饱和度、errcolor、errwidth、翻转)
1543订单,顺化订单,单位)
1544.自行确定颜色(颜色、调色板、饱和度)
->1545.自我估计统计(估计量、ci、n_引导)
1546
1547 self.errcolor=errcolor
C:\Users\SamSung\Anaconda3\lib\site packages\seaborn\category.py in estimate\u statistic(self、estimator、ci、n\u boot)
1450 n_boot=n_boot,
1451单位=单位(数据)
->1452约束附加(utils.ci(boots,ci))
1453
1454#选项2:我们按色调层进行分组
C:\Users\SamSung\Anaconda3\lib\site packages\seaborn\utils.py在ci中(a,which,axis)
341 def ci(a,其中=95,轴=无):
342“从值数组返回百分位范围。”“”
-->343 p=50-哪个/2,50+哪个/2
344返回百分位(a、p、轴)
345
TypeError:/:“str”和“int”的操作数类型不受支持

为什么会这样?我该如何解决这个问题呢?

Seaborn在0.8.0版中增加了使用
ci='sd'
的功能:

摘自“包v0.8.0中的新增内容(2017年7月)”:

“添加了在大多数统计函数中使用误差条来显示标准偏差而不是引导置信区间的功能,方法是放置ci=“sd”。”

见-


您需要更新Seaborn才能使用此功能。

Seaborn添加了在0.8.0版中使用
ci='sd'
的功能:

摘自“包v0.8.0中的新增内容(2017年7月)”:

“添加了在大多数统计函数中使用误差条来显示标准偏差而不是引导置信区间的功能,方法是放置ci=“sd”。”

见-

您需要更新Seaborn才能使用此功能