1

我只是想问一下如何最好地使用 matplotlib 创建频率像素图。通过这个术语,我的意思是:

http://img513.imageshack.us/img513/8677/g8df.png

其中正方形的颜色代表相应小时和间隔的频率。

我正在考虑绘制一系列 50 个色块并根据数据为它们着色并使用色标?还是有更好的方法来做到这一点?

谢谢

4

1 回答 1

1

听起来你基本上只是想要plt.hist2d.

import numpy as np
import matplotlib.pyplot as plt

data = np.array([[8,  15,  1, 65, 79],
                 [45, 22, 60, 43, 16],
                 [3,  75, 90, 11, 14],
                 [89, 32, 27, 59, 99],
                 [62,  5, 54, 92, 81]])
nrows, ncols = data.shape
# Generate 1-based row indicies, similar to your table
row = np.vstack(ncols * [np.arange(nrows) + 1]).T

x, y = row.flatten(), data.flatten()

xbins = np.arange(nrows+1) + 0.5
plt.hist2d(x, y, bins=(xbins, 10), cmap=plt.cm.Reds)
plt.show()

在此处输入图像描述

于 2013-10-25T13:33:51.213 回答