Python-如何在网格中排列多个直方图

Python-如何在网格中排列多个直方图,python,matplotlib,histogram,Python,Matplotlib,Histogram,以下代码从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)

以下代码从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)

我如何在网格5 x 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)

您必须使用不同的
ax
将绘图放在“网格”中的不同“单元格”中


您必须使用不同的
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()