我正在尝试使用matplotlib.animation
函数制作一个动画。我有一个大的矩阵,我想在每个帧中使用plt.imshow()
在彩色贴图中显示这个矩阵的不同部分。然而,动画中只显示了一帧,我不知道为什么。我试图模仿An animated image using a list of images中的代码。我看过{a2}和{a3},但我在那里找不到解决办法
这是我的代码:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
def make_animation(pwv_matrix, length_side):
pwv_shape = pwv_matrix.shape
fig = plt.figure()
num_frames = min(pwv_shape[0], pwv_shape[1])-length_side
y_min = int(np.round(pwv_shape[0]/2) - np.round(length_side/2))
y_max = int(np.round(pwv_shape[0]/2) + np.round(length_side/2))
x_min = 0
x_max = length_side
ims = []
for i in range(0, num_frames):
pwv_frame = pwv_matrix[x_min:x_max, y_min:y_max]
im = plt.imshow(pwv_frame, animated=True, cmap = 'viridis')
ims.append([im])
x_min += 1
x_max += 1
ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,
repeat_delay=1000)
plt.show()
x = np.linspace(0, 1, 200)
y = np.linspace(0, 1, 200)
pwv_matrix, yv = np.meshgrid(x, y)
length_side = 20 #m
make_animation(pwv_matrix, length_side)
其中self.pwv_matrix
是从.dat文件获得的大型矩阵。有人看到问题了吗
非常感谢
尝试在show()函数之后添加一个非常小的延迟 matplotlib.pyplot.pause(间隔)[源] 功能或:
图像的实际绘制发生在您给它一些处理时间的情况下(以非常简单的方式解释)
如果它不起作用,您可以尝试其他一些方法,如果它不起作用,请告诉我
相关问题 更多 >
编程相关推荐