Skip to content

Commit 1e0abe9

Browse files
committed
add python tutor
1 parent ad4ab25 commit 1e0abe9

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
-- python tutor: http://www.pythontutor.com/
2+
13
-- merge in the REU python stuff
24

35
-- matplotlib example: mandelbrot

examples/matplotlib/fractal/mandelbrot.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,22 @@
2323
ymin = -0.75
2424
ymax = -0.25
2525

26+
# nice spot
2627
xc = -0.7435669
2728
yc = 0.1314023
2829
dx = 0.0022878
2930

30-
xmin = xc-dx
31-
xmax = xc+dx
32-
ymin = yc-dx
33-
ymax = yc+dx
31+
xmin = xc-0.5*dx
32+
xmax = xc+0.5*dx
33+
ymin = yc-0.5*dx
34+
ymax = yc+0.5*dx
35+
36+
37+
# dagger
38+
#xmin = -0.8
39+
#xmax = -0.7
40+
#ymin = 0.0
41+
#ymax = 0.1
3442

3543
x = np.linspace(xmin, xmax, N, dtype=np.float)
3644
y = np.linspace(ymin, ymax, N, dtype=np.float)
@@ -43,13 +51,13 @@
4351
niter = np.zeros((N,N), dtype=np.int)
4452
niter[:,:] = -1
4553

46-
MAX_ITER = 256
54+
MAX_ITER = 1024
4755

4856
for n in range(MAX_ITER):
4957
# potentially faster
50-
#idx = niter == -1
51-
#z[idx] = z[idx]**2 + c[idx]
52-
z = z**2 + c
58+
idx = niter == -1
59+
z[idx] = z[idx]**2 + c[idx]
60+
#z = z**2 + c
5361
idx = np.logical_and(abs(z) > 2, niter == -1)
5462
niter[idx] = n
5563

@@ -58,7 +66,13 @@
5866

5967
print(niter.min(), niter.max())
6068

61-
plt.imshow(niter.T, extent=[xmin, xmax, ymin, ymax], origin="lower", cmap="magma_r")
69+
# we should do the colors based on putting equal numbers of points in
70+
# the plot for each color value, using a histogram
71+
hist, edges = np.histogram(niter, range=(0, MAX_ITER-1), bins=256)
72+
centers = 0.5*(edges[1:] + edges[:-1])
73+
74+
75+
plt.imshow(niter.T, extent=[xmin, xmax, ymin, ymax], origin="lower", cmap="gnuplot2") #cmap="magma_r")
6276
f = plt.gcf()
6377
f.set_size_inches(8.0, 8.0)
6478
#plt.show()

0 commit comments

Comments
 (0)