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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 605 - (show annotations)
Mon Mar 20 07:16:27 2006 UTC (13 years, 7 months ago) by gross
File MIME type: text/x-python
File size: 4513 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: contour_plot.py,v 1.1 2005/11/30 04:29:53 paultcochrane Exp $
18
19 """
20 Class and functions associated with a pyvisi ContourPlot objects (gnuplot)
21 """
22
23 # generic imports
24 from common import debugMsg
25 import copy
26
27 # module specific imports
28 from plot import Plot
29
30 __revision__ = '$Revision: 1.1 $'
31
32 class ContourPlot(Plot):
33 """
34 Contour plot
35 """
36 def __init__(self, scene):
37 """
38 Initialisation of ContourPlot class
39
40 @param scene: the scene with which to associate the ContourPlot
41 @type scene: Scene object
42 """
43 debugMsg("Called ContourPlot.__init__()")
44 Plot.__init__(self, scene)
45
46 self.renderer = scene.renderer
47
48 self.title = None
49 self.xlabel = None
50 self.ylabel = None
51 self.zlabel = None # may need, or may not
52
53 self.linestyle = None # pyvisi-defined linestyle
54 self._linestyle = None # renderer-specific linestyle
55
56 # now add the plot to the scene
57 scene.add(self)
58
59 def setData(self, *dataList):
60 """
61 Sets the data to the Plot
62
63 @param dataList: list of data objects to plot
64 @type dataList: tuple
65 """
66 debugMsg("Called ContourPlot.setData()")
67
68 self.renderer.runString("# ContourPlot.setData()")
69
70 # this is a really dodgy way to get the data into the renderer
71 # I really have to find a better, more elegant way to do this
72
73 # for the moment, make sure that there are three arrays
74 if len(dataList) != 3:
75 raise ValueError, "Must have three arrays as input (at present)"
76
77 # do some sanity checks on the data
78 xData = dataList[0]
79 yData = dataList[1]
80 zData = dataList[2]
81
82 if len(xData.shape) != 1:
83 raise ValueError, "x data array is not of correct shape: %s" % \
84 xData.shape
85
86 if len(yData.shape) != 1:
87 raise ValueError, "y data array is not of correct shape: %s" % \
88 yData.shape
89
90 if len(zData.shape) != 2:
91 raise ValueError, "z data array is not of correct shape: %s" % \
92 zData.shape
93
94 ## the x data
95 self.renderer.renderDict['_x'] = copy.deepcopy(xData)
96
97 ## the y data
98 self.renderer.renderDict['_y'] = copy.deepcopy(yData)
99
100 ## the z data
101 self.renderer.renderDict['_z'] = copy.deepcopy(zData)
102
103 self.renderer.runString(\
104 "_data = Gnuplot.GridData(_z, _x, _y, binary=1)")
105
106 return
107
108 def render(self):
109 """
110 Does ContourPlot object specific rendering stuff
111 """
112 debugMsg("Called ContourPlot.render()")
113
114 self.renderer.runString("# ContourPlot.render()")
115 self.renderer.runString("_gnuplot('set contour base')")
116 self.renderer.runString("_gnuplot('set view 0, 0, 1, 1')")
117 self.renderer.runString("_gnuplot('set nosurface')") # gnuplot 3.7
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 self.renderer.runString("_gnuplot('set pm3d')")
135
136 # set up the evalString to use for plotting
137 evalString = "_gnuplot.splot(_data)"
138 self.renderer.runString(evalString)
139
140 return
141
142
143 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26