What I am trying to do is to plot the data from an orbital simulation using Matplotlib; an example of what I am trying to achieve is attached below.

I have the data of planets as well as the spacecraft in X,Y,Z, time coordinates(or if necessary I can rerun to get it in other coordinate systems) with respect to the Sun.
How can I make a GIF like this?
I tried just using pyplot of x,y, but instead of the moving GIF I only get a flat image.(As expected, because PyPlot can only make static graphs). Any help/pointers to where I can look is greatly appreciated.
One can use
matplotlib FuncAnimationfacility to create animations based on data in matplotlib. The idea is to view the animation as a collection of frames and define the graph/contents of each frame based on the frame number (assuming that the frames are placed in ascending order). More details on matplotlib animations can be found on this page on the official site: Matplotlib Animations. Rest of the answer provides some guidance specifically for the question.End Result
Here is a dummy animation that I created using matplotlib
FuncAnimation. It is based around the idea of the question (though with dummy data).Code
Here is the code to generate the above animation -
Explanation
The comments inside the code contain all the assistive information required while reading and working with the code. This section contains overall explanation.
fps,total_time,time_ratio.fig, ax = plt.subplots()) and then define theupdatefunction which takes frame number as input and creates the figure for that frame number.FuncAnimation. In the code we did this withFuncAnimation(fig, update, frames = range(total_frames), interval = interval*1000). We specify the frames to match the time we want and interval to match the FPS we want in the animation.plt.show(). To save, callanim.save()in which, specify the path to the output file along with the filename and the fps to match the FPS we want.