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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26