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

Annotation of /trunk/pyvisi/examples/surfacePlotExample.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: 4722 byte(s)
more copyright statements added
1 cochrane 337 # $Id: surfacePlotExample.py,v 1.6 2005/05/05 00:46:44 paultcochrane Exp $
2    
3     """
4     Example of plotting surfaces 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.plplot 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 SurfacePlot object
62     plot = SurfacePlot(scene)
63    
64     # add some helpful info to the plot
65     plot.title = 'Example surface plot'
66     plot.xlabel = 'x'
67     plot.ylabel = 'y'
68     plot.zlabel = 'z'
69    
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     # render the scene to screen
80     scene.render(pause=True, interactive=True)
81    
82     # save the scene to file
83     plot.setData(x,y,z) # have to do this now because we've already
84     # render()ed the scene. This requirement will be
85     # removed in the future
86     scene.save(fname="surfacePlot.png", format=PngImage())
87    
88     elif method == 'vtk':
89     print "vtk surface plotting not yet implemented"
90    
91     elif method == 'plplot':
92     import plplot
93    
94     # determine the min and max of x, y, and z in world coordinates
95     xMin = min(x)
96     xMax = max(x)
97    
98     yMin = min(y)
99     yMax = max(y)
100    
101     zMin = min(z.flat)
102     zMax = max(z.flat)
103    
104     # min and max of x and y variables in normalised coordinates
105     # (these are values recommended by plplot in an example)
106     xMin2D = -2.5
107     xMax2D = 2.5
108    
109     yMin2D = -2.5
110     yMax2D = 4.0
111    
112     # sides of box in normalised coordinates
113     # (these are values recommended by plplot in an example)
114     basex = 2.0
115     basey = 4.0
116     height = 3.0
117    
118     # angle to view box
119     alt = 45.0
120     az = 30.0
121    
122     side = 1
123     opt = 3 # plots a net of lines
124    
125     plplot.plsdev("xwin")
126     plplot.plinit()
127     plplot.plenv(xMin2D, xMax2D, yMin2D, yMax2D, 0, -2)
128     plplot.plw3d(basex, basey, height,
129     xMin, xMax, yMin, yMax, zMin, zMax,
130     alt, az)
131     plplot.plmtex("t", 1.0, 0.5, 0.5, "Example surface plot")
132     plplot.plbox3("bnstu", "x axis", 0.0, 0,
133     "bnstu", "y axis", 0.0, 0,
134     "bcdmnstuv", "z axis", 0.0, 0)
135     plplot.plsurf3d(x, y, z, 0, ())
136     plplot.plend()
137    
138     # to save as well, have to set everything up again, and replot
139     # save as png
140     plplot.plsdev("png")
141     plplot.plsfnam("surfacePlot.png")
142     plplot.plinit()
143     plplot.plenv(xMin2D, xMax2D, yMin2D, yMax2D, 0, -2)
144     plplot.plw3d(basex, basey, height,
145     xMin, xMax, yMin, yMax, zMin, zMax,
146     alt, az)
147     plplot.plmtex("t", 1.0, 0.5, 0.5, "Example surface plot")
148     plplot.plbox3("bnstu", "x axis", 0.0, 0,
149     "bnstu", "y axis", 0.0, 0,
150     "bcdmnstuv", "z axis", 0.0, 0)
151     plplot.plsurf3d(x, y, z, 0, ())
152     plplot.plend()
153    
154     else:
155     print "Eeek! What plotting method am I supposed to use???"
156    
157     # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26