Вам нужно будет создать два изображения, одно из которых остается сверху, а другое - с изменением animate()
:
# create dummy data
data = np.random.random(size=(240,512,512))
# load an image in first frame of data
temp = plt.imread('./stinkbug.png')
data[0,:,:] = 0.5
data[0,:375,:500] = temp[::-1,::-1,0]
fig,ax=plt.subplots()
ax.set_xlim((0,512))
ax.set_ylim((0,512))
top_img = ax.imshow(data[0,:,:], zorder=10, alpha=0.5, cmap='gray')
bottom_img = ax.imshow(data[1,:,:], zorder=1, cmap='viridis')
def init():
top_img.set_data(data[0,:,:])
bottom_img.set_data(data[1,:,:])
return (top_img, bottom_img)
def animate(i):
data_slice=data[i,:,:]
bottom_img.set_data(data_slice)
return (bottom_img,)
ani = animation.FuncAnimation(fig,animate,init_func=init,frames=range(1,240),interval=100)
plt.show()
![enter image description here](https://i.stack.imgur.com/MxoMe.gif)