2015-04-08 174 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为您处理所有细节。