【问题标题】:AttributeError: Unknown property yerrAttributeError:未知属性 yerr
【发布时间】:2018-03-16 22:25:13
【问题描述】:

当我在没有误差线的情况下进行绘图时,我已经能够使用 matplotlib 获得我的绘图。但是,当我尝试添加 yerr 参数(以获取标准错误栏)时,我收到错误 AttributeError: Unknown property yerr

错误代码是:

for i in range (3):
    j=i+1
plt.plot([1,2],[totalcount_baseline[i], totalcount_treatment[i]], yerr=[yerr_list_baseline[i], yerr_list_treatment[i]], label='label%d'%j)

如上代码所示,1 和 2 是我的 x 轴值,totalcount 是 y 轴值,yerr 包含两个数值的列表。

如果我删除 yerr 参数,我的代码可以工作(显示图)。

   plt.plot([1,2],[totalcount_baseline[i], totalcount_treatment[i]], label='label%d'%j)

那么,如何修改我的代码来获取错误栏?

【问题讨论】:

  • 最有趣的是plt.plot([1,2],[2,3], some_argument_I_just_invented=True) 也不起作用。神秘!

标签: python matplotlib


【解决方案1】:

pyplot.plt 不提供错误栏。使用正确的函数,pyplot.errorbar

plt.errorbar(x=[1,2],
             y=[totalcount_baseline[i], totalcount_treatment[i]],
             yerr=[yerr_list_baseline[i], yerr_list_treatment[i]],
             label='label%d'%j)

【讨论】:

    猜你喜欢
    • 2018-11-03
    • 1970-01-01
    • 2018-12-01
    • 2018-12-24
    • 1970-01-01
    • 2023-01-04
    • 1970-01-01
    • 1970-01-01
    • 2015-02-07
    相关资源
    最近更新 更多