2016-11-23 6 views
0

次のコードは、numpyのndarrayから各行を読み取るグリッド内の複数のヒストグラムを配置し、同図の上に複数のヒストグラムを作成する方法:内のすべてのヒストグラムを含むのパイソン -

fig, ax = plt.subplots(figsize=(10, 8)) 
fontP = FontProperties() 
fontP.set_size('small') 
for f in eval_list: 
    local_id = getIndexByIdentifier(f) 
    temp_sim = total_sim[local_id,:] 
    c=np.random.rand(3,1) 
    ax.hist(temp_sim, 10, ec=c, fc='none', lw=1.5, histtype='step', label=f) 
    ax.legend(loc="upper left", bbox_to_anchor=(1.1,1.1),prop = fontP) 

enter image description here

代わり1つのプロット、どのようにグリッド5×5にそれらを配置できますか?ここで

が更新されたコードです:

#Plot indvidual Histograms 
SIZE = 10 
all_data=[] 
for f in eval_list: 
    local_id = getIndexByIdentifier(f) 
    temp_sim = total_sim[local_id,:] 
    all_data.append(temp_sim) 

# create grid 10x10  
fi, axi = plt.subplots(SIZE, SIZE,figsize=(50,50)) 
for idx, data in enumerate(all_data): 
    x = idx % SIZE 
    y = idx // SIZE 
    axi[y, x].hist(data) 

答えて

2

あなたが "グリッド" に異なる "セル" のプロットを置くために異なるaxを使用する必要が

import matplotlib.pyplot as plt 
import random 

SIZE = 5 

# random data 
all_data = [] 
for x in range(SIZE*SIZE): 
    all_data.append([ random.randint(0,10) for _ in range(10) ]) 

# create grid 5x5  
f, ax = plt.subplots(SIZE, SIZE) 

# put data in different cell 
for idx, data in enumerate(all_data): 
    x = idx % SIZE 
    y = idx // SIZE 
    ax[y, x].hist(data) 

plt.show() 

enter image description here