我想你有像这个数据框这样的数据存储:
N = 20
df = pd.DataFrame({'x': np.linspace(0, 150000, N),
'y': np.random.random(N)})
df['y_max'] = df['y'] + np.random.random(N)
df['y_min'] = df['y'] - np.random.random(N)
x y y_max y_min
0 0.000000 0.856374 1.685085 0.181898
1 7894.736842 0.471733 0.713564 0.128606
2 15789.473684 0.817586 1.453245 0.520492
3 23684.210526 0.352486 0.464310 0.093795
4 31578.947368 0.188503 0.427685 -0.203351
5 39473.684211 0.192593 1.018089 -0.586906
6 47368.421053 0.143718 0.375640 -0.833777
7 55263.157895 0.288232 0.764800 0.035718
8 63157.894737 0.047860 0.802160 -0.776364
9 71052.631579 0.647542 1.389724 0.290451
...
其中'y' 是实际值,'y_min' 和'y_max' 是从您拥有的其他数据集中获得的最小值和最大值。
然后你可以用matplotlib.axes.Axes.plot绘制'y',用matplotlib.axes.Axes.fill_between绘制阴影区域:
fig, ax = plt.subplots()
ax.plot(df['x'], df['y'], color = 'blue')
ax.fill_between(df['x'], df['y_max'], df['y_min'], color = 'blue', alpha = 0.5)
plt.show()
完整代码
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
N = 20
df = pd.DataFrame({'x': np.linspace(0, 150000, N),
'y': np.random.random(N)})
df['y_max'] = df['y'] + np.random.random(N)
df['y_min'] = df['y'] - np.random.random(N)
fig, ax = plt.subplots()
ax.plot(df['x'], df['y'], color = 'blue')
ax.fill_between(df['x'], df['y_max'], df['y_min'], color = 'blue', alpha = 0.5)
plt.show()