Reality Bending Lab › News › One Python code line for a Mandelbrot fractal
One Python code line for a Mandelbrot fractal
Mandelbrot Set
I wrote a small Python function to easily generate and plot a Mandelbrot set. This function is now available through the NeuroKit2 package, and can be used as follows:
import neurokit2 as nk
nk.fractal_mandelbrot(show=True)
The Mandelbrot set is defined in the between -2 and 2 on the x (real) and y (imaginary) axes. Following that, the image can be cropped accordingly by changing the coordinates. Moreover, the colors can be tweaked by changing the colormap (cmap).
m = nk.fractal_mandelbrot(real_range=(-2, 0.75), imaginary_range=(-1.25, 1.25))
plt.imshow(m.T, cmap="viridis")
plt.axis("off")
plt.show()
Buddhabrot Set
It is also possible to generate a Buddhabrot:
b = nk.fractal_mandelbrot(size=1500,
real_range=(-2, 0.75), imaginary_range=(-1.25, 1.25),
buddha=True, iterations=200)
plt.imshow(b.T, cmap="gray")
plt.axis("off")
plt.show()
Although the NeuroKit Python package is primarily devoted to physiological signal processing, it also includes tons of other useful features.
👉 Discover more about NeuroKit here 👈
Have fun!
Thanks for reading! 🐦 Don't forget to join me on X (@Dom_Makowski)