source: trunk/python/plotter2.py@ 2903

Last change on this file since 2903 was 2896, checked in by WataruKawasaki, 11 years ago

New Development: Yes

JIRA Issue: Yes CAS-6216/6217

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: added new methods in sd.plotter2

Test Programs:

Put in Release Notes:

Module(s): sd

Description: arrows and annotation texts become available in sd.plotter2.


File size: 33.2 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 append 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_annotation(self, label, posx=None, posy=None, angle=None, fjust=None, size=None, style=None, color=None, bgcolor=None, vpid=None, annid=None):
592 if posx is None: posx = 0.5
593 if posy is None: posy = 0.5
594 if angle is None: angle = 0.0
595 if fjust is None: fjust = 0.5
596 if size is None: size = 1.0
597 if style is None: style = ""
598 if color is None: color = "black"
599 if bgcolor is None: bgcolor = "" # transparent
600 if vpid is None: vpid = -1
601 if annid is None: annid = -1
602
603 coloridx = self.get_colorindex(color)
604 bgcoloridx = self.get_colorindex(bgcolor) if (bgcolor.strip() != "") else bgcolor
605
606 self._plotter.set_annotation(label, posx, posy, angle, fjust, size, style, coloridx, bgcoloridx, vpid, annid)
607
608 def set_xlabel(self, label, style=None, size=None, posx=None, posy=None, vpid=None):
609 """\
610 set label string along x axis. when the position of label is
611 specified explicitly by posx and posy, the label appears so
612 that its center placed on the specified position.
613
614 Parameters:
615 label: label string.
616 style: font style. "normal", "roman", "italic" and "script"
617 are available. default is "normal".
618 size: font size. default is 1.1 (10% larger than that
619 of number labels)
620 posx: x position of label string in window coordinate.
621 default is the center of x axis.
622 posy: y position of label string.
623 vpid: viewport id. when not given, the last viewport
624 will be the target.
625 """
626 if style is None: style = ""
627 if size is None: size = 1.1
628 if posx is None: posx = -1.0
629 if posy is None: posy = -1.0
630 if vpid is None: vpid = -1
631
632 self._plotter.set_label_x(label, posx, posy, size, style, 1, 0, vpid)
633
634 def set_ylabel(self, label, style=None, size=None, posx=None, posy=None, vpid=None):
635 """\
636 set label string along y axis. when the position of label is
637 specified explicitly by posx and posy, the label appears so
638 that its center placed on the specified position.
639
640 Parameters:
641 label: label string.
642 style: font style. "normal", "roman", "italic" and "script"
643 are available. default is "normal".
644 size: font size. default is 1.1 (10% larger than that
645 of number labels)
646 posx: x position of label string in window coordinate.
647 posy: y position of label string.
648 default is the center of y axis.
649 vpid: viewport id. when not given, the last viewport
650 will be the target.
651 """
652 if style is None: style = ""
653 if size is None: size = 1.1
654 if posx is None: posx = -1.0
655 if posy is None: posy = -1.0
656 if vpid is None: vpid = -1
657
658 self._plotter.set_label_y(label, posx, posy, size, style, 1, 0, vpid)
659
660 def set_title(self, title, style=None, size=None, posx=None, posy=None, vpid=None):
661 """\
662 set title string over the top of the specified viewport.
663 when the position of title is specified explicitly by posx
664 and posy, the title appears so that its center placed on
665 the specified position.
666
667 Parameters:
668 title: title string.
669 style: font style. "normal", "roman", "italic" and "script"
670 are available. default is "normal".
671 size: font size. default is 1.5 (50% larger than that
672 of number titles)
673 posx: x position of title string in window coordinate.
674 posy: y position of title string.
675 default is the center of y axis.
676 vpid: viewport id. when not given, the last viewport
677 will be the target.
678 """
679 if style is None: style = ""
680 if size is None: size = 1.5
681 if posx is None: posx = -1.0
682 if posy is None: posy = -1.0
683 if vpid is None: vpid = -1
684
685 self._plotter.set_title(title, posx, posy, size, style, 1, 0, vpid)
686
687 def set_vpbgcolor(self, bgcolor, vpid=None):
688 """\
689 change the background color of the specified viewport.
690 default is transparent.
691
692 Parameters:
693 bgcolor: background color. see output of list_colornames().
694 default is "" (transparent).
695 vpid: viewport id. when not given, the last viewport
696 will be the target.
697 """
698 if vpid is None: vpid = -1
699
700 if bgcolor.strip() == "":
701 coloridx = -1
702 else:
703 coloridx = self.get_colorindex(bgcolor)
704
705 self._plotter.set_vpbgcolor(coloridx, vpid)
706
707 def plot(self):
708 """\
709 execute actual plotting.
710 """
711 self._plotter.plot()
712
713 def save(self, filename):
714 """\
715 save the figure in a file with specified name.
716 the filename and device previously set by set_output() is
717 not affected by this command.
718
719 Parameters:
720 filename: output file name.
721 """
722 prev_filename = self._plotter.get_filename()
723 prev_dev = self._plotter.get_device()
724
725 self.set_output(filename)
726 self.plot()
727
728 self.set_output(prev_filename, prev_dev)
729
730 def get_vinfo(self):
731 self._plotter.get_vinfo()
732
733 @classmethod
734 def get_colorindex(cls, colorname):
735 """\
736 convert the given color name into color index used in PGPLOT.
737 """
738 name = colorname.strip().lower()
739 available_color = True
740
741 if name == "white": idx = 0 # our definition of bgcolor
742 elif name == "black": idx = 1 # our definition of fgcolor
743 elif name == "red": idx = 2
744 elif name == "green": idx = 3
745 elif name == "blue": idx = 4
746 elif name == "cyan": idx = 5
747 elif name == "magenta": idx = 6
748 elif name == "yellow": idx = 7
749 elif name == "orange": idx = 8
750 elif name == "yellowgreen": idx = 9
751 elif name == "emerald": idx = 10
752 elif name == "skyblue": idx = 11
753 elif name == "purple": idx = 12
754 elif name == "pink": idx = 13
755 elif name == "gray": idx = 14
756 elif name == "lightgray": idx = 15
757 else: available_color = False
758
759 if (available_color):
760 return idx
761 else:
762 raise ValueError("Unavailable colour name.")
763
764 @classmethod
765 def list_colornames(cls):
766 """\
767 list the available color names.
768 """
769 print "plotter2: default color list ----"
770 print " (0) white (background)"
771 print " (1) black (foreground)"
772 print " (2) red"
773 print " (3) green"
774 print " (4) blue"
775 print " (5) cyan"
776 print " (6) magenta"
777 print " (7) yellow"
778 print " (8) orange"
779 print " (9) yellowgreen"
780 print " (10) emerald"
781 print " (11) skyblue"
782 print " (12) purple"
783 print " (13) pink"
784 print " (14) gray"
785 print " (15) lightgray"
786 print "---------------------------------"
787
788 @classmethod
789 def get_linestyleindex(cls, fstyle):
790 """\
791 convert the given line style into style index used in PGPLOT.
792 """
793 style = fstyle.strip().lower()
794 available_style = True
795
796 if style == "solid": idx = 1
797 elif style == "dashed": idx = 2
798 elif style == "dash-dotted": idx = 3
799 elif style == "dotted": idx = 4
800 elif style == "dash-dot-dot-dotted": idx = 5
801 else: available_style = False
802
803 if (available_style):
804 return idx
805 else:
806 raise ValueError("Unavailable line style.")
807
808 @classmethod
809 def list_linestyles(cls):
810 """\
811 list the available line styles.
812 """
813 print "plotter2: fill style list ----"
814 print " (1) solid"
815 print " (2) dashed"
816 print " (3) dash-dotted"
817 print " (4) dotted"
818 print " (5) dash-dot-dot-dotted"
819 print "------------------------------"
820
821 @classmethod
822 def get_fillstyleindex(cls, fstyle):
823 """\
824 convert the given fill style into style index used in PGPLOT.
825 """
826 style = fstyle.strip().lower()
827 available_style = True
828
829 if style == "solid": idx = 1
830 elif style == "outline": idx = 2
831 elif style == "hatched": idx = 3
832 elif style == "crosshatched": idx = 4
833 else: available_style = False
834
835 if (available_style):
836 return idx
837 else:
838 raise ValueError("Unavailable fill style.")
839
840 @classmethod
841 def list_fillstyles(cls):
842 """\
843 list the available fill styles.
844 """
845 print "plotter2: fill style list ----"
846 print " (1) solid"
847 print " (2) outline"
848 print " (3) hatched"
849 print " (4) crosshatched"
850 print "------------------------------"
851
852 @classmethod
853 def get_arrowheadfillstyleindex(cls, fstyle):
854 """\
855 convert the given arrowhead fill style into style index used in PGPLOT.
856 """
857 style = fstyle.strip().lower()
858 available_style = True
859
860 if style == "solid": idx = 1
861 elif style == "outline": idx = 2
862 else: available_style = False
863
864 if (available_style):
865 return idx
866 else:
867 raise ValueError("Unavailable fill style for arrow head.")
868
869 @classmethod
870 def list_arrowheadfillstyles(cls):
871 """\
872 list the available fill styles for arrow head.
873 """
874 print "plotter2: arrow head fill style list ----"
875 print " (1) solid"
876 print " (2) outline"
877 print "-----------------------------------------"
878
Note: See TracBrowser for help on using the repository browser.