蓝色点表示实际值,红色线段表示上下偏离的误差(相同误差0.6)
import matplotlib.pyplot as plt
import numpy as np
x=np.linspace(1,10,20)
dy=0.6
y=np.sin(x)*3
plt.errorbar(x,y,yerr=dy,fmt='o',ecolor='r',color='b',elinewidth=2,capsize=4)
plt.show()
不同的误差
import matplotlib.pyplot as plt
import numpy as np
x=np.linspace(1,10,20)
dy=np.random.rand(20)
y=np.sin(x)*3
plt.errorbar(x,y,yerr=dy,fmt='o',ecolor='r',color='b',elinewidth=2,capsize=4)
#fmt : 'o' ',' '.' 'x' '+' 'v' '^' '<' '>' 's' 'd' 'p'
plt.show()