首页 > 解决方案 > 如何保存 Matplotlib 3D 动画,包括动画期间视角的变化

问题描述

我是一名新的 Python 程序员,具有正确运行的 3D 散点图模拟。在模拟过程中更改视角很重要,并且保存这些更改。我能够保存模拟(下面的相关代码),但我不能同时保存和观看 - 只是“先保存,然后观看”。
我的问题:如何观看模拟、更改视角并保存我观看的内容,包括这些更改?我尝试过的:没有运气在网上找到类似的问题。学习有关 FuncAnimation、animation.save、plt.plot() 或任何其他可能相关主题的 Python 帮助没有任何帮助。

    """
    import numpy as np
    import matplotlib
    import matplotlib.pyplot as plt
    from matplotlib.animation import FuncAnimation
    from matplotlib import animation as animation
    import math as math
    from mpl_toolkits.mplot3d import Axes3D

    matplotlib.rcParams['animation.ffmpeg_path'] = r'C:\Users\harry\.ipython\ffmpeg-2021-07-25-git-a2a7547b2f-essentials_build\ffmpeg-2021-07-25-git-a2a7547b2f-essentials_build\bin\ffmpeg.exe'

    # Setup, calculate, define the plot. At the very end:

    save = False
    anim = FuncAnimation(fig, update, frames=nt, repeat=False, interval=1 )

    if save:
        f = r"D:\harry\Documents\Python_Scripts\3D\videos\scatter-TEST.mov"     
        writervideo = animation.FFMpegWriter(fps=30)
        anim.save(f, writer=writervideo)

    plt.show()
    """  

标签: matplotlibanimation3dsave

解决方案


推荐阅读