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

Contents of /trunk/pyvisi/py_src/renderers/gnuplot/scatter_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: 5407 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: scatter_plot.py,v 1.1 2005/11/30 04:29:53 paultcochrane Exp $
18
19 """
20 Class and functions associated with a pyvisi ScatterPlot 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 ScatterPlot(Plot):
33 """
34 Scatter plot
35
36 Plots a scatter data points in 2D, for 3D scatter plots use ScatterPlot3D
37 """
38
39 def __init__(self, scene):
40 """
41 Initialisation of ScatterPlot class
42
43 @param scene: the scene with which to associate the ScatterPlot
44 @type scene: Scene object
45 """
46 debugMsg("Called ScatterPlot.__init__()")
47 Plot.__init__(self, scene)
48
49 # grab the renderer
50 self.renderer = scene.renderer
51
52 # set up some of the attributes
53 self.title = None
54 self.xlabel = None
55 self.ylabel = None
56 self.zlabel = None
57
58 # now add the object to the scene
59 scene.add(self)
60
61 def setData(self, *dataList):
62 """
63 Sets the data to the given plot object.
64
65 @param dataList: list of data objects to plot
66 @type dataList: tuple
67 """
68 debugMsg("Called setData() in ScatterPlot()")
69
70 self.renderer.runString("# ScatterPlot.setData()")
71
72 # do some sanity checking on the data
73 for i in range(len(dataList)):
74 if len(dataList[0]) != len(dataList[i]):
75 raise ValueError, "Input vectors must all be the same length"
76
77 # if have more than one array to plot the first one is the x data
78 if len(dataList) > 1:
79 xData = dataList[0]
80 ## pass around the x data
81 self.renderer.renderDict['_x'] = copy.deepcopy(xData)
82 # don't need the first element of the dataList so get rid of it
83 dataList = dataList[1:]
84 # if only have one array input, then autogenerate the xData
85 elif len(dataList) == 1:
86 xData = range(1, len(dataList[0])+1)
87 if len(xData) != len(dataList[0]):
88 errorString = "Autogenerated xData array length not "
89 errorString += "equal to input array length"
90 raise ValueError, errorString
91
92 ## pass around the x data
93 self.renderer.renderDict['_x'] = copy.deepcopy(xData)
94
95 # range over the data, printing what the expansion of the array is
96 # and regenerate the data within the eval
97 for i in range(len(dataList)):
98 yDataVar = "_y%d" % i
99 data = dataList[i]
100 # check that the data here is a 1-D array
101 if len(data.shape) != 1:
102 raise ValueError, "Can only handle 1D arrays at present"
103
104 self.renderer.renderDict[yDataVar] = copy.deepcopy(data)
105
106 evalString = "_data%d = Gnuplot.Data(_x, " % i
107 evalString += "_y%d" % i
108
109 # this is the linestyle that makes this a scatter plot
110 evalString += ", with='points pointtype 2'"
111
112 # finish off the evalString
113 evalString += ")"
114
115 # and add it to the evalstack
116 self.renderer.runString(evalString)
117
118 # return the number of objects to plot
119 self.renderer.numDataObjects = len(dataList)
120
121 return
122
123 def render(self):
124 """
125 Does ScatterPlot object specific rendering stuff
126 """
127 debugMsg("Called ScatterPlot.render()")
128
129 self.renderer.runString("# ScatterPlot.render()")
130
131 # if a title is set, put it here
132 if self.title is not None:
133 evalString = "_gnuplot.title(\'%s\')" % self.title
134 self.renderer.runString(evalString)
135
136 # if an xlabel is set, add it
137 if self.xlabel is not None:
138 evalString = "_gnuplot.xlabel(\'%s\')" % self.xlabel
139 self.renderer.runString(evalString)
140
141 # if a ylabel is set, add it
142 if self.ylabel is not None:
143 evalString = "_gnuplot.ylabel(\'%s\')" % self.ylabel
144 self.renderer.runString(evalString)
145
146 # if a zlabel is set, add it
147 if self.zlabel is not None:
148 evalString = "_gnuplot('set zlabel \\'%s\\'')" % self.zlabel
149 self.renderer.runString(evalString)
150
151 # set up the evalString to use for plotting
152 evalString = "_gnuplot.plot("
153 for i in range(self.renderer.numDataObjects-1):
154 evalString += "_data%d, " % i
155 evalString += "_data%d)" % (self.renderer.numDataObjects-1,)
156 self.renderer.runString(evalString)
157
158 return
159
160
161 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26