【问题标题】:Add custom error bars to seaborn regplot and residplot向 seaborn regplot 和 residplot 添加自定义误差线
【发布时间】:2021-02-23 12:11:15
【问题描述】:

有没有一种方法可以向 seaborn regplot 和 residplot 添加自定义错误栏,就像使用 yerr 使用 matplotlib 错误栏一样?例子在这里;如果我只是添加一个 yerr 参数,则会发生错误,

import seaborn as sns

xd = [1,2,3,4,6,7]
yd = [2,4,7,9,12,14]
yerrd = [1,2,1,3,1,4]

sns.regplot(xd, yd)

sns.residplot(xd, yd)

【问题讨论】:

    标签: python matplotlib plot seaborn data-visualization


    【解决方案1】:

    使用 matplotlib 的 errorbar 绘制误差线

    xd = [1,2,3,4,6,7]
    yd = [2,4,7,9,12,14]
    yerrd = [1,2,1,3,1,4]
    fig, ax = plt.subplots()
    sns.regplot(xd, yd, ax=ax)
    ax.errorbar(xd, yd, yerr=yerrd, fmt='none', capsize=5, zorder=1, color='C0')
    

    【讨论】:

    • residplot 没那么快。这个想法是使用 seaborn 功能,但只需为其添加错误栏。
    • seaborn 函数无法做到这一点
    猜你喜欢
    • 2021-07-22
    • 2015-08-03
    • 2020-08-08
    • 1970-01-01
    • 2020-03-13
    • 2018-07-27
    • 2019-03-16
    相关资源
    最近更新 更多