我使用FuncAnimationMatplotlib Animation 类创建了一个动画绘图,我想将其保存为 .gif 文件。当我运行脚本时,输出看起来正常,如下所示(动画工作正常):
但是,当我尝试使用 ImageMagick 或 PillowWriter 将动画图另存为 .gif 文件时,该图如下图所示:
线条明显粗了很多,总的来说,看起来很糟糕。该问题归因于点(紫色和红色圆圈)。因此,似乎情节是在每一帧上书写的(我认为是这样)。我可以通过将它们全部删除来避免这种情况。但我不想这样做,因为很难看清线条。
这是代码:
line, = ax.plot([], [], color = 'blue', lw=1)
line2, = ax.plot([], [], color = 'red', lw=1)
line3, = ax.plot([], [], color = 'purple', lw=1)
def animate(i):
line.set_data(x1[:i], y1[:i])
line2.set_data(x2[:i], y2[:i])
line3.set_data(x3[:i], y3[:i])
point1, = ax.plot(x1[i], y1[i], marker='.', color='blue')
point2, = ax.plot(x2[i], y2[i], marker='.', color='red')
point3, = ax.plot(x3[i], y3[i], marker='.', color='purple')
return line, line2, line3, point1, point2, point3,
ani = animation.FuncAnimation(fig, animate, interval=20, blit=True, repeat=False, …Run Code Online (Sandbox Code Playgroud)