Mandelbrot set: Difference between revisions

(→‎Normalized Iteration Count, Distance Estimation and Mercator Maps: The first three examples merged into one program.)
Line 7,230:
 
plt.imshow(T ** 0.1, cmap=plt.cm.twilight_shifted)
plt.savefig("Mandelbrot_escape_timeMandelbrot_set_1.png", dpi=250)
 
N = abs(Z) > r # normalized iteration count
T[N] = T[N] - np.log2(np.log(abs(Z[N])) / np.log(r))
 
plt.imshow(T ** 0.1, cmap=plt.cm.twilight_shifted)
plt.savefig("Mandelbrot_normalized_countMandelbrot_set_2.png", dpi=250)
 
N = abs(Z) > 2 # exterior distance estimation
D[N] = 0.5 * np.log(abs(Z[N])) * abs(Z[N]) / abs(dZ[N])
 
plt.imshow(D ** 0.1, cmap=plt.cm.twilight_shifted)
plt.savefig("Mandelbrot_distance_estimationMandelbrot_set_3.png", dpi=250)
 
X, Y = C.real, C.imag
S = 150 * 2 / d # scaling depends on the size of the figurefigsize
 
fig, ax = plt.subplots(figsize=(8, 6))
ax.scatter(X, Y, s=S**2, c=D**0.1, cmap=plt.cm.twilight_shifted)
plt.savefig("Mandelbrot_scatter_plotMandelbrot_plot.png", dpi=250)</lang>
A small change in the above code allows Mercator maps of the Mandelbrot set (see David Madore: [http://www.madore.org/~david/math/mandelbrot.html ''Mandelbrot set images and videos''] and Anders Sandberg: [https://www.flickr.com/photos/arenamontanus/sets/72157615740829949 ''Mercator Mandelbrot Maps'']).
The maximum magnification is exp(2*pi*h/d) = exp(2*pi*5.5) = 535.5^5.5 = 10^15, which is also the maximum for 64-bit arithmetic.
Line 7,268:
 
Z, dZ = np.zeros_like(C), np.zeros_like(C)
T, D = np.zeros(C.shape), np.zeros(C.shape)
 
for k in range(n):
M = abs(Z) < r
Z[M], dZ[M] = Z[M] ** 2 + C[M], 2 * Z[M] * dZ[M] + 1
T[M] = T[M] + 1
 
plt.imshow(T.T ** 0.1, cmap=plt.cm.nipy_spectral_r)
N = abs(Z) > 2
plt.savefig("Mercator_map_1.png", dpi=250)
 
N = abs(Z) > r # normalized iteration count
T[N] = T[N] - np.log2(np.log(abs(Z[N])) / np.log(r))
 
plt.imshow(T.T ** 0.1, cmap=plt.cm.nipy_spectral_r)
plt.savefig("Mercator_map_2.png", dpi=250)
 
N = abs(Z) > 2 # exterior distance estimation
D[N] = 0.5 * np.log(abs(Z[N])) * abs(Z[N]) / abs(dZ[N])
 
plt.imshow(D.T ** 0.1, cmap=plt.cm.nipy_spectral)
plt.savefig("Mandelbrot_Mercator_mapMercator_map_3.png", dpi=250)
 
X, Y = C.real, C.imag
S = 150 * 2 / d * np.pi * np.exp(-B) # scaling depends on the size of the figurefigsize
 
fig, ax = plt.subplots(2, 2, figsize=(16, 16))
Line 7,288 ⟶ 7,298:
ax[1, 0].scatter(X[200:500], Y[200:500], s=S[0:300]**2, c=D[200:500]**0.3, cmap=plt.cm.nipy_spectral)
ax[1, 1].scatter(X[300:600], Y[300:600], s=S[0:300]**2, c=D[300:600]**0.2, cmap=plt.cm.nipy_spectral)
plt.savefig("Mandelbrot_Mercator_zoomMandelbrot_zoom.png", dpi=250)</lang>
 
=={{header|R}}==
305

edits