/[escript]/trunk/pyvisi/py_src/renderers/gnuplot/surface_plot.py
ViewVC logotype

Contents of /trunk/pyvisi/py_src/renderers/gnuplot/surface_plot.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 605 - (show annotations)
Mon Mar 20 07:16:27 2006 UTC (13 years, 6 months ago) by gross
File MIME type: text/x-python
File size: 5036 byte(s)
pyvisi with vtk runs noe on the altix
1 # Copyright (C) 2004-2005 Paul Cochrane
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # $Id: surface_plot.py,v 1.1 2005/11/30 04:29:53 paultcochrane Exp $
18
19 """
20 Class and functions associated with a pyvisi SurfacePlot objects (gnuplot)
21 """
22
23 # generic imports
24 from common import debugMsg
25 import copy
26
27 # module specific imports
28 from gnuplot.plot import Plot
29
30 __revision__ = '$Revision: 1.1 $'
31
32 class SurfacePlot(Plot):
33 """
34 Surface plot
35 """
36
37 def __init__(self, scene):
38 """
39 Initialisation of SurfacePlot class
40
41 @param scene: the scene with which to associate the SurfacePlot
42 @type scene: Scene object
43 """
44 debugMsg("Called SurfacePlot.__init__()")
45 Plot.__init__(self, scene)
46
47 # grab the renderer
48 self.renderer = scene.renderer
49
50 # set up some of the attributes
51 self.title = None
52 self.xlabel = None
53 self.ylabel = None
54 self.zlabel = None
55
56 # to show contours of the surface on the bottom of the axes, set
57 # this variable to True
58 self.contours = False
59
60 # now add the object to the scene
61 scene.add(self)
62
63 def setData(self, *dataList):
64 """
65 Sets the data to the given plot object.
66
67 @param dataList: list of data objects to plot
68 @type dataList: tuple
69 """
70 debugMsg("Called setData() in SurfacePlot()")
71
72 self.renderer.runString("# SurfacePlot.setData()")
73
74 # for the moment, make sure that there are three arrays
75 if len(dataList) != 3:
76 raise ValueError, "Must have three arrays as input (at present)"
77
78 # do some sanity checks on the data
79 xData = dataList[0]
80 yData = dataList[1]
81 zData = dataList[2]
82
83 if len(xData.shape) != 1:
84 raise ValueError, "x data array is not of the correct shape: %s"\
85 % xData.shape
86
87 if len(yData.shape) != 1:
88 raise ValueError, "y data array is not of the correct shape: %s"\
89 % yData.shape
90
91 if len(zData.shape) != 2:
92 raise ValueError, "z data array is not of the correct shape: %s"\
93 % zData.shape
94
95 # share around the data
96 ## the x data
97 self.renderer.renderDict['_x'] = copy.deepcopy(xData)
98
99 ## the y data
100 self.renderer.renderDict['_y'] = copy.deepcopy(yData)
101
102 ## the z data
103 self.renderer.renderDict['_z'] = copy.deepcopy(zData)
104
105 self.renderer.runString(\
106 "_data = Gnuplot.GridData(_z, _x, _y, binary=1)")
107
108 return
109
110 def render(self):
111 """
112 Does SurfacePlot object specific rendering stuff
113 """
114 debugMsg("Called SurfacePlot.render()")
115
116 self.renderer.runString("# SurfacePlot.render()")
117 self.renderer.runString("_gnuplot('set surface')")
118
119 # if a title is set, put it here
120 if self.title is not None:
121 evalString = "_gnuplot.title(\'%s\')" % self.title
122 self.renderer.runString(evalString)
123
124 # if an xlabel is set, add it
125 if self.xlabel is not None:
126 evalString = "_gnuplot.xlabel(\'%s\')" % self.xlabel
127 self.renderer.runString(evalString)
128
129 # if a ylabel is set add it
130 if self.ylabel is not None:
131 evalString = "_gnuplot.ylabel(\'%s\')" % self.ylabel
132 self.renderer.runString(evalString)
133
134 # if a zlabel is set add it
135 if self.zlabel is not None:
136 evalString = "_gnuplot('set zlabel \\'%s\\'')" % self.zlabel
137 self.renderer.runString(evalString)
138
139 # dunno if need this - could be just for gnuplot3
140 evalString = "_gnuplot('set style data lines')"
141 self.renderer.runString(evalString)
142
143 # makes sure that hidden lines are removed
144 evalString = "_gnuplot('set hidden3d')"
145 self.renderer.runString(evalString)
146
147 # if contours is true, set the relevant option
148 if self.contours:
149 evalString = "_gnuplot('set contour base')"
150 self.renderer.runString(evalString)
151
152 self.renderer.runString("_gnuplot('set pm3d')")
153
154 # set up the evalString to use for plotting
155 evalString = "_gnuplot.splot(_data)"
156 self.renderer.runString(evalString)
157
158 return
159
160 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26