2009年9月10日木曜日

Gnuplot-py のサンプル(マンデルブロー集合) Gnuplot-py sample code (for Mandelbrot set)

Gnuplot-pyライブラリをインストールすると、どこかにdemo.pyができているのでこいつを参考にしてコードを書いた。



import psyco
psyco.full()
import Gnuplot, Gnuplot.funcutils
from scipy import *

STOP_VALUE = 4

#CX_AREA=[-1.495,-1.475]
#CY_AREA=[-0.02,0.045]
CX_AREA=[0,0.4]
CY_AREA=[-0.65,-0.35]
SIZE = 300
YSTEP = (CY_AREA[1]-CY_AREA[0])/SIZE

XSTEP = (CX_AREA[1]-CX_AREA[0])/SIZE

def mandelbrot_seq(x,y):
mandelbrot_seq = 0.+0.j
c=x+y*1j
for n in range(0,100):
mandelbrot_seq=mandelbrot_seq**2+c
if abs(mandelbrot_seq)>STOP_VALUE:#avoid overflow(mandelbrot_seq is too large number)
break
else:
pass
return abs(mandelbrot_seq**2+c-mandelbrot_seq)


g = Gnuplot.Gnuplot(debug=1)
#g('set parametric')
#g('set data style lines')
g('set hidden')
g('set pm3d map')
#g('set contour base')
#g.title('An example of a surface plot')
g.xlabel('Re axis')
g.ylabel('Im axis')

x = arange(CX_AREA[0],CX_AREA[1],XSTEP)
y = arange(CY_AREA[0],CY_AREA[1],YSTEP)

g.splot(Gnuplot.funcutils.compute_GridData(x,y, mandelbrot_seq, binary=0))


g('set pm3d')をg('set pm3d map')に変更すると底面のマップのみが表示されるのでこっちのほうが見やすい。

0 件のコメント:

コメントを投稿