我确信这相对容易,但我似乎无法让它发挥作用。我想使用 matplotlib 模块绘制此 df,其中日期为 x 轴,gas 为 y 轴,std 为错误栏。我可以使用 pandas 包装器让它工作,但我不知道如何设置错误栏的样式。
使用 Pandas matplotlib 包装器
我可以使用 matplotlib pandas wrapper trip.plot(yerr='std', ax=ax, marker ='D')
绘制误差线但是我不确定如何使用 plt.errorbar()
使用 Matplotlib
fig, ax = plt.subplots()
ax.bar(trip.index, trip.gas, yerr=trip.std)
或
plt.errorbar(trip.index, trip.gas, yerr=trip.std)
上面的代码抛出这个错误TypeError: unsupported operand type(s) for -: 'float' and 'instancemethod'
所以基本上,我想要帮助的是使用标准 matplotlib 模块而不是 pandas 包装器绘制错误栏。
DF ==
date gas std
0 2015-11-02 6.805351 7.447903
1 2015-11-03 4.751319 1.847106
2 2015-11-04 2.835403 0.927300
3 2015-11-05 7.291005 2.250171
最佳答案
std
是数据帧上的一种方法,例如 df.std()
。
使用
plt.errorbar(trip.index, trip['gas'], yerr=trip['std'])
或者如果你有 mpl1.5.0+
plt.errorbar(trip.index, 'gas', yerr='std', data=trip)
关于python - 使用 pandas dataframe 绘制误差线 matplotlib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35562556/