Time saved with blit=True implies that the display a lot more rapidly.
We finish by having an optional save command, along with show command to exhibit the end result. This is what the script creates:
This framework for producing and saving animator is extremely effective and versatile: when we put some physics in to the animate function, the options are endless. Here are a few good examples of some physics animations that I have been experimenting with.
Among the good examples provided around the matplotlib example page is definitely an animation of the double pendulum. This situation works by precomputing the pendulum position over ten seconds, after which animating the outcomes. I saw this and wondered if python could be quick enough to compute the dynamics quickly. As it happens it’s:
Contaminants inside a Box
Another animator I produced may be the elastic collisions of several contaminants inside a box underneath the pressure of gravity. The collisions are elastic: they conserve energy and 2D momentum, and also the contaminants bounce realistically from the walls from the box and fall drunk of the constant gravitational pressure:
The mathematics ought to be familiar to anybody having a physics background, and it makes sense pretty enchanting. I coded this up throughout a flight, and wound up just sitting and watching it for around 10 mins.
Case the start: it may be a fascinating exercise to include additional factors, like computation from the temperature and pressure to show the perfect gas law, or real-time plotting from the velocity distribution to see it approach the expected Maxwellian distribution. It reveals many options for virtual physics demos…
The matplotlib animation module is a superb accessory for that which was already a great package. I believe I have just scratched the top of what is possible using these tools… what awesome animation ideas are you able to develop?
Edit: inside a followup publish, I show how these power tools may be used to generate an animation of the simple Quantum Mechanical system.