I'm interested in making an animated movie of a zoom in on a part of the Mandelbrot set. My code works well for a few zooms, but upon trying to zoom in quite far, I find that the fractal becomes "smoothed out". Am I missing something that prevents me from seeing the fractal structure at higher zoom levels? Am I hitting machine precision in the computations? Here's what I'm talking about:
Zoom level 3:
Zoom level 9:
Zoom level 20:
The first plot looks good, the second is okay, and the third is not fractal at all.
If there are any other deficiencies or improvements I'd be glad to hear about them as well.
Here's my code:
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from matplotlib import animation import time # some interesting places in the set # http://www.nahee.com/Derbyshire/manguide.html N = 500 nIts = 25 nZooms = 50 x0=0 y0=-1 movie = np.zeros([N,N,nZooms]) x = np.linspace(-2,1,N) y = np.linspace(-1,1,N) X,Y = np.meshgrid(x,y) c = X + 1j*Y z = 0*c for i in range(nIts): z = z**2 + c mask = np.abs(z) < 1 z[z>1]=0 z[np.isnan(z)]=0 movie[:,:,0] = mask # plotting stuff for j in range(1,nZooms): h=1./(2**j) print "Plot number ", j x = x0+h*np.linspace(-1,1,N) y = y0+h*np.linspace(-1,1,N) X,Y = np.meshgrid(x,y) c = X + 1j*Y z = 0*c for i in range(nIts): z = z**2 + c mask = np.abs(z) < 1 z[z>1]=0 z[np.isnan(z)]=0 movie[:,:,j] = mask fig = plt.figure() for j in range(nZooms): name = "image%d.png" % j plt.imshow(movie[:,:,j], cmap = 'RdBu') plt.gray() plt.axis('equal') plt.axis('off') # plt.show() fig.savefig(name) time.sleep(1)