数字热力图
2016-04-17 13:29
225 查看
静态单图
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()
另一个动态的热力图
import numpy as np import matplotlib.pyplot as plt import collections '''动态号码热力图''' #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') # 根据前面历史数据,构造成一个图像 def build_image(a_list): c = collections.Counter(a_list).most_common() # 统计次数 d = np.zeros(49) for i, x in c: d[i-1] = x image = d.reshape(7,7) # 构造成一个图像 return image for i in range(100): if i == 0: # 号码热力图 pre = 49 a_list = np.random.randint(49, size=pre) + 1 # 模拟前期数据(这里不妨取49) image = build_image(a_list) im = plt.imshow(image, cmap=plt.cm.hot) # 画热力图 plt.colorbar() else: a_list = np.hstack((a_list[1:], np.random.randint(49)+1)) image = build_image(a_list) im.set_data(image) plt.pause(0.1)
相关文章推荐
- OpenGL透视投影
- STL中关于map和set的四个问题?
- 面向对象_2
- 面向对象
- NSUserDefault
- Android笔记之属性动画
- 20145208 《Java程序设计》第7周学习总结
- 机器人学 —— 飞行机器人(Introduction)
- HDU-1019
- 二维数组
- HDU-1021
- 调用系统图库获取图片
- Android Studio 编译失败 Could not read entry ':app:processDebugManifest' from cache taskArtifacts.bin
- 就业规划第四次作业
- 方法与数组
- 学习进度条
- hdu1074 Doing Homework(状压dp)
- HDU-1008
- iOS解决json串中的NSNull类型
- Http请求