静态单图
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
)
转载于:https://www.cnblogs.com/hhh5460/p/5400865.html