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

Contents of /trunk/pyvisi_old/examples/surfacePlot.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
Original Path: trunk/pyvisi/examples/surfacePlot.py
File MIME type: text/x-python
File size: 2039 byte(s)
pyvisi with vtk runs noe on the altix
1 # $Id: surfacePlot.py,v 1.5 2005/11/10 08:38:06 paultcochrane Exp $
2
3 """
4 Example of plotting surfaces with pyvisi
5 """
6
7 import sys
8 numArgs = len(sys.argv)
9 if numArgs == 1:
10 ren_mod = "vtk"
11 else:
12 ren_mod = sys.argv[1]
13
14 # set up some data to plot
15 from Numeric import *
16
17 # the x and y axes
18 x = arange(-2,2,0.2, typecode=Float)
19 y = arange(-2,3,0.2, typecode=Float)
20
21 # pick some interesting function to generate the data in the third dimension
22 # this is the one used in the matlab docs: z = x*exp(-x^2-y^2)
23 z = zeros((len(x),len(y)), typecode=Float)
24
25 # boy do *I* feel old fashioned writing it this way
26 # surely there's another way to do it: - something to do later
27 for i in range(len(x)):
28 for j in range(len(y)):
29 z[i,j] = x[i]*exp(-x[i]*x[i] - y[j]*y[j])
30
31 # import the general pyvisi stuff
32 from esys.pyvisi import *
33 # import the gnuplot overrides of the interface
34 if ren_mod == "gnuplot":
35 from esys.pyvisi.renderers.gnuplot import *
36 elif ren_mod == "vtk":
37 from esys.pyvisi.renderers.vtk import *
38 elif ren_mod == "plplot":
39 from esys.pyvisi.renderers.plplot import *
40 else:
41 raise ValueError, "Unknown renderer module"
42
43 # define a scene object
44 # a Scene is a container for all of the kinds of things you want to put
45 # into your plot, for instance, images, meshes, arrow/vector/quiver
46 # plots, contour plots, spheres etc.
47 scene = Scene()
48
49 # create a SurfacePlot object
50 plot = SurfacePlot(scene)
51
52 # add some helpful info to the plot
53 plot.title = 'Example surface plot'
54 plot.xlabel = 'x'
55 plot.ylabel = 'y'
56 plot.zlabel = 'z'
57
58 # assign the data to the plot
59 # this version assumes that we have x, then y, then z and that z is 2D
60 # and that x and y are 1D arrays
61 plot.setData(x,y,z)
62 # alternative syntax
63 #plot.setData(xData=x, yData=y, zData=z)
64 # or (but more confusing depending upon one's naming conventions)
65 #plot.setData(x=x, y=y, z=z)
66
67 # render the scene to screen
68 scene.render(pause=True, interactive=True)
69
70 # save the scene to file
71 scene.save(fname="surfacePlot.png", format=PngImage())
72
73 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26