adapted from code at Double pendulum formula translated from the C code at author: Jake Vanderplas email: website: license: BSD Please feel free to use and modify this, but keep the above information. """ General Numerical Solver for the 1D Time-Dependent Schrodinger's equation.
It turns out it is: Double Pendulum double_pendulum.py download Saw this and wondered if python would be fast enough to compute the dynamics The pendulum position over 10 seconds, and then animating the results. One of the examples provided on the matplotlib Below are a couple examples of some physics animations that This framework for generating and saving animations is very powerful andįlexible: if we put some physics into the animate function, the possibilitiesĪre endless. We end with an optional save command, and then a show command to show the Means that the animations display much more quickly. The pieces of the plot which have changed. Theīlit keyword is an important one: this tells the animation to only re-draw We'veĬhosen a 100 frame animation with a 20ms delay between frames. This object needs to persist, so it must be assigned to a variable. FuncAnimation ( fig, animate, init_func = init, frames = 100, interval = 20, blit = True )
Pieces of numpy and matplotlib, The script sets up the plot:Īnim = animation. Let's step through this and see what's going on. save ( 'basic_animation.mp4', fps = 30, extra_args = ) plt. You may need to adjust this for # your system: for more information, see # anim. The extra_args ensure that the x264 codec is used, so that # the video can be embedded in html5. This requires ffmpeg or mencoder to be # installed. FuncAnimation ( fig, animate, init_func = init, frames = 200, interval = 20, blit = True ) # save the animation as an mp4. blit=True means only re-draw the parts that have changed. set_data ( x, y ) return line, # call the animator. This is called sequentially def animate ( i ): x = np. set_data (, ) return line, # animation function. plot (,, lw = 2 ) # initialization function: plot the background of each frame def init (): line. Thanks! """ import numpy as np from matplotlib import pyplot as plt from matplotlib import animation # First set up the figure, the axis, and the plot element we want to animate fig = plt. """ Matplotlib Animation Example author: Jake Vanderplas email: website: license: BSD Please feel free to use and modify this, but keep the above information.