source: trunk/python/plotter2.py@ 2895

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

New Development: Yes

JIRA Issue: Yes CAS-6168

Ready for Test: Yes

Interface Changes:

What Interface Changed:

Test Programs:

Put in Release Notes: Yes

Module(s): sd.plotter2

Description: added methods to sd.plotter2 to enable changing the size and shape of the entire region to be plotted (which is referred to as 'viewsurface' in PGPLOT).


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