我已经想出了如何使用 matplotlib保存视频动画和缩放图片。我现在想合并这两件事并了解如何在动画中引入缩放:阅读一些文档,我注意到对于图片来说并不简单,我希望对于视频来说是相同或更糟。
在下面我写了一个简单的工作代码,你可以在第一个链接上找到
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation
from matplotlib import cm
#Define x,y vectors and meshgrid with function u on it
x = np.arange(0,10,.1)
y = np.arange(0,10,.1)
X,Y = np.meshgrid(x,y)
#Create a figure and an axis object for the surface
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
#Animation without axes and with colormap
def animate(n):
ax.cla()
u = np.sin(X+Y+(n/10))
plt.axis('off')
plt.grid('off')
ax.plot_surface(X,Y,u,cmap=cm.inferno)
return fig,
anim = animation.FuncAnimation(fig,animate,frames=63)
anim.save('A.mp4',fps=20)
这里的输出
如您所见,放大后还不错,但这还不够,我想要更多!
在我使用的实际代码中,视频动画非常非常小,我不知道为什么,因为它与此非常相似。我也希望这样我可以提高视频质量,那是很差的。谢谢你的帮助。