source: trunk/python/plotter2.py

Last change on this file was 3017, checked in by WataruKawasaki, 9 years ago

New Development: No

JIRA Issue: Yes CAS-6168

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sd

Description: add help text in plotter2.set_vs() that the actual image height might not be always the same as the value expected from (width * aspect) and there might be 1 pixel difference especially when unit is set 'pixel'; actually height is calculated inside cpgpap() so uncontrollable directly.


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