/[escript]/trunk/pyvisi_old/examples/contourPlotMovieExample.py
ViewVC logotype

Contents of /trunk/pyvisi_old/examples/contourPlotMovieExample.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 786 - (show annotations)
Tue Jul 25 04:58:05 2006 UTC (13 years, 2 months ago) by gross
File MIME type: text/x-python
File size: 3577 byte(s)
switched off pyvisi
1 # $Id: contourPlotMovieExample.py,v 1.3 2005/03/07 05:23:37 paultcochrane Exp $
2
3 """
4 Example of contour plotting a changing function with pyvisi
5
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 """
13
14 __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 # 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 from esys.pyvisi import *
51 # import the gnuplot overrides of the interface
52 from esys.pyvisi.renderers.gnuplot import *
53
54 # define a scene object
55 # a Scene is a container for all of the kinds of things you want to put
56 # into your plot, for instance, images, meshes, arrow/vector/quiver
57 # plots, contour plots, spheres etc.
58 scene = Scene()
59
60 # create a ContourPlot object
61 plot = ContourPlot(scene)
62
63 # add some helpful info to the plot
64 plot.title = 'Example contour plot'
65 plot.xlabel = 'x'
66 plot.ylabel = 'y'
67
68 for i in range(100):
69 # assign the data to the plot
70 # this version assumes that we have x, then y, then z and that z is 2D
71 # and that x and y are 1D arrays
72 plot.setData(x,y,z)
73 # alternative syntax
74 #plot.setData(xData=x, yData=y, zData=z)
75 # or (but more confusing depending upon one's naming conventions)
76 #plot.setData(x=x, y=y, z=z)
77
78 # save the scene to file
79 scene.save(fname="contourPlotMovieExample%03d.png"%i, format=PngImage())
80
81 # update the value of z to plot
82 z = z*0.9
83
84 elif method == 'gnuplot':
85 #### original gnuplot code
86
87 import Gnuplot
88
89 # set the plot up
90 _gnuplot = Gnuplot.Gnuplot()
91 _gnuplot.title('Example contour plot')
92 _gnuplot.xlabel('x')
93 _gnuplot.ylabel('y')
94 #_gnuplot.zlabel('z')
95
96 # this is a contour plot, so...
97 _gnuplot('set contour base')
98 _gnuplot('set view 0, 0, 1, 1')
99 _gnuplot('set nosurface')
100 _gnuplot('set terminal png')
101
102 for i in range(100):
103 plotString = "set output \"contourPlotMovieExample%03d.png\""%i
104 _gnuplot(plotString)
105 # set up the data
106 _data = Gnuplot.GridData(z,x,y, binary=1)
107
108 _gnuplot.splot(_data)
109
110 # update the value of z to plot
111 z = z*0.9
112
113 raw_input('Press enter to continue...')
114
115 elif method == 'vtk':
116 print "vtk contour plotting not yet implemented"
117
118 else:
119 print "Eeek! What plotting method am I supposed to use???"
120
121 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26