2015-04-08 175 views

回答

0

複製您的示例很容易,因爲可以計算每個x處的最小值和最大值並填充它們。例如。

import matplotlib.pyplot as plt 
import numpy as np 

#dummy data 
y = [range(20) + 3 * i for i in np.random.randn(3, 20)] 
x = list(range(20)) 

#calculate the min and max series for each x 
min_ser = [min(i) for i in np.transpose(y)] 
max_ser = [max(i) for i in np.transpose(y)] 

#initial plot 
fig, axs = plt.subplots() 
axs.plot(x, x) 
for s in y: 
    axs.scatter(x, s) 

#plot the min and max series over the top 
axs.fill_between(x, min_ser, max_ser, alpha=0.2) 

enter image description here

爲您顯示的數據,因爲該系列不會在所有情況下共享x值可能證明是有問題。如果是這種情況,那麼你需要一些統計技術來以某種方式平滑該系列。一種選擇是使用像seaborn這樣的包,其中provides functions爲您處理所有細節。