Changeset 2895 for trunk/python


Ignore:
Timestamp:
02/19/14 20:41:19 (11 years ago)
Author:
WataruKawasaki
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/plotter2.py

    r2861 r2895  
    55    def __init__(self):
    66        self._plotter = Plotter2()
     7        self.current_vs_unit = 'cm'
    78
    89    def set_output(self, filename=None, dev=None):
     
    3738        self._plotter.set_filename(expanduser(expandvars(filename)))
    3839        self._plotter.set_device(dev.strip())
    39 
     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       
    40112    def set_vp(self, xmin, xmax, ymin, ymax, id=None):
    41113        """\
Note: See TracChangeset for help on using the changeset viewer.