【发布时间】:2019-11-19 17:25:55
【问题描述】:
我正在尝试使用matplotlib.animation 制作动画,使用ArtistAnimation 函数。我有一个大矩阵,我想在每帧中使用plt.imshow() 在颜色图中显示该矩阵的不同部分。但是,动画中只显示了一帧,我不知道为什么。我试图模仿An animated image using a list of images 中的代码。我看过this question 和this question,但在那里找不到解决方案。
这是我的代码:
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 文件中获得的大矩阵。有没有人看到问题?
提前非常感谢!
【问题讨论】:
-
检查minimal reproducible example并在问题中提供一个。
-
我现在添加了所有内容以使代码能够运行
标签: python matplotlib animation