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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 605 - (hide annotations)
Mon Mar 20 07:16:27 2006 UTC (13 years, 8 months ago) by gross
File MIME type: text/x-python
File size: 4114 byte(s)
pyvisi with vtk runs noe on the altix
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     """
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 gross 605 from esys.pyvisi import *
33 cochrane 337 # import the gnuplot overrides of the interface
34 gross 605 #from esys.pyvisi.renderers.gnuplot import *
35     from esys.pyvisi.renderers.plplot import *
36 cochrane 337
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 SurfacePlot object
44     plot = SurfacePlot(scene)
45    
46     # add some helpful info to the plot
47     plot.title = 'Example surface plot'
48     plot.xlabel = 'x'
49     plot.ylabel = 'y'
50     plot.zlabel = 'z'
51    
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     # render the scene to screen
62     scene.render(pause=True, interactive=True)
63    
64     # save the scene to file
65     plot.setData(x,y,z) # have to do this now because we've already
66     # render()ed the scene. This requirement will be
67     # removed in the future
68     scene.save(fname="surfacePlot.png", format=PngImage())
69    
70     elif method == 'vtk':
71     print "vtk surface plotting not yet implemented"
72    
73     elif method == 'plplot':
74     import plplot
75    
76     # determine the min and max of x, y, and z in world coordinates
77     xMin = min(x)
78     xMax = max(x)
79    
80     yMin = min(y)
81     yMax = max(y)
82    
83     zMin = min(z.flat)
84     zMax = max(z.flat)
85    
86     # min and max of x and y variables in normalised coordinates
87     # (these are values recommended by plplot in an example)
88     xMin2D = -2.5
89     xMax2D = 2.5
90    
91     yMin2D = -2.5
92     yMax2D = 4.0
93    
94     # sides of box in normalised coordinates
95     # (these are values recommended by plplot in an example)
96     basex = 2.0
97     basey = 4.0
98     height = 3.0
99    
100     # angle to view box
101     alt = 45.0
102     az = 30.0
103    
104     side = 1
105     opt = 3 # plots a net of lines
106    
107     plplot.plsdev("xwin")
108     plplot.plinit()
109     plplot.plenv(xMin2D, xMax2D, yMin2D, yMax2D, 0, -2)
110     plplot.plw3d(basex, basey, height,
111     xMin, xMax, yMin, yMax, zMin, zMax,
112     alt, az)
113     plplot.plmtex("t", 1.0, 0.5, 0.5, "Example surface plot")
114     plplot.plbox3("bnstu", "x axis", 0.0, 0,
115     "bnstu", "y axis", 0.0, 0,
116     "bcdmnstuv", "z axis", 0.0, 0)
117     plplot.plsurf3d(x, y, z, 0, ())
118     plplot.plend()
119    
120     # to save as well, have to set everything up again, and replot
121     # save as png
122     plplot.plsdev("png")
123     plplot.plsfnam("surfacePlot.png")
124     plplot.plinit()
125     plplot.plenv(xMin2D, xMax2D, yMin2D, yMax2D, 0, -2)
126     plplot.plw3d(basex, basey, height,
127     xMin, xMax, yMin, yMax, zMin, zMax,
128     alt, az)
129     plplot.plmtex("t", 1.0, 0.5, 0.5, "Example surface plot")
130     plplot.plbox3("bnstu", "x axis", 0.0, 0,
131     "bnstu", "y axis", 0.0, 0,
132     "bcdmnstuv", "z axis", 0.0, 0)
133     plplot.plsurf3d(x, y, z, 0, ())
134     plplot.plend()
135    
136     else:
137     print "Eeek! What plotting method am I supposed to use???"
138    
139     # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26