首页 > 解决方案 > 如何在 Python 中制作动画?

问题描述

我正在尝试使用称为 X 门的量子计算创建有关一个量子位的 x、y、z 坐标变化的动画。这是我写的代码。

#length means number of phase here
length = 10
# theta, pi are variable we need to calculate x,y,z in each phase
# and I get these values from users.
xgate_theta = np.linspace(theta,theta+np.pi,length)
xgate_phi = np.linspace(phi,phi,length)

# this array contains all the coordinates in each phase
xgate= []
# these array contains only one kind of coordinates
xgate_x = []
xgate_y = []
xgate_z = []

for i in range(length):
    # X means x coordinate in the initial phase
    xgate_x.append(X)
    xgate_z.append(np.cos(xgate_theta[i]))
    xgate_y.append(np.sqrt(1-np.sqrt(xgate_x[i]**2+xgate_z[i]**2))*(-1))
for j in range(length):             xgate.append(put.quiver(0,0,0,xgate_x[j],xgate_y[j],xgate_z[j],color="red")

# I don't show you the codes for fig, but it doesn't have any problems
ani = animation.ArtistAnimation(fig,xgate,interval=1000)
plt.show()

每次看到结果,我只得到下图。 我想让它成为动画的图像

如果有人告诉我如何将其更改为动画,我将不胜感激。

标签: pythonanimation

解决方案


推荐阅读