Mandelbrot set: Difference between revisions

→‎Mercator zooms of the Mandelbrot set using NumPy: Explanations have been added and the zoom depth has been doubled. In addition, the escape time is compressed as described by David Madore in order to improve the image quality.
(→‎Mercator zooms of the Mandelbrot set using NumPy: for avoiding cropping the mercator map and for nice looking pictures)
(→‎Mercator zooms of the Mandelbrot set using NumPy: Explanations have been added and the zoom depth has been doubled. In addition, the escape time is compressed as described by David Madore in order to improve the image quality.)
Line 7,151:
import matplotlib.pyplot as plt
 
d, h = 8060, 6040 # pixel density and image height
n, r = 50, 2.5 # number of iterations and escape radius (r > 2)
 
Line 7,157:
y = np.linspace(0, 2 / d * h, h, endpoint=False)
 
UX, VY = np.meshgrid(x, y)
WG = (UX - 1) + (VY - h / d) * 1j # rectangular grid around zero
 
C = (-0.4 + 0.6 * 1j) + 1.5 * WG
A, B = C.real, C.imag
 
Line 7,171:
T[M] = k + 1
 
fig, ax = plt.subplots(figsize=(43, 32))
ax.imshow(T, cmap=plt.cm.twilight_shifted, vmin=0, vmax=n)
plt.savefig("Mandelbrot_setMandelbrot_map.png", dpi=100)
 
D = 2 / d # distance between points in the grid
D = 2 / d
S = (150 * D) ** 2 # factorscaling depends on the size of the figure
 
fig, ax = plt.subplots(figsize=(86, 64))
ax.scatter(A, B, s=S, c=T, cmap=plt.cm.twilight_shifted, vmin=0, vmax=n)
plt.savefig("Mandelbrot_plot.png", dpi=100)</lang>
A small change in the code above allows Mercator zooms of the Mandelbrot set (seecf. [http://www.madore.org/~david/math/mandelbrot.html David Madore: ''Mandelbrot set images and videos'']). Escape time compression is used as described by David Madore.
<lang python>import numpy as np
import matplotlib.pyplot as plt
 
d, h = 250200, 5001000 # pixel density and zoom depth
n, r = 100200, 2.5 # number of iterations and escape radius (r > 2)
 
x = np.linspace(0, 2 * np.pi, d, endpoint=False)
y = np.linspace(0, 2 * np.pi / d * h, h, endpoint=False)
 
UX, VY = np.meshgrid(x, y)
WG = np.exp(UX * 1j - VY) # circular grid around zero
 
C = (-0.410314105 + 0.610216102 * 1j) + 1.5 * WG
A, B = C.real, C.imag
 
Line 7,205:
T[M] = k + 1
 
fig, ax = plt.subplots(figsize=(43, 815))
ax.imshow(T, cmap=plt.cm.twilight_shifted, vmin=0, vmax=n)
plt.savefig("Mercator_map.png", dpi=100)
 
D = 2 * np.pi / d * abs(WG) # distance between points in the grid
S = (150 * D) ** 2 # factorscaling depends on the size of the figure
 
t = T ** 0.5 # compression of the escape times with a concave function
fig, ax = plt.subplots(2, 2, figsize=(16, 16))
 
ax[0, 0].scatter(A[0:200], B[0:200], s=S[0:200], c=T[0:200], cmap=plt.cm.twilight_shifted, vmin=0, vmax=n)
fig, ax = plt.subplots(2, 2, figsize=(1615, 1615))
ax[0, 1].scatter(A[100:300], B[100:300], s=S[0:200], c=T[100:300], cmap=plt.cm.twilight_shifted, vmin=0, vmax=n)
ax[10, 0].scatter(A[2000:400150], B[2000:400150], s=S[0:200150], c=Tt[2000:400150], cmap=plt.cm.twilight_shifted, vmin=0, vmax=n)
ax[10, 1].scatter(A[30050:500200], B[30050:500200], s=S[0:200150], c=Tt[30050:500200], cmap=plt.cm.twilight_shifted, vmin=0, vmax=n)
ax[01, 0].scatter(A[0100:200250], B[0100:200250], s=S[0:200150], c=Tt[0100:200250], cmap=plt.cm.twilight_shifted, vmin=0, vmax=n)
plt.savefig("Mandelbrot_zoom.png", dpi=100)</lang>
ax[01, 1].scatter(A[100150:300], B[100150:300], s=S[0:200150], c=Tt[100150:300], cmap=plt.cm.twilight_shifted, vmin=0, vmax=n)
plt.savefig("Mandelbrot_zoomMercator_zoom.png", dpi=100)</lang>
 
=={{header|R}}==
305

edits