source: branches/casa-release-4_3-test/python/plotter2.py@ 3117

Last change on this file since 3117 was 2909, checked in by WataruKawasaki, 10 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes:

Module(s): sd

Description: (1) a bug fix in sd.scantable.parse_spw_selection(). modified to get rest frequency value correctly based on molecule ID stored for each spw (the first spectrum having the specified spw in scantable). (2) renamed 'annotation' to 'text' in class or variable names for sd.plotter2.


File size: 34.7 KB
Line 
1from os.path import expanduser, expandvars
2from asap._asap import Plotter2
3
4class plotter2:
5 def __init__(self):
6 self._plotter = Plotter2()
7 self.current_vs_unit = 'cm'
8
9 def set_output(self, filename=None, dev=None):
10 """\
11 set output filename and/or output device.
12 when only filename given, filename is splitted with '.' then
13 the last part (filename extension) will be used as output device.
14 Parameters:
15 filename: output file name (default is '')
16 device: output device. default is 'xwindow'. 'png', 'ps'
17 and 'vps'(PostScript in portrait shape) are
18 available also.
19
20 Example:
21 set_output() -- display in X Window (default)
22 set_output('foo.png') -- generate foo.png in PNG format.
23 set_output('bar.ps', 'vps') -- generate bar.ps in portrait shape.
24 """
25 if filename is None:
26 filename = ''
27 dev = 'xwindow'
28 else:
29 filename = filename.strip()
30 if filename == '':
31 dev = 'xwindow'
32 else:
33 if (dev is None) or (dev.strip() == ''):
34 fnamelem = filename.lower().split('.')
35 dev = fnamelem[len(fnamelem)-1].strip()
36 if dev == 'ps': dev = 'cps'
37
38 self._plotter.set_filename(expanduser(expandvars(filename)))
39 self._plotter.set_device(dev.strip())
40 self.device = dev.strip()
41
42 def get_vs(self):
43 """\
44 returns size and shape information on 'view surface' (a word used
45 in PGPLOT, meaning the entire region of plotting) as a dictionary.
46 """
47 width = self._plotter.get_viewsurface_width()
48 unit = self.current_vs_unit
49 if unit == 'cm':
50 width = width * 2.54 # inch to centimeter
51 elif unit == 'mm':
52 width = width * 25.4 # inch to millimeter
53 elif unit == 'pixel':
54 width = width * 85.0 + 1.0 # inch to pixel (plus correction for 1pixel)
55
56 aspect = self._plotter.get_viewsurface_aspect()
57
58 return {'width': width, 'unit': unit, 'aspect': aspect}
59
60 def set_vs(self, width=None, unit=None, aspect=None):
61 """\
62 set size and shape of 'view surface', namely, the entire region
63 of plotting including graphic window or output file. ('view
64 surface' is a word used in PGPLOT)
65 Parameters:
66 width: width of graphic window or output file.
67 unit: unit of width. default value is 'cm'. 'mm', 'inch'
68 and 'pixel' are also available.
69 aspect: aspect ratio (= height / width).
70
71 Example:
72 set_vs(width=10, unit='cm', aspect=1.0) -- set the output
73 window/file as a square 10cm on a side.
74 set_vs(width=400, unit='pixel', aspect=0.75) -- set the output
75 window/file as a rectangle with 400 pixels in width and
76 300 pixels in height.
77
78 Note:
79 setting unit to 'cm', 'mm' or 'inch' results in output with the
80 correct size when output device is X Window or PostScript, but
81 not for the other cases (png). also, setting unit to 'pixel'
82 works correctly only when output device is 'png': this arises
83 from PGPLOT's assumption on device resolution of 85 pixel/inch,
84 though actual resolution will vary depending on device type.
85 thus, for output with a correct size specified, users are
86 recommended to use 'pixel' for 'png' output, and other units
87 for 'xwindow' (the default) or PostScript output.
88 """
89 if width is None:
90 width = self._plotter.get_viewsurface_width() # inch
91 if self.current_vs_unit == 'cm':
92 width = width * 2.54 # inch to centimeter
93 elif self.current_vs_unit == 'mm':
94 width = width * 25.4 # inch to millimeter
95 elif self.current_vs_unit == 'pixel':
96 width = width * 85.0 + 1.0 # inch to pixel (plus correction for 1pixel)
97 if unit is None: unit = self.current_vs_unit
98 if aspect is None: aspect = self._plotter.get_viewsurface_aspect()
99
100 if not ((isinstance(width, int) or isinstance(width, float)) and (width > 0)):
101 raise ValueError("Width must be positive float or integer.")
102 if not (isinstance(aspect, int) or isinstance(aspect, float)):
103 raise ValueError("Aspect must be positive float or integer.")
104
105 unit = unit.lower().strip()
106 if unit == 'cm':
107 width = width / 2.54 # centimeter to inch
108 elif unit == 'mm':
109 width = width / 25.4 # millimeter to inch
110 elif unit == 'pixel':
111 width = (width - 1.0) / 85.0 # pixel to inch (plus correction for 1pixel)
112 elif unit != 'inch':
113 raise ValueError("Unit must be 'cm', 'mm', 'inch' or 'pixel'.")
114 self.current_vs_unit = unit
115
116 self._plotter.set_viewsurface(width, aspect)
117
118 def set_vp(self, xmin, xmax, ymin, ymax, id=None):
119 """\
120 change the position/shape of viewport in which data are to be plotted.
121 positions should be given in window coordinate (0<={x,y}<=1), but,
122 unlike the usual definition of window coordinates, with the origin at
123 the bottom left corner.
124 when you create plotter2 instance, it already has a single viewport
125 with xmin=ymin=0.1 and xmax=ymax=0.9 (id=0). in case you don't want to
126 change the size/position of the viewport, you never need to run this
127 function.
128 if you want to have two or more viewports, run set_vp() first to
129 move/resize the first viewport, then you will be able to add a new
130 viewport by executing set_vp without id (the id of the new viewport
131 is returned in this case). the location and shape of any viewport
132 can be modified later by specifying its viewport id.
133
134 Parameters:
135 xmin: the x position of the left side.
136 xmax: the x position of the rightt side.
137 ymin: the y position of the top of viewport.
138 ymax: the y position of the bottom of viewport.
139 id: viewport id
140 """
141 if id is None:
142 if self._plotter.get_hasdefaultvp():
143 self._plotter.set_viewport(xmin, xmax, ymin, ymax, 0)
144 else:
145 return self._plotter.add_viewport(xmin, xmax, ymin, ymax)
146 else:
147 self._plotter.set_viewport(xmin, xmax, ymin, ymax, id)
148
149 def show_vp(self, vpid=None):
150 """\
151 show viewport specified with its id.
152
153 Parameter:
154 vpid: viewport id. when unset, operation is applied to
155 the viewport with the largest id.
156 """
157 if vpid is None: vpid = -1
158 self._plotter.show_viewport(vpid)
159
160 def hide_vp(self, vpid=None):
161 """\
162 hide viewport specified with its id.
163
164 Parameter:
165 vpid: viewport id. when unset, operation is applied to
166 the viewport with the largest id.
167 """
168 if vpid is None: vpid = -1
169 self._plotter.hide_viewport(vpid)
170
171 def set_range(self, xmin, xmax, ymin, ymax, vpid=None):
172 """\
173 set 2D range to be displayed in the specified viewport.
174 by default, the display range is set automatically.
175
176 Parameter:
177 xmin: the minimum of x range.
178 xmax: the maximum of x range.
179 ymin: the minimum of y range.
180 ymax: the maximum of y range.
181 vpid: viewport id. when unset, operation is applied to
182 the viewport with the largest id.
183 """
184 if vpid is None: vpid = -1
185 self._plotter.set_range(xmin, xmax, ymin, ymax, vpid)
186
187 def set_xrange(self, xmin, xmax, vpid=None):
188 """\
189 set x range to be displayed in the specified viewport.
190 by default, the display range is set automatically.
191
192 Parameter:
193 xmin: the minimum of x range.
194 xmax: the maximum of x range.
195 vpid: viewport id. when unset, operation is applied to
196 the viewport with the largest id.
197 """
198 if vpid is None: vpid = -1
199 self._plotter.set_range_x(xmin, xmax, vpid)
200
201 def set_yrange(self, ymin, ymax, vpid=None):
202 """\
203 set y range to be displayed in the specified viewport.
204 by default, the display range is set automatically.
205
206 Parameter:
207 ymin: the minimum of y range.
208 ymax: the maximum of y range.
209 vpid: viewport id. when unset, operation is applied to
210 the viewport with the largest id.
211 """
212 if vpid is None: vpid = -1
213 self._plotter.set_range_y(ymin, ymax, vpid)
214
215 def get_xrange(self, vpid=None):
216 """\
217 returns x range of displayed region of the specified viewport
218 as a list of [xmin, xmax].
219
220 Parameter:
221 vpid: viewport id. when unset, operation is applied to
222 the viewport with the largest id.
223 """
224 if vpid is None: vpid = -1
225 return self._plotter.get_range_x(vpid)
226
227 def get_yrange(self, vpid=None):
228 """\
229 returns y range of displayed region in the specified viewport
230 as a list of [ymin, ymax].
231
232 Parameter:
233 vpid: viewport id. when unset, operation is applied to
234 the viewport with the largest id.
235 """
236 if vpid is None: vpid = -1
237 return self._plotter.get_range_y(vpid)
238
239 def set_autorange(self, vpid=None):
240 """\
241 set the 2-Dimensional range of displayed area of the specified
242 viewport to automatically enclose the given data.
243 the x range will be from the minimum up to the maximum value
244 of the given x values, whereas y range has margins of 10% of
245 the y value range both at the top and the bottom sides.
246
247 Parameter:
248 vpid: viewport id. when unset, operation is applied to
249 the viewport with the largest id.
250 """
251 if vpid is None: vpid = -1
252 self._plotter.set_autorange(vpid)
253
254 def set_xautorange(self, vpid=None):
255 """\
256 set x range of displayed area of the specified viewport to
257 automatically enclose the given data with no margins.
258
259 Parameter:
260 vpid: viewport id. when unset, operation is applied to
261 the viewport with the largest id.
262 """
263 if vpid is None: vpid = -1
264 self._plotter.set_autorange_x(vpid)
265
266 def set_yautorange(self, vpid=None):
267 """\
268 set y range of displayed area of the specified viewport to
269 automatically enclose the given data with margins of 10% of
270 the y value range both at the top and the bottom sides.
271
272 Parameter:
273 vpid: viewport id. when unset, operation is applied to
274 the viewport with the largest id.
275 """
276 if vpid is None: vpid = -1
277 self._plotter.set_autorange_y(vpid)
278
279 def set_fontsize(self, size, vpid=None):
280 """\
281 set the font size that is used for number labels etc.
282
283 Parameter:
284 size: font size (default is 1)
285 vpid: viewport id. when unset, operation is applied to
286 the viewport with the largest id.
287 """
288 if vpid is None: vpid = -1
289 self._plotter.set_fontsize(size, vpid)
290
291 def set_xtics(self, interval_major, num_minor=None, vpid=None):
292 """\
293 set the interval of ticks along x axis.
294
295 Parameter:
296 interval_major: interval of major ticks
297 num_minor: major tick interval / minor tick interval.
298 default is 5.
299 vpid: viewport id. when unset, operation is
300 applied to the viewport with the largest id.
301 """
302 if vpid is None: vpid = -1
303 if num_minor is None: num_minor = 5
304 self._plotter.set_tics_x(interval_major, num_minor, vpid)
305
306 def set_ytics(self, interval_major, num_minor=None, vpid=None):
307 """\
308 set the interval of ticks along y axis.
309
310 Parameter:
311 interval_major: interval of major ticks
312 num_minor: major tick interval / minor tick interval.
313 default is 5.
314 vpid: viewport id. when unset, operation is
315 applied to the viewport with the largest id.
316 """
317 if vpid is None: vpid = -1
318 if num_minor is None: num_minor = 5
319 self._plotter.set_tics_y(interval_major, num_minor, vpid)
320
321 def set_xautotics(self, vpid=None):
322 """\
323 set the interval of ticks and number labels along x axis
324 given automatically.
325
326 Parameter:
327 vpid: viewport id. when unset, operation is applied to
328 the viewport with the largest id.
329 """
330 if vpid is None: vpid = -1
331 self._plotter.set_autotics_x(vpid)
332
333 def set_yautotics(self, vpid=None):
334 """\
335 set the interval of ticks and number labels along y axis
336 given automatically.
337
338 Parameter:
339 vpid: viewport id. when unset, operation is applied to
340 the viewport with the largest id.
341 """
342 if vpid is None: vpid = -1
343 self._plotter.set_autotics_y(vpid)
344
345 def set_xnuminterval(self, interval, vpid=None):
346 """\
347 set the interval of number labels along x axis.
348
349 Parameter:
350 interval: interval of number labels
351 vpid: viewport id. when unset, operation is
352 applied to the viewport with the largest id.
353 """
354 if vpid is None: vpid = -1
355 self._plotter.set_ninterval_x(interval, vpid)
356
357 def set_ynuminterval(self, interval, vpid=None):
358 """\
359 set the interval of number labels along y axis.
360
361 Parameter:
362 interval: interval of number labels
363 vpid: viewport id. when unset, operation is
364 applied to the viewport with the largest id.
365 """
366 if vpid is None: vpid = -1
367 self._plotter.set_ninterval_y(interval, vpid)
368
369 def set_xnumlocation(self, location=None, vpid=None):
370 """\
371 set the location of number labels along x axis.
372
373 Parameters:
374 location: 'l' (left side) or 'r' (right side). default is 'l'.
375 vpid: viewport id. when unset, operation is
376 applied to the viewport with the largest id.
377 """
378 if vpid is None: vpid = -1
379 if location is None: location = "l"
380 self._plotter.set_nlocation_x(location.lower(), vpid)
381
382 def set_ynumlocation(self, location=None, vpid=None):
383 """\
384 set the location of number labels along y axis.
385
386 Parameters:
387 location: 'b' (bottom) or 't' (top). default is 'b'.
388 vpid: viewport id. when unset, operation is
389 applied to the viewport with the largest id.
390 """
391 if vpid is None: vpid = -1
392 if location is None: location = "b"
393 self._plotter.set_nlocation_y(location.lower(), vpid)
394
395 def set_data(self, xdata, ydata, vpid=None, dataid=None):
396 """\
397 append or change dataset to be plotted.
398
399 Parameters:
400 xdata: a list of x positions of the input data.
401 ydata: a list of y positions of the input data.
402 vpid: viewport id. when not given, the last viewport
403 will be the target.
404 dataid: dataset id. a integer starting from 0. when dataid
405 is given, the corresponding dataset of the specified
406 viewport is replaced by the given xdata and ydata.
407 when not given, a new dataset of xdata and ydata is
408 appended.
409 """
410 if dataid is None:
411 if vpid is None: vpid = -1
412 dataid = -1
413
414 self._plotter.set_data(xdata, ydata, vpid, dataid)
415
416 def set_line(self, color, width=None, style=None, vpid=None, dataid=None):
417 """\
418 change line attributes.
419
420 Parameters:
421 color: line color specified by color name. available colors
422 can be listed via list_colornames().
423 width: line width. default is 1.
424 style: line style. available styles can be listed via
425 list_linestyles().
426 vpid: viewport id. when not given, the last viewport
427 will be the target of operation.
428 dataid: dataset id. when not given, the last dataset for the
429 specified viewport is the target.
430 """
431 if width is None: width = 1
432 if style is None: style = "solid"
433 if vpid is None: vpid = -1
434 if dataid is None: dataid = -1
435
436 coloridx = self.get_colorindex(color)
437 styleidx = self.get_linestyleindex(style)
438 self._plotter.set_line(coloridx, width, styleidx, vpid, dataid)
439
440 def show_line(self, vpid=None, dataid=None):
441 """\
442 show line connecting the specified dataset.
443
444 Parameters:
445 vpid: viewport id. when not given, the last viewport
446 will be the target.
447 dataid: dataset id. when not given, the last dataset used.
448 """
449 if dataid is None:
450 if vpid is None: vpid = -1
451 dataid = -1
452
453 self._plotter.show_line(vpid, dataid)
454
455 def hide_line(self, vpid=None, dataid=None):
456 """\
457 hide line connecting the specified dataset.
458
459 Parameters:
460 vpid: viewport id. when not given, the last viewport
461 will be the target.
462 dataid: dataset id. when not given, the last dataset used.
463 """
464 if dataid is None:
465 if vpid is None: vpid = -1
466 dataid = -1
467
468 self._plotter.hide_line(vpid, dataid)
469
470 def set_point(self, type, size, color, vpid=None, dataid=None):
471 """\
472 change marker attributes for the specified dataset.
473
474 Parameters:
475 type: type of marker symbol. see PGPLOT manual for detail.
476 size: marker size.
477 color: color of marker. see output of list_colornames().
478 vpid: viewport id. when not given, the last viewport
479 will be the target.
480 dataid: dataset id. when not given, the last dataset used.
481 """
482 if dataid is None:
483 if vpid is None: vpid = -1
484 dataid = -1
485 coloridx = self.get_colorindex(color)
486 self._plotter.set_point(type, size, coloridx, vpid, dataid)
487
488 def show_point(self, vpid=None, dataid=None):
489 """\
490 show markers for the specified dataset.
491
492 Parameters:
493 vpid: viewport id. when not given, the last viewport
494 will be the target.
495 dataid: dataset id. when not given, the last dataset used.
496 """
497 if dataid is None:
498 if vpid is None: vpid = -1
499 dataid = -1
500
501 self._plotter.show_point(vpid, dataid)
502
503 def hide_point(self, vpid=None, dataid=None):
504 """\
505 hide markers for the specified dataset.
506
507 Parameters:
508 vpid: viewport id. when not given, the last viewport
509 will be the target.
510 dataid: dataset id. when not given, the last dataset used.
511 """
512 if dataid is None:
513 if vpid is None: vpid = -1
514 dataid = -1
515
516 self._plotter.hide_point(vpid, dataid)
517
518 def set_xmask(self, xmin, xmax, color=None, fstyle=None, width=None, hsep=None, vpid=None):
519 """\
520 add a rectangle which spans the full y range.
521
522 Parameters:
523 xmin: the smaller end of mask region
524 xmax: the larger end of mask region
525 color: color of mask region. see output of list_colornames().
526 default is "lightgray".
527 fstyle: fill style. see output of list_fillstyles().
528 default is "solid".
529 width: width of outline of mask region. default is 1.
530 hsep: spacing of hatched lines. default is 1.0
531 vpid: viewport id. when not given, the last viewport
532 will be the target.
533 """
534 if color is None: color = "lightgray"
535 if fstyle is None: fstyle = "solid"
536 if width is None: width = 1
537 if hsep is None: hsep = 1.0
538 if vpid is None: vpid = -1
539
540 coloridx = self.get_colorindex(color)
541 fstyleidx = self.get_fillstyleindex(fstyle)
542
543 self._plotter.set_mask_x(xmin, xmax, coloridx, fstyleidx, width, hsep, vpid)
544
545 def set_arrow(self, xtail, xhead, ytail, yhead, color=None, width=None, linestyle=None, headsize=None, headfs=None, headangle=None, headvent=None, vpid=None, arrowid=None):
546 """\
547 draw an arrow or change existing arrow attributes.
548
549 Parameters:
550 xtail: x position of arrow tail
551 xhead: x position of arrow head
552 ytail: y position of arrow tail
553 yhead: y position of arrow head
554 color: color of arrow. see output of list_colornames().
555 default is "black".
556 width: width of arrow line and outline of arrow head.
557 default is 1.
558 linestyle: line style. available styles can be listed via
559 list_linestyles().
560 headsize: size of arrow head. default is 1.0.
561 headfs: fill style of arrow head. see output of
562 list_arrowheadfillstyles(). default is "solid".
563 headangle: acute angle of arrow head in unit of degree.
564 default is 45.0.
565 headvent: fraction of the triangular arrow-head that is
566 cut away from the back. 0.0 gives a triangular
567 wedge arrow head while 1.0 gives an open
568 '>'-shaped one. default is 0.3.
569 vpid: viewport id. when not given, the last viewport
570 will be the target.
571 arrowid: arrow id. when not given, the arrow having the
572 final arrow id for the specified viewport will
573 be the target.
574 """
575 if color is None: color = "black"
576 if width is None: width = 1
577 if linestyle is None: linestyle = "solid"
578 if headsize is None: headsize = 1.0
579 if headfs is None: headfs = "solid"
580 if headangle is None: headangle = 45.0
581 if headvent is None: headvent = 0.3
582 if vpid is None: vpid = -1
583 if arrowid is None: arrowid = -1
584
585 coloridx = self.get_colorindex(color)
586 linestyleidx = self.get_linestyleindex(linestyle)
587 headfsidx = self.get_arrowheadfillstyleindex(headfs)
588
589 self._plotter.set_arrow(xtail, xhead, ytail, yhead, coloridx, width, linestyleidx, headsize, headfsidx, headangle, headvent, vpid, arrowid)
590
591 def set_text(self, text, posx=None, posy=None, angle=None, fjust=None, size=None, style=None, color=None, bgcolor=None, vpid=None, textid=None):
592 """\
593 write text string or change existing text attributes.
594
595 Parameters:
596 text: text string.
597 posx: x position of text in world coordinate.
598 default is center of x axis.
599 posy: y position of text in world coordinate.
600 default is center of y axis.
601 angle: rotation angle of text in unit of degree.
602 0.0 (default) is horizontal.
603 fjust: horizontal justification of text string. if 0.0
604 (default) is given, the text is left-justified at
605 (posx, posy). if 0.5, the text is centered, and if
606 1.0, the text is right-justified.
607 size: size of text string. the default is 1.0.
608 style: font style. "normal", "roman", "italic" and "script"
609 are available. default is "normal".
610 color: color of text. see output of list_colornames().
611 default is "black".
612 bgcolor: background color of text. see output of
613 list_colornames(). default is transparent(-1).
614 vpid: viewport id. when not given, the last viewport will
615 be the target.
616 textid: text id independently defined for each viewport.
617 when not given, the text having the final text id
618 for the specified viewport will be the target.
619 """
620 if posx is None: posx = -1.0
621 if posy is None: posy = -1.0
622 if angle is None: angle = 0.0
623 if fjust is None: fjust = 0.0
624 if size is None: size = 1.0
625 if style is None: style = ""
626 if color is None: color = "black"
627 if bgcolor is None: bgcolor = "" # transparent
628 if vpid is None: vpid = -1
629 if textid is None: textid = -1
630
631 coloridx = self.get_colorindex(color)
632 bgcoloridx = self.get_colorindex(bgcolor) if (bgcolor.strip() != "") else -1 #bgcolor
633
634 self._plotter.set_text(text, posx, posy, angle, fjust, size, style, coloridx, bgcoloridx, vpid, textid)
635
636 def set_xlabel(self, label, style=None, size=None, posx=None, posy=None, vpid=None):
637 """\
638 set label string along x axis. when the position of label is
639 specified explicitly by posx and posy, the label appears so
640 that its center placed on the specified position.
641
642 Parameters:
643 label: label string.
644 style: font style. "normal", "roman", "italic" and "script"
645 are available. default is "normal".
646 size: font size. default is 1.1 (10% larger than that
647 of number labels)
648 posx: x position of label string in window coordinate.
649 default is the center of x axis.
650 posy: y position of label string in window coordinate.
651 vpid: viewport id. when not given, the last viewport
652 will be the target.
653 """
654 if style is None: style = ""
655 if size is None: size = 1.1
656 if posx is None: posx = -1.0
657 if posy is None: posy = -1.0
658 if vpid is None: vpid = -1
659
660 self._plotter.set_label_x(label, posx, posy, size, style, 1, 0, vpid)
661
662 def set_ylabel(self, label, style=None, size=None, posx=None, posy=None, vpid=None):
663 """\
664 set label string along y axis. when the position of label is
665 specified explicitly by posx and posy, the label appears so
666 that its center placed on the specified position.
667
668 Parameters:
669 label: label string.
670 style: font style. "normal", "roman", "italic" and "script"
671 are available. default is "normal".
672 size: font size. default is 1.1 (10% larger than that
673 of number labels)
674 posx: x position of label string in window coordinate.
675 posy: y position of label string in window coordinate.
676 default is the center of y axis.
677 vpid: viewport id. when not given, the last viewport
678 will be the target.
679 """
680 if style is None: style = ""
681 if size is None: size = 1.1
682 if posx is None: posx = -1.0
683 if posy is None: posy = -1.0
684 if vpid is None: vpid = -1
685
686 self._plotter.set_label_y(label, posx, posy, size, style, 1, 0, vpid)
687
688 def set_title(self, title, style=None, size=None, posx=None, posy=None, vpid=None):
689 """\
690 set title string over the top of the specified viewport.
691 when the position of title is specified explicitly by posx
692 and posy, the title appears so that its center placed on
693 the specified position.
694
695 Parameters:
696 title: title string.
697 style: font style. "normal", "roman", "italic" and "script"
698 are available. default is "normal".
699 size: font size. default is 1.5 (50% larger than that
700 of number titles)
701 posx: x position of title string in window coordinate.
702 posy: y position of title string.
703 default is the center of y axis.
704 vpid: viewport id. when not given, the last viewport
705 will be the target.
706 """
707 if style is None: style = ""
708 if size is None: size = 1.5
709 if posx is None: posx = -1.0
710 if posy is None: posy = -1.0
711 if vpid is None: vpid = -1
712
713 self._plotter.set_title(title, posx, posy, size, style, 1, 0, vpid)
714
715 def set_vpbgcolor(self, bgcolor, vpid=None):
716 """\
717 change the background color of the specified viewport.
718 default is transparent.
719
720 Parameters:
721 bgcolor: background color. see output of list_colornames().
722 default is "" (transparent).
723 vpid: viewport id. when not given, the last viewport
724 will be the target.
725 """
726 if vpid is None: vpid = -1
727
728 if bgcolor.strip() == "":
729 coloridx = -1
730 else:
731 coloridx = self.get_colorindex(bgcolor)
732
733 self._plotter.set_vpbgcolor(coloridx, vpid)
734
735 def plot(self):
736 """\
737 execute actual plotting.
738 """
739 self._plotter.plot()
740
741 def save(self, filename):
742 """\
743 save the figure in a file with specified name.
744 the filename and device previously set by set_output() is
745 not affected by this command.
746
747 Parameters:
748 filename: output file name.
749 """
750 prev_filename = self._plotter.get_filename()
751 prev_dev = self._plotter.get_device()
752
753 self.set_output(filename)
754 self.plot()
755
756 self.set_output(prev_filename, prev_dev)
757
758 def get_vinfo(self):
759 self._plotter.get_vinfo()
760
761 @classmethod
762 def get_colorindex(cls, colorname):
763 """\
764 convert the given color name into color index used in PGPLOT.
765 """
766 name = colorname.strip().lower()
767 available_color = True
768
769 if name == "white": idx = 0 # our definition of bgcolor
770 elif name == "black": idx = 1 # our definition of fgcolor
771 elif name == "red": idx = 2
772 elif name == "green": idx = 3
773 elif name == "blue": idx = 4
774 elif name == "cyan": idx = 5
775 elif name == "magenta": idx = 6
776 elif name == "yellow": idx = 7
777 elif name == "orange": idx = 8
778 elif name == "yellowgreen": idx = 9
779 elif name == "emerald": idx = 10
780 elif name == "skyblue": idx = 11
781 elif name == "purple": idx = 12
782 elif name == "pink": idx = 13
783 elif name == "gray": idx = 14
784 elif name == "lightgray": idx = 15
785 else: available_color = False
786
787 if (available_color):
788 return idx
789 else:
790 raise ValueError("Unavailable colour name.")
791
792 @classmethod
793 def list_colornames(cls):
794 """\
795 list the available color names.
796 """
797 print "plotter2: default color list ----"
798 print " (0) white (background)"
799 print " (1) black (foreground)"
800 print " (2) red"
801 print " (3) green"
802 print " (4) blue"
803 print " (5) cyan"
804 print " (6) magenta"
805 print " (7) yellow"
806 print " (8) orange"
807 print " (9) yellowgreen"
808 print " (10) emerald"
809 print " (11) skyblue"
810 print " (12) purple"
811 print " (13) pink"
812 print " (14) gray"
813 print " (15) lightgray"
814 print "---------------------------------"
815
816 @classmethod
817 def get_linestyleindex(cls, fstyle):
818 """\
819 convert the given line style into style index used in PGPLOT.
820 """
821 style = fstyle.strip().lower()
822 available_style = True
823
824 if style == "solid": idx = 1
825 elif style == "dashed": idx = 2
826 elif style == "dash-dotted": idx = 3
827 elif style == "dotted": idx = 4
828 elif style == "dash-dot-dot-dotted": idx = 5
829 else: available_style = False
830
831 if (available_style):
832 return idx
833 else:
834 raise ValueError("Unavailable line style.")
835
836 @classmethod
837 def list_linestyles(cls):
838 """\
839 list the available line styles.
840 """
841 print "plotter2: fill style list ----"
842 print " (1) solid"
843 print " (2) dashed"
844 print " (3) dash-dotted"
845 print " (4) dotted"
846 print " (5) dash-dot-dot-dotted"
847 print "------------------------------"
848
849 @classmethod
850 def get_fillstyleindex(cls, fstyle):
851 """\
852 convert the given fill style into style index used in PGPLOT.
853 """
854 style = fstyle.strip().lower()
855 available_style = True
856
857 if style == "solid": idx = 1
858 elif style == "outline": idx = 2
859 elif style == "hatched": idx = 3
860 elif style == "crosshatched": idx = 4
861 else: available_style = False
862
863 if (available_style):
864 return idx
865 else:
866 raise ValueError("Unavailable fill style.")
867
868 @classmethod
869 def list_fillstyles(cls):
870 """\
871 list the available fill styles.
872 """
873 print "plotter2: fill style list ----"
874 print " (1) solid"
875 print " (2) outline"
876 print " (3) hatched"
877 print " (4) crosshatched"
878 print "------------------------------"
879
880 @classmethod
881 def get_arrowheadfillstyleindex(cls, fstyle):
882 """\
883 convert the given arrowhead fill style into style index used in PGPLOT.
884 """
885 style = fstyle.strip().lower()
886 available_style = True
887
888 if style == "solid": idx = 1
889 elif style == "outline": idx = 2
890 else: available_style = False
891
892 if (available_style):
893 return idx
894 else:
895 raise ValueError("Unavailable fill style for arrow head.")
896
897 @classmethod
898 def list_arrowheadfillstyles(cls):
899 """\
900 list the available fill styles for arrow head.
901 """
902 print "plotter2: arrow head fill style list ----"
903 print " (1) solid"
904 print " (2) outline"
905 print "-----------------------------------------"
906
Note: See TracBrowser for help on using the repository browser.