In [104]:
def mandelbrot(zmin, zmax, hpx, niter, func=lambda z, c: z**2 + c):
vpx=round(hpx * abs((zmax-zmin).imag / (zmax-zmin).real))
z = zeros((vpx, hpx), dtype=complex128)
x = linspace(zmin.real, zmax.real, hpx)
y = linspace(zmin.imag, zmax.imag, vpx)
cRe, cIm = meshgrid(x, y)
c = cRe + cIm * 1j
M = zeros((vpx,hpx))
for _ in range(niter):
mask = find(abs(z)<2)
M.flat[mask] = M.flat[mask] + 1
z.flat[mask] = func(z.flat[mask], c.flat[mask])
#z.flat[mask] = z.flat[mask]**2 + c.flat[mask]
M.flat[mask] = 0
return M

In [105]:
Mc = mandelbrot(-2.1+1.05j,0.7-1.05j,640,64)

In [106]:
imshow(Mc)

Out[106]:
<matplotlib.image.AxesImage at 0xafa142cc>
In [107]:
Mn3 = mandelbrot(-1.2+1.6j,1.2-1.6j,240,64, func=lambda z, c: z**3 + c)

In [108]:
imshow(Mn3)

Out[108]:
<matplotlib.image.AxesImage at 0xafa3e20c>
In [109]:
Mn4 = mandelbrot(-1.2+1.6j, 1.2-1.6j, 320, 64, func=lambda z, c: z**4 + c)

In [110]:
imshow(Mn4)

Out[110]:
<matplotlib.image.AxesImage at 0xaf79014c>
In [112]:
Mn2_5 = mandelbrot(-1.6 + 1.2j, 1.6 - 1.2j, 320, 64, func=lambda z,c: z**2.5 + c)

In [113]:
imshow(Mn2_5)

Out[113]:
<matplotlib.image.AxesImage at 0xaf63044c>
In [118]:
Mn2_01i = mandelbrot(-2.2 + 1.2j, 1.0 - 1.2j, 320, 64, func=lambda z, c: z**(2 + 0.1j) + c)

In [119]:
imshow(Mn2_01i)

Out[119]:
<matplotlib.image.AxesImage at 0xaf5b11cc>
In [122]:
(3 + 2j)**(1 + 3j)

Out[122]:
(-0.16893784584344818-0.5942900283096888j)
In [123]:
Mp=mandelbrot(-2 + 1.05j, 0.8 - 1.05j, 320, 64, func=lambda z, c: z**2 + z + c)

In [124]:
imshow(Mp)

Out[124]:
<matplotlib.image.AxesImage at 0xaf5db22c>