代码源于:Python数据分析与挖掘实战
绘制误差棒图:
#-*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
error = np.random.randn(10) #定义误差列
print(error)
y = pd.Series(np.sin(np.arange(10))) #取序列值,用于绘制正弦曲线
print(y)
y.plot(yerr=error) #y轴方向绘制误差棒图
plt.show()
输出:
error:
[-0.90993526 0.43104993 0.77853013 -0.59633535 0.78404268 -0.21942184 1.42360538 -1.01250047 -1.15035766 1.34098822]
y:
0 0.000000
1 0.841471
2 0.909297
3 0.141120
4 -0.756802
5 -0.958924
6 -0.279415
7 0.656987
8 0.989358
9 0.412118
dtype: float64