Mandelbrot set: Difference between revisions
→Normalized Iteration Count, Distance Estimation and Mercator Maps: The first three examples merged into one program.
(→{{header|Python}}: Chapters merged and headline changed) |
(→Normalized Iteration Count, Distance Estimation and Mercator Maps: The first three examples merged into one program.) |
||
Line 7,206:
===Normalized Iteration Count, Distance Estimation and Mercator Maps===
Actually the same, but without optimizations and therefore better suited for teaching
The Mandelbrot set is also printed using a scatter plot.
<lang python>import numpy as np
import matplotlib.pyplot as plt
Line 7,219 ⟶ 7,221:
C = 2.0 * (A + B * 1j) - 0.5
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 ** 0.1, cmap=plt.cm.twilight_shifted)
plt.savefig("
▲Second, the normalized iteration counting algorithm using NumPy (see Wikipedia: [https://en.wikipedia.org/wiki/Plotting_algorithms_for_the_Mandelbrot_set#Continuous_(smooth)_coloring ''Plotting algorithms for the Mandelbrot set: Continuous (smooth) coloring'']).
N = abs(Z) > r
Line 7,253 ⟶ 7,236:
plt.imshow(T ** 0.1, cmap=plt.cm.twilight_shifted)
plt.savefig("
N = abs(Z) > 2
Line 7,278 ⟶ 7,242:
plt.imshow(D ** 0.1, cmap=plt.cm.twilight_shifted)
plt.savefig("
X, Y = C.real, C.imag
Line 7,285 ⟶ 7,249:
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("
A small change in the above code allows Mercator
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.
Note that Anders Sandberg uses a different scaling.
Line 7,314 ⟶ 7,278:
plt.imshow(D.T ** 0.1, cmap=plt.cm.nipy_spectral)
plt.savefig("
X, Y = C.real, C.imag
Line 7,324 ⟶ 7,288:
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("
=={{header|R}}==
|