python不同分类的直方图_Python-如何在网格中排列多个直方图

The following code read each row from a numpy ndarray and create multiple histograms on the same figure:

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)

Instead of including all histograms in one plot, how can I arrange them in a grid 5 x 5?

Here is an updated code:

#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)

解决方案

You have to use different ax to put plot in different "cell" in "grid"

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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值