matplotlib中使用errorbar()绘制误差棒图来表示被测量的误差范围。
各示例代码如下(除第2例子外,其它例子来自于matplotlib官方文档):
import numpy as npimport matplotlib.pyplot as plt# example datax = np.arange(0.1, 4, 0.5)y = np.exp(-x)fig, ax = plt.subplots()ax.errorbar(x, y, xerr=0.2, yerr=0.4)plt.show()
import matplotlibfrom matplotlib import tickerimport matplotlib.pyplot as pltimport numpy as npmatplotlib.rcParams["font.sans-serif"] = ["SimHei"]matplotlib.rcParams["axes.unicode_minus"] = FalseX = np.linspace(2,80,8)Y= 100*np.sin(X)xerror = 1* np.random.randn(X.shape[0])+3yerror = 2*xerrorplt.errorbar(X, Y, fmt= "bo: