【问题标题】:How to show the value of the error bars generated by seaborn?如何显示seaborn产生的误差线的值?
【发布时间】:2019-10-28 10:06:50
【问题描述】:

我正在尝试使用 seaborns 可视化一些数据。我正在使用设置为条形图的 catplot。我让它显示误差线是标准偏差。我想知道它在可视化中使用的平均值和标准偏差是什么值,但是我不知道如何从图中检索该信息。我将如何获取这些信息?

bar_graph = seaborn.catplot(x="x", y="y", hue="z", data=data, ci="sd", capsize=0.1, kind="bar")

【问题讨论】:

    标签: python pandas dataframe data-visualization seaborn


    【解决方案1】:

    试图从 seaborn 生成的情节中获取数据并非不可能,但会非常麻烦,因为 seaborn 不会返回它创建的艺术家,而catplot() 可以生成许多子情节等。

    但是,我希望您不需要从绘图中获取数据,您可以直接从数据框中获取它们,不是吗?这个简单的演示表明绘图和计算值确实匹配:

    titanic = sns.load_dataset("titanic")
    sns.catplot(x='sex',y='age',hue="class", data=titanic, ci="sd", capsize=0.1, kind="bar")
    

    titanic.groupby(['sex','class'])['age'].describe()[['mean','std']]
    
                    mean        std
    sex     class       
    female  First   34.611765   13.612052
            Second  28.722973   12.872702
            Third   21.750000   12.729964
    male    First   41.281386   15.139570
            Second  30.740707   14.793894
            Third   26.507589   12.159514
    

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 1970-01-01
      • 2017-08-26
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 2017-02-26
      • 2021-09-29
      • 2021-04-12
      相关资源
      最近更新 更多