Python 我希望3D动画点的颜色随时间变化

Python 我希望3D动画点的颜色随时间变化,python,animation,colors,data-visualization,4d,Python,Animation,Colors,Data Visualization,4d,因此,在我的最后一个项目中,我正在为3颗质量相等的恒星的轨道制作动画,这在某种程度上需要是4D的,我想让动画中这些点的颜色随着时间的推移而改变,就像一张彩色地图或其他东西。我该怎么做 这是我的密码: t = trajectory[0]/day #pull out time array in days positions = trajectory[1]/au #pull out positions array in AU x = positions[:,:,0] #pull out x posi

因此,在我的最后一个项目中,我正在为3颗质量相等的恒星的轨道制作动画,这在某种程度上需要是4D的,我想让动画中这些点的颜色随着时间的推移而改变,就像一张彩色地图或其他东西。我该怎么做

这是我的密码:

t = trajectory[0]/day #pull out time array in days
positions = trajectory[1]/au #pull out positions array in AU 
x = positions[:,:,0] #pull out x positions in AU
y = positions[:,:,1] #pull out y positions in AU
z = positions[:,:,2] #pull out z positions in AU

FFMpegWriter = ani.writers['ffmpeg']
fig = plt.figure(figsize=(5,5)) #set figure size
ax = fig.gca(projection='3d') #set projection to 3D
writer = ani.FFMpegWriter(fps=30) #set fps to 30
with writer.saving(fig, 'Figure8.mp4', 200):
for i in range(len(t)): #for loop length of time array
plt.cla() #clear plot
colors = ["yellow","red","blue"] #set particle color list
ax.scatter(x[i,:], y[i,:], z[i,:],s=masses[:]/np.max(masses)*100, label = [f'Yellow ={masses[0]}, red ={masses[1]}, blue ={masses[2]}']) #scatter plot of x,y,z positons 
ax.set_xlim(-1,1); ax.set_ylim(-1,1); ax.set_zlim(-1,1) #set x,y,z limit
ax.set_xlabel('x (AU)'); ax.set_ylabel('y (AU)'); ax.set_zlabel('z (AU)') #set x,y,z label
ax.set_title(f'Figure 8 System: day {t[i]}') #set title
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05)) #plot legend

if i % 200 == 0: #every 200 frames print we are saving frame
print(f"saving movie frame {i}") 
writer.grab_frame() #grab frame