If you, like me, think that fractals are beautiful, and have some knowledge of Python, you will enjoy this article. We will follow very easy steps to visualize the Mandelbrot Set using the library matplotlib.

The Mandelbrot Set is formally defined as the set of complex numbers for which the function:

**Fc(Z) = Z^2 + c**

remains bounded to an absolute value. In fact, the entire set is contained in a distance of radius 2 around the origin.

Now let’s see what this means.

If we take our **complex number called c **and write it in a polar form we have:

Where **a is the real **part and **b is the imaginary** part.

Well, now what we need to keep in mind is in our graph, a point (x,y) will belong to the Mandelbrot Set if and only if the modulus or absolute value of our complex number c, is never larger than 2 no matter how many iterations we do.

In case you want to check, pick a point, and do a small number of iterations. You will see that the moment the value of Z is bigger than 2 it quickly escapes to infinite.

So now that we understood the maths, let’s see how to code this in Python using the library Matplotlib which makes it quite straightforward.

First of all, we import NumPy (used to create arrays) and Matplotlib for our plots and create an array of 1000 items for the values of coordinates on each axis (from -2 to 2 in the x-axis and from -1 to 1 in the y-axis), we will also create 2 empty lists where we will append the values of the points contained in our set:

```
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-2,2,1000)
y = np.linspace(-1,1,1000)
x_axis = []
y_axis = []
```

#matplotlib #machine-learning #data-science

8.00 GEEK