【问题标题】:Placing Multiple Histograms in Figure with PyLab使用 PyLab 在图中放置多个直方图
【发布时间】:2014-03-01 02:52:03
【问题描述】:

我有一个简短的函数如下:

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 次调用,并且理想情况下希望将它们全部保存为一个文档。

现在首先我如何将它们全部整理并从 drawChart 返回一个对象以实现这一点?

我见过有人用图here

【问题讨论】:

标签: python matplotlib


【解决方案1】:

所以你想要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()

给出一个类似

的数字

更多子图示例可以在matplotlib gallery 中找到,例如here.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    • 2014-09-29
    • 2014-09-10
    • 2016-08-13
    • 1970-01-01
    • 2011-08-23
    相关资源
    最近更新 更多