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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 637 - (hide annotations)
Thu Mar 23 10:55:31 2006 UTC (14 years, 3 months ago) by gross
File MIME type: text/x-python
File size: 3601 byte(s)
more copyright statements added
1 cochrane 337 # $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 gross 637
6     @var __author__: name of author
7     @var __license__: licence agreement
8     @var __copyright__: copyrights
9     @var __url__: url entry point on documentation
10     @var __version__: version
11     @var __date__: date of the version
12 cochrane 337 """
13    
14 gross 637 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
15     http://www.access.edu.au
16     Primary Business: Queensland, Australia"""
17     __license__="""Licensed under the Open Software License version 3.0
18     http://www.opensource.org/licenses/osl-3.0.php"""
19     __author__="Paul Cochrane"
20     __url__="http://www.iservo.edu.au/esys"
21     __version__="$Revision$"
22     __date__="$Date$"
23    
24    
25 cochrane 337 # what plotting method are we using?
26     method = 'pyvisi'
27    
28     # set up some data to plot
29     from Numeric import *
30    
31     # the x and y axes
32     x = arange(-2,2,0.2, typecode=Float)
33     y = arange(-2,3,0.2, typecode=Float)
34    
35     # pick some interesting function to generate the data in the third dimension
36     # this is the one used in the matlab docs: z = x*exp(-x^2-y^2)
37     z = zeros((len(x),len(y)), typecode=Float)
38    
39     # boy do *I* feel old fashioned writing it this way
40     # surely there's another way to do it: - something to do later
41     for i in range(len(x)):
42     for j in range(len(y)):
43     z[i,j] = x[i]*exp(-x[i]*x[i] - y[j]*y[j])
44    
45     # plot it with either gnuplot, vtk or pyvisi
46     if method == 'pyvisi':
47     #### pyvisi version of code
48    
49     # import the general pyvisi stuff
50 gross 605 from esys.pyvisi import *
51 cochrane 337 # import the gnuplot overrides of the interface
52 gross 605 #from esys.pyvisi.renderers.gnuplot import *
53     from esys.pyvisi.renderers.vtk import *
54 cochrane 337
55     # define a scene object
56     # a Scene is a container for all of the kinds of things you want to put
57     # into your plot, for instance, images, meshes, arrow/vector/quiver
58     # plots, contour plots, spheres etc.
59     scene = Scene()
60    
61     # create a ContourPlot object
62     plot = ContourPlot(scene)
63    
64     # add some helpful info to the plot
65     plot.title = 'Example contour plot'
66     plot.xlabel = 'x'
67     plot.ylabel = 'y'
68    
69     for i in range(100):
70     # assign the data to the plot
71     # this version assumes that we have x, then y, then z and that z is 2D
72     # and that x and y are 1D arrays
73     plot.setData(x,y,z)
74     # alternative syntax
75     #plot.setData(xData=x, yData=y, zData=z)
76     # or (but more confusing depending upon one's naming conventions)
77     #plot.setData(x=x, y=y, z=z)
78    
79     # save the scene to file
80     scene.save(fname="contourPlotMovie%03d.png"%i, format=PngImage())
81    
82     # update the value of z to plot
83     z = z*0.9
84    
85     elif method == 'gnuplot':
86     #### original gnuplot code
87    
88     import Gnuplot
89    
90     # set the plot up
91     _gnuplot = Gnuplot.Gnuplot()
92     _gnuplot.title('Example contour plot')
93     _gnuplot.xlabel('x')
94     _gnuplot.ylabel('y')
95     #_gnuplot.zlabel('z')
96    
97     # this is a contour plot, so...
98     _gnuplot('set contour base')
99     _gnuplot('set view 0, 0, 1, 1')
100     _gnuplot('set nosurface')
101     _gnuplot('set terminal png')
102    
103     for i in range(100):
104     plotString = "set output \"contourPlotMovie%03d.png\""%i
105     _gnuplot(plotString)
106     # set up the data
107     _data = Gnuplot.GridData(z,x,y, binary=1)
108    
109     _gnuplot.splot(_data)
110    
111     # update the value of z to plot
112     z = z*0.9
113    
114     raw_input('Press enter to continue...')
115    
116     elif method == 'vtk':
117     print "vtk contour plotting not yet implemented"
118    
119     else:
120     print "Eeek! What plotting method am I supposed to use???"
121    
122     # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26