我有一个 JupyterLab 笔记本(v1.1.4),我试图在其中制作散点图的动画。我尝试使用 matplotlib 示例中的雨滴示例,它运行良好,但我无法让我的工作。
这是一个 MWE
%matplotlib widget
import random
import matplotlib.pyplot as plt
import matplotlib.animation as anim
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
p1, p2 = [], []
points = 10
for member in range(points):
p1.append(random.random())
p2.append(random.random())
scat = ax.scatter(p1,p2)
def animator(i):
for idx in range(points):
p1[idx] = random.random()
p2[idx] = random.random()
scat.set_offsets([p1, p2])
animation = anim.FuncAnimation(fig, animator, 50, interval=100)
它简要地显示了第一帧,但是一旦动画启动,我就会得到一个空白的图形。该小部件仍然存在,但其中没有任何内容,甚至没有轴框架。