zoukankan      html  css  js  c++  java
  • 画动态热图

    动态图可以更加清晰的反映某种特征的变化趋势,从而给人直观的感受,帮助人们理解抽象化的特征或者不易直接观察到的特征变化趋势。

    import numpy as np
    from matplotlib import pyplot as plt
    from matplotlib import animation
    
    imgData = np.random.random((4368,3,16,16))
    fig = plt.figure()
    data = np.random.random((16, 16))
    im = plt.imshow(data, cmap='hot') #注意这里一定要先对data的格式进行定义,cmp是热度参数,可以自行设置
    
    # animation function.  This is called sequentially
    def animate(frame):
        # data = np.random.random((16, 16))
        data = imgData[frame,1,:,:] #该frame是由下面的frames逐个传入的
        print (data)
        im.set_array(data)
        return [im]
    
    anim = animation.FuncAnimation(fig, animate, frames=np.arange(0,4368), interval=200, blit=True)
    #该函数中fig是画布,animate变换函数,frames序列化传入函数值,interval为图片变换的时间间隔 plt.show()

     这个也是画动态图的示例,对其中在被赋值变量后加逗点做个说明

    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.animation import FuncAnimation
    
    fig, ax = plt.subplots()
    xdata, ydata = [], []
    imgData = np.random.randint(0,10,(4368,3,16,16))
    
    ln,= ax.plot([], [], 'r-', animated=False)
    #这里在变量后加逗点,是使ln变为truple格式,后边可以调用set_data函数
    #如果不加逗点,ln就是list,不能调用set_data函数
    # ln, = ax.imshow([],[]) def init(): ax.set_xlim(0, 2*np.pi) ax.set_ylim(-1, 1) # ax.imshow(imgData[1,1,:,:]) return ln, def update(frame): xdata.append(frame) ydata.append(np.sin(frame)) ln.set_data(xdata, ydata) return ln, def getdata(): for i in range(4368): a=imgData[i,1,:,:] return a ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128), init_func=init, blit=True) plt.show() b=np.arange(0, 4368) print (b)
  • 相关阅读:
    【题解】LOJ #6488 数表【FWT】
    【题解】[Comet OJ Contest #11 F] arewell【子集卷积】
    【CF757F】 Team Rocket Rises Again 【支配树】
    支配树学习笔记
    JS模拟实现题目(new debounce throwee 等)
    React生命周期
    js转义符
    CSS3中的transform转换属性
    animation动画
    flex
  • 原文地址:https://www.cnblogs.com/zhibei/p/9600180.html
Copyright © 2011-2022 走看看