Python matplotlib FuncAnimation在第一个传递的图像为全零时生成黑屏

Python matplotlib FuncAnimation在第一个传递的图像为全零时生成黑屏,python,matplotlib,Python,Matplotlib,我有一段代码,它绘制了一系列图像。它很好用 mask=np.array(np.random.randn(250,512,512)) fig = plt.figure() # make figure im = plt.imshow(mask[0], cmap=pylab.cm.bone) # function to update figure def updatefig(j): # set the data in the axesimage object im.set_array

我有一段代码,它绘制了一系列图像。它很好用

mask=np.array(np.random.randn(250,512,512))
fig = plt.figure() # make figure
im = plt.imshow(mask[0], cmap=pylab.cm.bone)

# function to update figure
def updatefig(j):
    # set the data in the axesimage object
    im.set_array(mask[j])
    # return the artists set
    return im,
# kick off the animation
ani = animation.FuncAnimation(fig, updatefig, frames=range(len(mask)), 
                              interval=10, blit=True)
plt.show()
但是,如果我经过的初始帧都是零,那么我只会得到一个黑色图像

z=np.zeros((1,512,512))
X=np.concatenate((z,mask))

fig = plt.figure() # make figure
im = plt.imshow(X[0], cmap=pylab.cm.bone)

# function to update figure
def updatefig(j):
    # set the data in the axesimage object
    im.set_array(X[j])
    # return the artists set
    return im,
# kick off the animation
ani = animation.FuncAnimation(fig, updatefig, frames=range(len(X)), 
                              interval=10, blit=True)
plt.show()

有没有办法解决这个问题

快速想法:尝试在
plt.imshow()中设置
vmin
vmax
。我认为问题在于它试图从第一幅图像猜出值的范围,如果图像都是零,那么值的范围就是零。谢谢。这就解决了问题。Quick idea可能重复:尝试在
plt.imshow()中设置
vmin
vmax
。我认为问题在于它试图从第一幅图像猜出值的范围,如果图像都是零,那么值的范围就是零。谢谢。这就解决了问题。可能是