误差条#

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
# matplotlib加入中文支持
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
x = np.arange(10)
y = np.random.randint(5, 20, 10)
x_error = np.random.rand(10)
y_error = np.random.rand(10) * 2

x: 横坐标

y: 纵坐标

xerr: 横坐标误差

yerr: 纵坐标误差

fmt: 线图的基本参数,如color、linstyle、linewidth、marker、markersize、label等

ecolor: 误差线颜色

elinewidth: 误差线宽度

plt.errorbar(x=x, y=y, xerr=x_error, color='red', marker='o', ecolor='blue', label='x-error sample')
plt.show()
../_images/6fd1888e544cbfdb6e89375981bc7dd1541714d8b3ea16cc6dfac7e0aa5282c5.png
plt.errorbar(x, y, yerr=y_error, linestyle='--', marker='s', linewidth=1, elinewidth=2)
plt.show()
../_images/d4d349060614edd2739ff26938cec5b03234fe89ba444dc1c36f0069588430cd.png