add UnicodeEngine (MultiEngineText and axis texters returning MultiEngineText), texte...
[PyX.git] / examples / graphstyles / density.py
blob94ed92ad3b7d07d70f61f53a00652e986bfb2b47
1 from pyx import *
3 # Mandelbrot calculation contributed by Stephen Phillips
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, im, n])
32 # Plot graph
33 g = graph.graphxy(height=8, width=8,
34 x=graph.axis.linear(min=re_min, max=re_max, title=r"$\Re(c)$"),
35 y=graph.axis.linear(min=im_min, max=im_max, title=r'$\Im(c)$'))
36 g.plot(graph.data.points(d, x=1, y=2, color=3, title="iterations"),
37 [graph.style.density(gradient=color.rgbgradient.Rainbow)])
38 g.writeEPSfile()
39 g.writePDFfile()
40 g.writeSVGfile()