【发布时间】:2020-04-23 05:34:07
【问题描述】:
我试图在一维上绘制波函数,但它有实部和虚部,所以我做了一个 3D 绘图动画。这是截图:
我想做的主要事情是将它沿着 x 轴(现在是垂直的)展开,这样它看起来就不会被挤压。此外,最好将其设置在一组 3 个 RGB 轴中,这些轴在点 (0,0,0) 处相交。在文档中,我找不到任何直接的方法来做到这一点。我附上了我用来制作动画的代码部分:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import mpl_toolkits.mplot3d.axes3d as p3
fig = plt.figure()
ax = fig.gca(projection='3d')
line, = ax.plot(REAL[0,:],IMAG[0,:],x,"r",linewidth=0.5)
def animacio(i):
ax.collections.clear()
line.set_data(REAL[i,:],IMAG[i,:])
line.set_3d_properties(x, 'z')
return line,
ani = animation.FuncAnimation(fig,animacio,interval=50, frames=Nt,repeat=True)
nom = 'Evolució_'
ani.save(str(nom)+'['+str(V0)+','+str(L)+','+str(l)+','+str(xi)+','+str(sigmax)+','+str(T)+']'+'.mp4', writer="ffmpeg", dpi=300)
plt.show()
print('Animation saved as: '+str(nom)+'['+str(V0)+','+str(L)+','+str(l)+','+str(xi)+','+str(sigmax)+','+str(T)+']'+'.mp4')
【问题讨论】:
-
PS:使用 f-strings (python 3.6),你可以写
nom_complet = f'{nom}[{V0},{L},{l},{xi},{sigmax},{T}].mp4' -
能否分享生成类似曲线的代码?它有助于提供真正适合您的案例的答案。
-
感谢您提供有关名称的提示!当然可以分享!但是代码有点长,要不要编辑问题添加一下?
-
也许this post 也有帮助? This article 提供了一些关于 3D 动画的想法。
-
This post 处理多色
标签: python matplotlib animation data-visualization complex-numbers