用PyLab在图中放置多个直方图

2024-03-29 13:10:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个简短的功能如下:

def drawChart(data,title):
    P.title(title)
    P.hist(data, bins=20, histtype='stepfilled')
    P.xlabel("Relevance")
    P.ylabel("Frequency")
    P.savefig(title + '.pdf')

这将创建我的直方图的pdf。不过,我打了大约6个电话到这个,并希望能保存它们作为一个理想的文件。你知道吗

首先,我该如何整理它们,并从绘图图中返回一个对象来实现这一点?你知道吗

我见过有人用图here


Tags: 功能datapdftitledefhistrelevancefrequency
1条回答
网友
1楼 · 发布于 2024-03-29 13:10:29

所以你想要subplots。一个可能的例子如下:

import numpy as np
import matplotlib.pyplot as plt
# create some data
data = np.random.rand(6,10)
fig, ax = plt.subplots(3,2)
ax = ax.reshape(6)
for ind, d in enumerate(data):
  ax[ind].hist(d)
fig.tight_layout()
plt.show()

它给出了一个像
enter image description here

子图的更多示例可以在matplotlib gallery中找到,例如here。你知道吗

相关问题 更多 >