【问题标题】:Added shared error around Pandas line plot在 Pandas 线图周围添加了共享错误
【发布时间】:2022-01-05 17:14:35
【问题描述】:

我有一个漂亮的线图,但我想在现有线的上方和下方添加阴影区域来指定误差范围。我有一列已经在我的 pandas 数据框中计算了错误,但我不确定如何将它添加到我的绘图中。

fig, ax = plt.subplots()
joinedDF.plot(x='date', y='count', figsize = (15, 8), ax = ax)
ax.set_xlabel("Date")
ax.set_ylabel("Count")

【问题讨论】:

    标签: python-3.x pandas matplotlib plot line-plot


    【解决方案1】:

    基于the pandas plotting documentation,并假设您的DataFrame joinedDF 在名为err 的列中有错误,请在您当前的代码之后运行:

    plt.fill_between(joinedDF['date'], 
                     joinedDF['count'] - joinedDF['err'], 
                     joinedDF['count'] + joinedDF['err'], 
                     color='b', 
                     alpha=0.2);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-15
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多