小编Vah*_*idG的帖子

在 matplotlib 中使用动画的颜色图问题

我用来matplotlib.animation在一个名为arr. 我使用h5py库从 h5 文件中读取数据,一切正常。但是在使用动画时,颜色图卡在数据范围的第一帧中,经过一些步骤后,它在绘图时显示了非标准化的颜色。

这是我的代码:

import numpy as np
import h5py
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib.cm as cm

f = h5py.File('ez.h5','r')
arr = f["ez"][:,:,:]
f.close()

fig = plt.figure()

i = 0
p = plt.imshow(arr[:,:,0], interpolation='bilinear', cmap=cm.RdYlGn)

def updatefig(*args):
    global i
    i += 1
    if (i==333):
        i = 0
    p.set_array(arr[:,:,i])
    plt.clim()
    return p,

ani = animation.FuncAnimation(fig, updatefig, interval=50, blit=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)

python animation matplotlib color-mapping h5py

2
推荐指数
1
解决办法
2012
查看次数

标签 统计

animation ×1

color-mapping ×1

h5py ×1

matplotlib ×1

python ×1