2017-07-24 170 views
0

这是我的代码。python - 显示barplot标准差的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.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' 

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

回答

2

Seaborn加入到使用ci='sd'在0.8.0版本的功能:

从“什么是在包v0.8.0(2017年七月)新”:

“添加到使用误差线的能力在大多数统计函数中显示标准偏差而不是自举置信区间,方法是将ci =“sd”。“

见式http://seaborn.pydata.org/whatsnew.html

你需要更新Seaborn使用此。