 # Contents of /trunk/pyvisi/examples/surfaceAndContourPlot.py

Revision 337 - (show annotations)
Mon Dec 12 01:57:07 2005 UTC (14 years, 5 months ago) by cochrane
File MIME type: text/x-python
File size: 2080 byte(s)
```Initial merge of pyvisi into esys repository.
```
 1 # \$Id: surfaceAndContourPlot.py,v 1.3 2005/11/08 08:23:45 paultcochrane Exp \$ 2 3 """ 4 Example of plotting surfaces with contours in pyvisi 5 """ 6 7 import sys 8 numArgs = len(sys.argv) 9 if numArgs == 1: 10 ren_mod = "gnuplot" 11 else: 12 ren_mod = sys.argv 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 pyvisi import * 33 # import the renderer-specific overrides of the interface 34 if ren_mod == "gnuplot": 35 from pyvisi.renderers.gnuplot import * 36 elif ren_mod == "vtk": 37 from pyvisi.renderers.vtk import * 38 else: 39 raise ValueError, "Unknown renderer module" 40 41 # define a scene object 42 # a Scene is a container for all of the kinds of things you want to put 43 # into your plot, for instance, images, meshes, arrow/vector/quiver 44 # plots, contour plots, spheres etc. 45 scene = Scene() 46 47 # create a SurfacePlot object 48 plot = SurfacePlot(scene) 49 50 # add some helpful info to the plot 51 plot.title = 'Example surface plot with contour on base' 52 plot.xlabel = 'x' 53 plot.ylabel = 'y' 54 plot.zlabel = 'z' 55 56 # add a contour to the base of the axes 57 plot.contours = True 58 59 # assign the data to the plot 60 # this version assumes that we have x, then y, then z and that z is 2D 61 # and that x and y are 1D arrays 62 plot.setData(x,y,z) 63 # alternative syntax 64 #plot.setData(xData=x, yData=y, zData=z) 65 # or (but more confusing depending upon one's naming conventions) 66 #plot.setData(x=x, y=y, z=z) 67 68 # render the scene to screen 69 scene.render(pause=True, interactive=True) 70 71 # save the scene to file 72 scene.save(fname="surfaceAndContourPlot.png", format=PngImage()) 73 74 # vim: expandtab shiftwidth=4: