# Chaotic Beauty: Bifurcation Diagram Animation with Matplotlib

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!

Animation: Convergence to Bifurcation Diagram regardless of the initial value