zoukankan      html  css  js  c++  java
  • 数字热力图

    静态单图

    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)
        
  • 相关阅读:
    PCA本质和SVD
    特征工程(转载)
    python入门基础代码
    长尾理论
    金融行业数据分析
    [rancher-net]
    rancher中使用ingress-lbs做负载均衡
    python 高级语言特性
    docker从初识到深入
    关于容器技术的发展以及虚拟化技术的总结
  • 原文地址:https://www.cnblogs.com/hhh5460/p/5400865.html
Copyright © 2011-2022 走看看