【问题标题】:saving a animated plot from vscode to my computer将动画情节从 vscode 保存到我的电脑
【发布时间】:2020-09-29 08:23:19
【问题描述】:

我在 vscode 上创建了一个动画情节,我想将它保存到我的桌面。 目前我有:

animation = FuncAnimation(fig, func=animation_frame, interval=10)
plt.show()
writer = animation.FFMpegWriter(fps=15, metadata=dict(artist='Me'), bitrate=1800)
animation.save("movie.mp4", writer=writer)

但它返回错误:

AttributeError: 'FuncAnimation' object has no attribute 'FFmpegWriter'

我确实 pip install FFmpeg 成功。

我也试过这个:

animation.save("movie.mp4")

但它也返回错误:

ValueError: unknown file extension: .mp4

知道如何解决这两种情况吗?或者如何从vscode下载动画情节?提前谢谢你。

【问题讨论】:

  • animation.save("movie.mp4",writer='ffmpeg')如果是,我不能保存吗?

标签: python matplotlib visual-studio-code data-visualization


【解决方案1】:

为了保存绘制的动画,我使用以下代码自动将绘图保存为gif:

 ani = animation.ArtistAnimation(fig, ims, interval=200, repeat_delay=1000)
 plt.show()
 ani.save("test1.gif", writer='pillow') #The default is in the project, you can also specify the path. 

完整代码:

import matplotlib.animation as animation
import matplotlib.pyplot as plt
ims = []
fig = plt.figure()
for i in range(1,10):
    im = plt.scatter(1,1).findobj()
    ims.append(im)
ani = animation.ArtistAnimation(fig, ims, interval=200, repeat_delay=1000)
plt.show()
ani.save("test1.gif", writer='pillow')

结果:

【讨论】:

  • 嗯,由于某种原因,没有生成 gif。 :(
  • @조혜연 能否提供详细的描述,以便我们更好地帮助您。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
  • 1970-01-01
  • 2012-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多