import numpy as np
import matplotlib.pyplot as plt

# a 2D array of complex numbers, one per pixel
x, y = np.meshgrid(np.linspace(-0.748, -0.742, 1000), np.linspace(0.097, 0.1006, 600))
c = x + 1j * y
z = np.zeros_like(c)
age = np.zeros(c.shape)

for step in range(400):
    inside = np.abs(z) < 2              # boolean array
    z[inside] = z[inside]**2 + c[inside]
    age[inside] += 1

plt.figure(figsize=(10, 6))
plt.imshow(np.log(age), cmap='inferno', origin='lower')
plt.axis('off')
plt.savefig('mandelbrot.png', bbox_inches='tight', pad_inches=0)
