Chaotic Beauty: Bifurcation Diagram Animation with Matplotlib

1 minute read

Not everything that seems simple turns out to be so simple, sounds familiar right? Let's take the Logistic Map, which is a simple chaotic dynamical system. It is defined with the following recursive relation:

\[ x^{(r)}_{n + 1} = rx^{(r)}_{n}(1 - x^{(r)}_{n}) \]

where \( x_{n} \) is a number between 0 and 1, while \( r \) is a free parameter that controls the behaviour of the system.

Going from Equilibrium to Chaos

To see how the free parameter \( r \) affects the convergence of the sequence, we can animate its evolution for a few consecutive steps regardless of the initial value \( x_{0} \).

For this reason, we can use the Matplotlib Animation API. First, we randomly generate 1 million random values between 0 and 1 and use them as initial values. Then, we crank the Logistic Map relation for 50 iterations by varying the free parameter \( r \) from 0 to 4.

We can see that for \( r \) between 0 and 3, the system is pretty stable and predictable, it almost always converges to a single point. But then, something strange happens, it goes out of equilibrium and becomes chaotic, unpredictable. Pretty amazing, huh!

Animated Visualization of bifurcation diagram for the logistic map
Animation: Convergence to Bifurcation Diagram regardless of the initial value

The source code for these animations can be found in this Jupyter Notebook. For more information, please follow me on Twitter or LinkedIn.

If this demonstration of the Bifurcation Diagram for the Logistic Map is interesting to you, feel free to share it on the social media. Also, it would help if you subscribe to the mailing list below. You will get cool animations like this one from time to time. Thanks for reading this article!

References

[1] Cyrille Rossant, "IPython Interactive Computing and Visualization Cookbook, Second Edition" (2018), Packt Publishing

Leave a comment