【问题标题】:python - Seaborn error for showing barplot standard deviationpython - 用于显示条形图标准偏差的 Seaborn 错误
【发布时间】:2017-07-24 23:21:02
【问题描述】:

这是我的代码。

我想使用 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'

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

【问题讨论】:

    标签: python pandas seaborn


    【解决方案1】:

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

    来自“软件包 v0.8.0(2017 年 7 月)中的新增功能”:

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

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

    您需要更新 Seaborn 才能使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-08
      • 2021-10-30
      • 2016-03-21
      • 1970-01-01
      • 2023-03-16
      • 2013-02-10
      • 1970-01-01
      相关资源
      最近更新 更多