correct table format
[PyX/mjg.git] / gallery / graphs / mandel.py
blobdecdaf0dfe5229142be284a6990635a23f5c117f
1 # contributed by Stephen Phillips
3 from pyx import *
5 # Mandelbrot parameters
6 re_min = -2
7 re_max = 0.5
8 im_min = -1.25
9 im_max = 1.25
10 gridx = 100
11 gridy = 100
12 max_iter = 10
14 # Set-up
15 re_step = (re_max - re_min) / gridx
16 im_step = (im_max - im_min) / gridy
17 d = []
19 # Compute fractal
20 for re_index in range(gridx):
21 re = re_min + re_step * (re_index + 0.5)
22 for im_index in range(gridy):
23 im = im_min + im_step * (im_index + 0.5)
24 c = complex(re, im)
25 n = 0
26 z = complex(0, 0)
27 while n < max_iter and abs(z) < 2:
28 z = (z * z) + c
29 n += 1
30 d.append([re - 0.5 * re_step, re + 0.5 * re_step,
31 im - 0.5 * im_step, im + 0.5 * im_step,
32 float(n)/max_iter])
34 # Plot graph
35 g = graph.graphxy(height=8, width=8,
36 x=graph.axis.linear(min=re_min, max=re_max, title=r'$\Re(c)$'),
37 y=graph.axis.linear(min=im_min, max=im_max, title=r'$\Im(c)$'))
38 g.plot(graph.data.points(d, xmin=1, xmax=2, ymin=3, ymax=4, color=5),
39 [graph.style.rect(color.gradient.Rainbow)])
40 g.dodata() # plot data first, then axes
41 g.writeEPSfile('mandel')
42 g.writePDFfile('mandel')