标签:
import numpy as np import matplotlib.pyplot as plt # 号码热力图 pre = 49 a = np.random.randint(49, size=pre) + 1 # 模拟前期数据(这里不妨取49) import collections c = collections.Counter(a).most_common() # 统计次数 d = np.zeros(49) for i, x in c: d[i-1] = x image = d.reshape(7,7) # 构造成一个图像 plt.imshow(image, cmap=plt.cm.hot) # 画热力图 plt.colorbar() #plt.imshow(image, cmap=plt.cm.hot, interpolation="nearest") #plt.colorbar() # 为了方便,把号码也对应显示 xx, yy = np.meshgrid(np.arange(7), np.arange(7)) for i, (x, y) in enumerate(zip(xx.flatten(), yy.flatten())): c = str(i+1) plt.text(x, y, c, va=‘center‘, ha=‘center‘) plt.show()
标签:
原文地址:http://www.cnblogs.com/hhh5460/p/5400865.html