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

Contents of /trunk/pyvisi_old/examples/surfaceAndContourPlotExample.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 786 - (show annotations)
Tue Jul 25 04:58:05 2006 UTC (13 years, 2 months ago) by gross
File MIME type: text/x-python
File size: 3940 byte(s)
switched off pyvisi
1 # $Id: surfaceAndContourPlotExample.py,v 1.4 2005/03/07 05:23:37 paultcochrane Exp $
2
3 """
4 Example of plotting surfaces with contours in pyvisi
5
6 Will hopefully help me write a decent interface.
7
8 @var __author__: name of author
9 @var __license__: licence agreement
10 @var __copyright__: copyrights
11 @var __url__: url entry point on documentation
12 @var __version__: version
13 @var __date__: date of the version
14 """
15
16 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
17 http://www.access.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __author__="Paul Cochrane"
22 __url__="http://www.iservo.edu.au/esys"
23 __version__="$Revision$"
24 __date__="$Date$"
25
26
27 # what plotting method are we using?
28 method = 'pyvisi'
29
30 # set up some data to plot
31 from Numeric import *
32
33 # the x and y axes
34 x = arange(-2,2,0.2, typecode=Float)
35 y = arange(-2,3,0.2, typecode=Float)
36
37 # pick some interesting function to generate the data in the third dimension
38 # this is the one used in the matlab docs: z = x*exp(-x^2-y^2)
39 z = zeros((len(x),len(y)), typecode=Float)
40
41 # boy do *I* feel old fashioned writing it this way
42 # surely there's another way to do it: - something to do later
43 for i in range(len(x)):
44 for j in range(len(y)):
45 z[i,j] = x[i]*exp(-x[i]*x[i] - y[j]*y[j])
46
47 # plot it with either gnuplot, vtk or pyvisi
48 if method == 'pyvisi':
49 #### pyvisi version of code
50
51 # import the general pyvisi stuff
52 from esys.pyvisi import *
53 # import the gnuplot overrides of the interface
54 from esys.pyvisi.renderers.gnuplot import *
55
56 # define a scene object
57 # a Scene is a container for all of the kinds of things you want to put
58 # into your plot, for instance, images, meshes, arrow/vector/quiver
59 # plots, contour plots, spheres etc.
60 scene = Scene()
61
62 # create a SurfacePlot object
63 plot = SurfacePlot(scene)
64
65 # add some helpful info to the plot
66 plot.title = 'Example surface plot with contour on base'
67 plot.xlabel = 'x'
68 plot.ylabel = 'y'
69 plot.zlabel = 'z'
70
71 # add a contour to the base of the axes
72 plot.contours = True
73
74 # assign the data to the plot
75 # this version assumes that we have x, then y, then z and that z is 2D
76 # and that x and y are 1D arrays
77 plot.setData(x,y,z)
78 # alternative syntax
79 #plot.setData(xData=x, yData=y, zData=z)
80 # or (but more confusing depending upon one's naming conventions)
81 #plot.setData(x=x, y=y, z=z)
82
83 # render the scene to screen
84 scene.render(pause=True, interactive=True)
85
86 # save the scene to file
87 plot.setData(x,y,z) # have to do this now because we've already
88 # render()ed the scene. This requirement will be
89 # removed in the future
90 scene.save(fname="surfaceAndContourPlotExample.png", format=PngImage())
91 plot.setData(x,y,z) # have to do this now because we've already save()d
92 # the scene. This requirement will be removed in
93 # the future
94 scene.save(fname="surfaceAndContourPlotExample.ps", format=PsImage())
95
96 elif method == 'gnuplot':
97 #### original gnuplot code
98
99 import Gnuplot
100
101 # set the plot up
102 _gnuplot = Gnuplot.Gnuplot()
103 _gnuplot.title('Example surface plot with contour on base')
104 _gnuplot.xlabel('x')
105 _gnuplot.ylabel('y')
106 _gnuplot('set zlabel \'z\'')
107
108 # this is a surface plot, so...
109 _gnuplot('set surface')
110 _gnuplot('set data style lines')
111 _gnuplot('set contour base')
112
113 # set up the data
114 _data = Gnuplot.GridData(z,x,y, binary=1)
115
116 _gnuplot.splot(_data)
117
118 raw_input('Press enter to continue...')
119
120 elif method == 'vtk':
121 print "vtk surface plotting not yet implemented"
122
123 else:
124 print "Eeek! What plotting method am I supposed to use???"
125
126 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26