1 |
""" |
2 |
Base class and functions associated with a pyvisi Plot objects |
3 |
|
4 |
@var __author__: name of author |
5 |
@var __license__: licence agreement |
6 |
@var __copyright__: copyrights |
7 |
@var __url__: url entry point on documentation |
8 |
@var __version__: version |
9 |
@var __date__: date of the version |
10 |
""" |
11 |
|
12 |
__copyright__=""" Copyright (c) 2006 by ACcESS MNRF |
13 |
http://www.access.edu.au |
14 |
Primary Business: Queensland, Australia""" |
15 |
__license__="""Licensed under the Open Software License version 3.0 |
16 |
http://www.opensource.org/licenses/osl-3.0.php""" |
17 |
__author__="Paul Cochrane" |
18 |
__url__="http://www.iservo.edu.au/esys" |
19 |
__version__="$Revision$" |
20 |
__date__="$Date$" |
21 |
|
22 |
# generic imports |
23 |
from common import debugMsg, overrideWarning |
24 |
from item import Item |
25 |
|
26 |
class Plot(Item): |
27 |
""" |
28 |
Abstract plot class |
29 |
|
30 |
This is the abstract base class of all Plot objects. Renderer |
31 |
modules must inherit and override the methods defined here. |
32 |
""" |
33 |
def __init__(self, scene): |
34 |
""" |
35 |
Initialisation of abstract Plot class |
36 |
|
37 |
@param scene: the scene with which to associate the Plot |
38 |
@type scene: Scene object |
39 |
""" |
40 |
Item.__init__(self) |
41 |
debugMsg("Called Plot.__init__()") |
42 |
|
43 |
if scene is None: |
44 |
raise ValueError, "You must specify a scene object" |
45 |
|
46 |
self.title = None |
47 |
self.xlabel = None |
48 |
self.ylabel = None |
49 |
self.zlabel = None |
50 |
|
51 |
def setData(self, *dataList): |
52 |
""" |
53 |
Set data to Plot |
54 |
|
55 |
@param dataList: the data to set to the plot |
56 |
@type dataList: tuple |
57 |
""" |
58 |
debugMsg("Called setData() in Plot()") |
59 |
|
60 |
if dataList is None: |
61 |
raise ValueError, "You must specify a data list" |
62 |
|
63 |
# print a warning message if get to here |
64 |
overrideWarning("Plot.setData") |
65 |
|
66 |
return |
67 |
|
68 |
def setTitle(self, title): |
69 |
""" |
70 |
Set the plot title |
71 |
|
72 |
@param title: the string holding the title to the plot |
73 |
@type title: string |
74 |
""" |
75 |
debugMsg("Called Plot.setTitle()") |
76 |
|
77 |
self.title = title |
78 |
|
79 |
return |
80 |
|
81 |
def setXLabel(self, label): |
82 |
""" |
83 |
Set the label of the x-axis |
84 |
|
85 |
@param label: the string holding the label of the x-axis |
86 |
@type label: string |
87 |
""" |
88 |
debugMsg("Called Plot.setXLabel()") |
89 |
|
90 |
self.xlabel = label |
91 |
|
92 |
return |
93 |
|
94 |
def setYLabel(self, label): |
95 |
""" |
96 |
Set the label of the y-axis |
97 |
|
98 |
@param label: the string holding the label of the y-axis |
99 |
@type label: string |
100 |
""" |
101 |
debugMsg("Called Plot.setYLabel()") |
102 |
|
103 |
self.ylabel = label |
104 |
|
105 |
return |
106 |
|
107 |
def setZLabel(self, label): |
108 |
""" |
109 |
Set the label of the z-axis |
110 |
|
111 |
@param label: the string holding the label of the z-axis |
112 |
@type label: string |
113 |
""" |
114 |
debugMsg("Called Plot.setZLabel()") |
115 |
|
116 |
self.zlabel = label |
117 |
|
118 |
return |
119 |
|
120 |
def setLabel(self, axis, label): |
121 |
""" |
122 |
Set the label of a given axis |
123 |
|
124 |
@param axis: string (Axis object maybe??) of the axis (e.g. x, y, z,) |
125 |
@type axis: string or Axis object |
126 |
|
127 |
@param label: string of the label to set for the axis |
128 |
@type label: string |
129 |
""" |
130 |
debugMsg("Called Plot.setLabel()") |
131 |
|
132 |
# string-wise implementation |
133 |
if axis == 'x' or axis == 'X': |
134 |
self.xlabel = label |
135 |
elif axis == 'y' or axis == 'Y': |
136 |
self.ylabel = label |
137 |
elif axis == 'z' or axis == 'Z': |
138 |
self.zlabel = label |
139 |
else: |
140 |
raise ValueError, "axis must be x or y or z" |
141 |
|
142 |
return |
143 |
|
144 |
class ArrowPlot(Plot): |
145 |
""" |
146 |
Arrow field plot |
147 |
|
148 |
This is the abstract base class of all ArrowPlot objects. Renderer |
149 |
modules must inherit and override the methods defined here. |
150 |
""" |
151 |
def __init__(self, scene): |
152 |
""" |
153 |
Initialisation of ArrowPlot class |
154 |
|
155 |
@param scene: the scene with which to associate the ArrowPlot |
156 |
@type scene: Scene object |
157 |
""" |
158 |
Plot.__init__(self, scene) |
159 |
debugMsg("Called ArrowPlot.__init__()") |
160 |
|
161 |
if scene is None: |
162 |
raise ValueError, "You must specify a scene object" |
163 |
|
164 |
def setData(self, *dataList): |
165 |
""" |
166 |
Set data to ArrowPlot |
167 |
|
168 |
@param dataList: the data to set to the plot |
169 |
@type dataList: tuple |
170 |
""" |
171 |
debugMsg("Called setData() in ArrowPlot()") |
172 |
|
173 |
if dataList is None: |
174 |
raise ValueError, "You must specify a data list" |
175 |
|
176 |
# print a warning message if get to here |
177 |
overrideWarning("ArrowPlot.setData") |
178 |
|
179 |
return |
180 |
|
181 |
class BallPlot(Plot): |
182 |
""" |
183 |
Ball plot |
184 |
|
185 |
This is the abstract base class of all BallPlot objects. Renderer |
186 |
modules must inherit and override the methods defined here. |
187 |
""" |
188 |
def __init__(self, scene): |
189 |
""" |
190 |
Initialisation of BallPlot class |
191 |
|
192 |
@param scene: the scene with which to associate the BallPlot |
193 |
@type scene: Scene object |
194 |
""" |
195 |
Plot.__init__(self, scene) |
196 |
debugMsg("Called BallPlot.__init__()") |
197 |
|
198 |
if scene is None: |
199 |
raise ValueError, "You must specify a scene object" |
200 |
|
201 |
def setData(self, *dataList): |
202 |
""" |
203 |
Set data to BallPlot |
204 |
|
205 |
@param dataList: the data to set to the plot |
206 |
@type dataList: tuple |
207 |
""" |
208 |
debugMsg("Called setData() in BallPlot()") |
209 |
|
210 |
if dataList is None: |
211 |
raise ValueError, "You must specify a data list" |
212 |
|
213 |
# print a warning message if get to here |
214 |
overrideWarning("BallPlot.setData") |
215 |
|
216 |
return |
217 |
|
218 |
class ContourPlot(Plot): |
219 |
""" |
220 |
Contour plot |
221 |
|
222 |
This is the abstract base class of all ContourPlot objects. Renderer |
223 |
modules must inherit and override the methods defined here. |
224 |
""" |
225 |
def __init__(self, scene): |
226 |
""" |
227 |
Initialisation of ContourPlot class |
228 |
|
229 |
@param scene: the scene with which to associate the ContourPlot |
230 |
@type scene: Scene object |
231 |
""" |
232 |
Plot.__init__(self, scene) |
233 |
debugMsg("Called ContourPlot.__init__()") |
234 |
|
235 |
if scene is None: |
236 |
raise ValueError, "You must specify a scene object" |
237 |
|
238 |
def setData(self, *dataList): |
239 |
""" |
240 |
Set data to ContourPlot |
241 |
|
242 |
@param dataList: the data to set to the plot |
243 |
@type dataList: tuple |
244 |
""" |
245 |
debugMsg("Called setData() in ContourPlot()") |
246 |
|
247 |
if dataList is None: |
248 |
raise ValueError, "You must specify a data list" |
249 |
|
250 |
# print a warning message if get to here |
251 |
overrideWarning("ContourPlot.setData") |
252 |
|
253 |
return |
254 |
|
255 |
class EllipsoidPlot(Plot): |
256 |
""" |
257 |
Ellipsoid plot |
258 |
|
259 |
This is the abstract base class of all EllipsoidPlot objects. Renderer |
260 |
modules must inherit and override the methods defined here. |
261 |
""" |
262 |
def __init__(self, scene): |
263 |
""" |
264 |
Initialisation of EllipsoidPlot class |
265 |
|
266 |
@param scene: the scene with which to associate the EllipsoidPlot |
267 |
@type scene: Scene object |
268 |
""" |
269 |
Plot.__init__(self, scene) |
270 |
debugMsg("Called EllipsoidPlot.__init__()") |
271 |
|
272 |
if scene is None: |
273 |
raise ValueError, "You must specify a scene object" |
274 |
|
275 |
def setData(self, *dataList): |
276 |
""" |
277 |
Set data to EllipsoidPlot |
278 |
|
279 |
@param dataList: the data to set to the plot |
280 |
@type dataList: tuple |
281 |
""" |
282 |
debugMsg("Called setData() in EllipsoidPlot()") |
283 |
|
284 |
if dataList is None: |
285 |
raise ValueError, "You must specify a data list" |
286 |
|
287 |
# print a warning message if get to here |
288 |
overrideWarning("EllipsoidPlot.setData") |
289 |
|
290 |
return |
291 |
|
292 |
class IsosurfacePlot(Plot): |
293 |
""" |
294 |
Isosurface plot |
295 |
|
296 |
This is the abstract base class of all IsosurfacePlot objects. Renderer |
297 |
modules must inherit and override the methods defined here. |
298 |
""" |
299 |
def __init__(self, scene): |
300 |
""" |
301 |
Initialisation of IsosurfacePlot class |
302 |
|
303 |
@param scene: the scene with which to associate the IsosurfacePlot |
304 |
@type scene: Scene object |
305 |
""" |
306 |
Plot.__init__(self, scene) |
307 |
debugMsg("Called IsosurfacePlot.__init__()") |
308 |
|
309 |
if scene is None: |
310 |
raise ValueError, "You must specify a scene object" |
311 |
|
312 |
def setData(self, *dataList): |
313 |
""" |
314 |
Set data to IsosurfacePlot |
315 |
|
316 |
@param dataList: the data to set to the plot |
317 |
@type dataList: tuple |
318 |
""" |
319 |
debugMsg("Called setData() in IsosurfacePlot()") |
320 |
|
321 |
if dataList is None: |
322 |
raise ValueError, "You must specify a data list" |
323 |
|
324 |
# print a warning message if get to here |
325 |
overrideWarning("IsosurfacePlot.setData") |
326 |
|
327 |
return |
328 |
|
329 |
class LinePlot(Plot): |
330 |
""" |
331 |
Line plot |
332 |
|
333 |
This is the abstract base class of all LinePlot objects. Renderer |
334 |
modules must inherit and override the methods defined here. |
335 |
""" |
336 |
def __init__(self, scene): |
337 |
""" |
338 |
Initialisation of LinePlot class |
339 |
|
340 |
@param scene: the scene with which to associate the LinePlot |
341 |
@type scene: Scene object |
342 |
""" |
343 |
Plot.__init__(self, scene) |
344 |
debugMsg("Called LinePlot.__init__()") |
345 |
|
346 |
self.renderer = scene.renderer |
347 |
|
348 |
if scene is None: |
349 |
raise ValueError, "You must specify a scene object" |
350 |
|
351 |
self.title = None |
352 |
self.xlabel = None |
353 |
self.ylabel = None |
354 |
self.zlabel = None |
355 |
|
356 |
self.linestyle = None # pyvisi-defined linestyle |
357 |
self._linestyle = None # renderer-specific linestyle |
358 |
|
359 |
def setData(self, *dataList): |
360 |
""" |
361 |
Sets the data to the given plot object. |
362 |
|
363 |
@param dataList: list of data objects to plot |
364 |
@type dataList: tuple |
365 |
""" |
366 |
debugMsg("Called setData() in LinePlot()") |
367 |
|
368 |
if dataList is None: |
369 |
raise ValueError, "You must specify a data list" |
370 |
|
371 |
# print a warning message if get to here |
372 |
overrideWarning("LinePlot.setData") |
373 |
|
374 |
return |
375 |
|
376 |
def render(self): |
377 |
""" |
378 |
Does LinePlot object specific (pre) rendering stuff |
379 |
""" |
380 |
debugMsg("Called LinePlot.render()") |
381 |
|
382 |
# print a warning message if get to here |
383 |
overrideWarning("LinePlot.render") |
384 |
|
385 |
return |
386 |
|
387 |
def setLineStyle(self, linestyle): |
388 |
""" |
389 |
Sets the linestyle of the LinePlot |
390 |
|
391 |
Linestyles may be either a word in the Gnuplot style, or a symbol |
392 |
shortcut in the Matlab style. Some of the options do not have a |
393 |
Matlab equivalent but do have a Gnuplot equivalent, or vice versa. |
394 |
|
395 |
What this method does, is take the linestyles possible as defined by |
396 |
PyVisi, and then does some conversion as best it can to get the |
397 |
relevant output from (in this case) gnuplot. |
398 |
|
399 |
Possible linestyles are: |
400 |
1. lines ('-') |
401 |
2. points ('o') |
402 |
3. linespoints ('-o') |
403 |
4. dots ('.') |
404 |
5. dotted (':') |
405 |
6. dashes ('--') |
406 |
7. dotdashes ('-.') |
407 |
|
408 |
@param linestyle: the style to use for the lines |
409 |
@type linestyle: string |
410 |
""" |
411 |
debugMsg("Called LinePlot.setLineStyle()") |
412 |
|
413 |
self.linestyle = linestyle |
414 |
|
415 |
# print a warning if get to here |
416 |
overrideWarning("LinePlot.setLineStyle") |
417 |
|
418 |
return |
419 |
|
420 |
def getLineStyle(self): |
421 |
""" |
422 |
Gets the current linestyle of the LinePlot |
423 |
|
424 |
@return: the linestyle as a string |
425 |
""" |
426 |
debugMsg("Called LinePlot.getLineStyle()") |
427 |
|
428 |
return self.linestyle |
429 |
|
430 |
class ScatterPlot(Plot): |
431 |
""" |
432 |
Scatter plot |
433 |
|
434 |
This is the abstract base class of all ScatterPlot objects. Renderer |
435 |
modules must inherit and override the methods defined here. |
436 |
""" |
437 |
def __init__(self, scene): |
438 |
""" |
439 |
Initialisation of ScatterPlot class |
440 |
|
441 |
@param scene: the scene with which to associate the ScatterPlot |
442 |
@type scene: Scene object |
443 |
""" |
444 |
Plot.__init__(self, scene) |
445 |
debugMsg("Called ScatterPlot.__init__()") |
446 |
|
447 |
if scene is None: |
448 |
raise ValueError, "You must specify a scene object" |
449 |
|
450 |
def setData(self, *dataList): |
451 |
""" |
452 |
Set data to ScatterPlot |
453 |
|
454 |
@param dataList: the data to set to the plot |
455 |
@type dataList: tuple |
456 |
""" |
457 |
debugMsg("Called ScatterPlot.setData()") |
458 |
|
459 |
if dataList is None: |
460 |
raise ValueError, "You must specify a data list" |
461 |
|
462 |
# print a warning message if get to here |
463 |
overrideWarning("ScatterPlot.setData") |
464 |
|
465 |
return |
466 |
|
467 |
class ScatterPlot3D(Plot): |
468 |
""" |
469 |
Three dimensional scatter plot |
470 |
|
471 |
This is the abstract base class of all ScatterPlot3D objects. Renderer |
472 |
modules must inherit and override the methods defined here. |
473 |
""" |
474 |
|
475 |
def __init__(self, scene): |
476 |
""" |
477 |
Intialisation of ScatterPlot3D class |
478 |
|
479 |
@param scene: the scene with which to associate the ScatterPlot3D |
480 |
@type scene: Scene object |
481 |
""" |
482 |
debugMsg("Called ScatterPlot3D.__init__()") |
483 |
Plot.__init__(self, scene) |
484 |
|
485 |
if scene is None: |
486 |
raise ValueError, "You must specify a scene object" |
487 |
|
488 |
def setData(self, *dataList): |
489 |
""" |
490 |
Set data to a ScatterPlot3D |
491 |
|
492 |
@param dataList: the data to set to the plot |
493 |
@type dataList: tuple |
494 |
""" |
495 |
debugMsg("Called ScatterPlot3D.setData()") |
496 |
|
497 |
if dataList is None: |
498 |
raise ValueError, "You must specify a data list" |
499 |
|
500 |
# print a warning message if get to here |
501 |
overrideWarning("ScatterPlot3D.setData") |
502 |
|
503 |
return |
504 |
|
505 |
def render(self): |
506 |
""" |
507 |
Perform ScatterPlot3D specific rendering stuff |
508 |
""" |
509 |
debugMsg("Called ScatterPlot3D.render()") |
510 |
|
511 |
# print a warning message if get to here |
512 |
overrideWarning("ScatterPlot3D.render") |
513 |
|
514 |
return |
515 |
|
516 |
class SurfacePlot(Plot): |
517 |
""" |
518 |
Surface plot |
519 |
|
520 |
This is the abstract base class of all SurfacePlot objects. Renderer |
521 |
modules must inherit and override the methods defined here. |
522 |
""" |
523 |
|
524 |
def __init__(self, scene): |
525 |
""" |
526 |
Intialisation of SurfacePlot class |
527 |
|
528 |
@param scene: the scene with which to associate the SurfacePlot |
529 |
@type scene: Scene object |
530 |
""" |
531 |
debugMsg("Called SurfacePlot.__init__()") |
532 |
Plot.__init__(self, scene) |
533 |
|
534 |
if scene is None: |
535 |
raise ValueError, "You must specify a scene object" |
536 |
|
537 |
def setData(self, *dataList): |
538 |
""" |
539 |
Set data to a SurfacePlot |
540 |
|
541 |
@param dataList: the data to set to the plot |
542 |
@type dataList: tuple |
543 |
""" |
544 |
debugMsg("Called SufracePlot.setData()") |
545 |
|
546 |
if dataList is None: |
547 |
raise ValueError, "You must specify a data list" |
548 |
|
549 |
# print a warning message if get to here |
550 |
overrideWarning("SurfacePlot.setData") |
551 |
|
552 |
return |
553 |
|
554 |
def render(self): |
555 |
""" |
556 |
Perform SurfacePlot specific rendering stuff |
557 |
""" |
558 |
debugMsg("Called SurfacePlot.render()") |
559 |
|
560 |
# print a warning message if get to here |
561 |
overrideWarning("SurfacePlot.render") |
562 |
|
563 |
return |
564 |
|
565 |
# vim: expandtab shiftwidth=4: |
566 |
|