Example Image:
import numpy as np
import matplotlib.pyplot as plt
Mandelbrot Equation:
#Calculate the finite set of numbers
def mandelbrot(Re, Im, maxIter):
c = complex(Re, Im)
z = 0.0j
for i in range(maxIter):
z = z*z + c
if(z.real*z.real + z.imag*z.imag) >= 4:
return i
return maxIter
Convert to image
#Using matplotlb to plot the number set
columns = 700
rows = 700
result = np.zeros([rows, columns])
for row_index, Re in enumerate(np.linspace(-2, 1, num=rows)):
for column_index, Im in enumerate(np.linspace(-1, 1, num=columns)):
result[row_index, column_index] = mandelbrot(Re, Im, 100)
plt.figure(dpi=100)
plt.imshow(result.T, cmap='twilight_shifted', interpolation='bilinear', extent=[-2, 1, -1, 1])
plt.xlabel("Re")
plt.ylabel("Im")
plt.show()