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

Contents of /trunk/pyvisi/examples/meshPlotExample.py

Parent Directory Parent Directory | Revision Log Revision Log


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: 2306 byte(s)
Initial merge of pyvisi into esys repository.
1 # $Id: meshPlotExample.py,v 1.2 2005/05/24 01:33:54 paultcochrane Exp $
2
3 """
4 Example of plotting meshed 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 from pyvisi import *
33 # import the gnuplot overrides of the interface
34 from pyvisi.renderers.gnuplot import *
35
36 # define a scene object
37 # a Scene is a container for all of the kinds of things you want to put
38 # into your plot, for instance, images, meshes, arrow/vector/quiver
39 # plots, contour plots, spheres etc.
40 scene = Scene()
41
42 # create a MeshPlot object
43 plot = MeshPlot(scene)
44
45 # add some helpful info to the plot
46 plot.title = 'Example mesh plot'
47 plot.xlabel = 'x'
48 plot.ylabel = 'y'
49 plot.zlabel = 'z'
50
51 # assign the data to the plot
52 # this version assumes that we have x, then y, then z and that z is 2D
53 # and that x and y are 1D arrays
54 plot.setData(x,y,z)
55 # alternative syntax
56 #plot.setData(xData=x, yData=y, zData=z)
57 # or (but more confusing depending upon one's naming conventions)
58 #plot.setData(x=x, y=y, z=z)
59
60 # render the scene to screen
61 scene.render(pause=True, interactive=True)
62
63 # save the scene to file
64 plot.setData(x,y,z) # have to do this now because we've already
65 # render()ed the scene. This requirement will be
66 # removed in the future
67 scene.save(fname="meshPlot.png", format=PngImage())
68
69 elif method == 'vtk':
70 print "vtk mesh plotting not yet implemented"
71
72 else:
73 print "Eeek! What plotting method am I supposed to use???"
74
75 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26