将yerr/xerr绘制为阴影区域而不是误差线 [英] Plot yerr/xerr as shaded region rather than error bars
本文介绍了将yerr/xerr绘制为阴影区域而不是误差线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在matplotlib中,如何将错误绘制为阴影区域而不是错误条?
In matplotlib, how do I plot error as a shaded region rather than error bars?
例如:
而不是
推荐答案
忽略示例图中各点之间的平滑插值(这需要进行一些手动插值,或者只是具有更高的数据分辨率),您可以使用 pyplot.fill_between()
:
Ignoring the smooth interpolation between points in your example graph (that would require doing some manual interpolation, or just have a higher resolution of your data), you can use pyplot.fill_between()
:
from matplotlib import pyplot as plt
import numpy as np
x = np.linspace(0, 30, 30)
y = np.sin(x/6*np.pi)
error = np.random.normal(0.1, 0.02, size=y.shape)
y += np.random.normal(0, 0.1, size=y.shape)
plt.plot(x, y, 'k-')
plt.fill_between(x, y-error, y+error)
plt.show()
另请参见 matplotlib示例.
这篇关于将yerr/xerr绘制为阴影区域而不是误差线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文