/[escript]/trunk/pyvisi/examples/contourPlotMovie.py
ViewVC logotype

Contents of /trunk/pyvisi/examples/contourPlotMovie.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 605 - (show annotations)
Mon Mar 20 07:16:27 2006 UTC (13 years, 7 months ago) by gross
File MIME type: text/x-python
File size: 2993 byte(s)
pyvisi with vtk runs noe on the altix
1 # $Id: contourPlotMovie.py,v 1.2 2005/11/08 05:11:13 paultcochrane Exp $
2
3 """
4 Example of contour plotting a changing function with pyvisi
5 """
6
7 # what plotting method are we using?
8 method = 'pyvisi'
9
10 # set up some data to plot
11 from Numeric import *
12
13 # the x and y axes
14 x = arange(-2,2,0.2, typecode=Float)
15 y = arange(-2,3,0.2, typecode=Float)
16
17 # pick some interesting function to generate the data in the third dimension
18 # this is the one used in the matlab docs: z = x*exp(-x^2-y^2)
19 z = zeros((len(x),len(y)), typecode=Float)
20
21 # boy do *I* feel old fashioned writing it this way
22 # surely there's another way to do it: - something to do later
23 for i in range(len(x)):
24 for j in range(len(y)):
25 z[i,j] = x[i]*exp(-x[i]*x[i] - y[j]*y[j])
26
27 # plot it with either gnuplot, vtk or pyvisi
28 if method == 'pyvisi':
29 #### pyvisi version of code
30
31 # import the general pyvisi stuff
32 from esys.pyvisi import *
33 # import the gnuplot overrides of the interface
34 #from esys.pyvisi.renderers.gnuplot import *
35 from esys.pyvisi.renderers.vtk import *
36
37 # define a scene object
38 # a Scene is a container for all of the kinds of things you want to put
39 # into your plot, for instance, images, meshes, arrow/vector/quiver
40 # plots, contour plots, spheres etc.
41 scene = Scene()
42
43 # create a ContourPlot object
44 plot = ContourPlot(scene)
45
46 # add some helpful info to the plot
47 plot.title = 'Example contour plot'
48 plot.xlabel = 'x'
49 plot.ylabel = 'y'
50
51 for i in range(100):
52 # assign the data to the plot
53 # this version assumes that we have x, then y, then z and that z is 2D
54 # and that x and y are 1D arrays
55 plot.setData(x,y,z)
56 # alternative syntax
57 #plot.setData(xData=x, yData=y, zData=z)
58 # or (but more confusing depending upon one's naming conventions)
59 #plot.setData(x=x, y=y, z=z)
60
61 # save the scene to file
62 scene.save(fname="contourPlotMovie%03d.png"%i, format=PngImage())
63
64 # update the value of z to plot
65 z = z*0.9
66
67 elif method == 'gnuplot':
68 #### original gnuplot code
69
70 import Gnuplot
71
72 # set the plot up
73 _gnuplot = Gnuplot.Gnuplot()
74 _gnuplot.title('Example contour plot')
75 _gnuplot.xlabel('x')
76 _gnuplot.ylabel('y')
77 #_gnuplot.zlabel('z')
78
79 # this is a contour plot, so...
80 _gnuplot('set contour base')
81 _gnuplot('set view 0, 0, 1, 1')
82 _gnuplot('set nosurface')
83 _gnuplot('set terminal png')
84
85 for i in range(100):
86 plotString = "set output \"contourPlotMovie%03d.png\""%i
87 _gnuplot(plotString)
88 # set up the data
89 _data = Gnuplot.GridData(z,x,y, binary=1)
90
91 _gnuplot.splot(_data)
92
93 # update the value of z to plot
94 z = z*0.9
95
96 raw_input('Press enter to continue...')
97
98 elif method == 'vtk':
99 print "vtk contour plotting not yet implemented"
100
101 else:
102 print "Eeek! What plotting method am I supposed to use???"
103
104 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26