【问题标题】:Add error bars manually to seaborn line marker plots手动将误差线添加到 seaborn 线标记图
【发布时间】:2021-01-28 16:04:20
【问题描述】:

我有xmeanstd 的列。我想用使用 seaborn 的标记画线:

import seaborn as sns
import matplotlib.pyplot as plt

x = [0,1,2]
mean = [2,1,3]
std = [0.1,0.4,0.2]

sns.lineplot(x=x,y=mean,marker='o')

如何将std 添加为错误栏?

【问题讨论】:

    标签: python matplotlib seaborn errorbar


    【解决方案1】:

    来自 seaborn 文档,

    markers : boolean, list, or dictionary, optional
        Object determining how to draw the markers for different levels of the
        ``style`` variable. Setting to ``True`` will use default markers, or
        you can pass a list of markers or a dictionary mapping levels of the
        ``style`` variable to markers. Setting to ``False`` will draw
        marker-less lines.  Markers are specified as in matplotlib.
    

    markerslineplotstyle 选项一起使用。在你的情况下,使用marker,它被传递给plt.plot,而不是markers

    sns.lineplot(x=x,y=mean,marker='o')
    

    输出:

    【讨论】:

    • 我的错!将编辑这个 - 标准错误呢?
    【解决方案2】:

    我找到了适合我的答案:

    df = pd.DataFrame({'x':x,'y':mean,'std':std})
    
    g = sns.FacetGrid(df, size=5)
    g.map(plt.errorbar, "x", "y", "std", marker="o")
    

    【讨论】:

      猜你喜欢
      • 2021-08-06
      • 2021-01-25
      • 2016-01-04
      • 2022-11-24
      • 2020-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-23
      相关资源
      最近更新 更多