2D Animated Orbits
Learn how to plot 2D animated orbits.
Now, let’s animate the orbit. Note that you have reset the argument of perigee to be 0 degrees.
Matplotlib
’s FuncAnimation()
takes a function and computes the next value given a range, plots the new value, waits a specified period of time, and then plots the next value. In your case, your animation is really just displaying the pre-computed X and Y coordinates of the orbit. You need to do some prep work to plot the orbit, plot the starting point of a red dot that will go around the orbit, and internally define an animate()
function that accepts the incremental value i
and returns (pos[i][1], pos[i][0])
, so that the FuncAnimation()
function can plot the new coordinates. Since pos[i]
will give you the entire list
of X or Y coordinates, you use the second [1]
to get the X coordinates or [0]
to get the Y coordinates of the nested list
.
Get hands-on with 1400+ tech skills courses.