Mandelbrot set: Difference between revisions

Content added Content deleted
(Added Fōrmulæ)
(→‎{{header|Python}}: a little tidier for teaching purposes)
Line 6,388:
plt.imshow(exit_times.T,
cmap=plt.cm.prism,
extent=(X.min(), X.max(), Y.min(), Y.max()))</lang>
 
</lang>
Actually the same, but a little tidier for teaching purposes.
<lang python>import numpy as np
import matplotlib.pyplot as plt
 
dots = 100
iterations = 50
 
x = np.linspace(-2.0, 1.0, 3 * dots + 1)
y = np.linspace(-1.0, 1.0, 2 * dots + 1)
 
A, B = np.meshgrid(x, y)
 
C = A + B * 1j
Z = np.zeros_like(C)
 
escape_radius = 2.1 # must be greater than 2
escape_table = np.zeros(Z.shape)
 
not_escaped = abs(Z) < escape_radius
 
for i in range(iterations):
Z[not_escaped] = Z[not_escaped] ** 2 + C[not_escaped]
not_escaped = abs(Z) < escape_radius
escape_table[not_escaped] = i + 1
 
fig, ax = plt.subplots(dpi = 150)
ax.imshow(escape_table, cmap=plt.cm.twilight_shifted)
plt.show()</lang>
 
=={{header|R}}==