Changeset 2895
- Timestamp:
- 02/19/14 20:41:19 (11 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/plotter2.py
r2861 r2895 5 5 def __init__(self): 6 6 self._plotter = Plotter2() 7 self.current_vs_unit = 'cm' 7 8 8 9 def set_output(self, filename=None, dev=None): … … 37 38 self._plotter.set_filename(expanduser(expandvars(filename))) 38 39 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 40 112 def set_vp(self, xmin, xmax, ymin, ymax, id=None): 41 113 """\ -
trunk/src/Plotter2.cpp
r2861 r2895 294 294 hasDefaultViewport = true; 295 295 currentViewportId = 0; 296 297 width = 8.82796; // default viewsurface width seems to be this value. 298 aspect = 0.75; // default viewsurface aspect 296 299 } 297 300 … … 320 323 cpgopen((filename + "/" + device).c_str()); 321 324 hasDevice = true; 325 } 326 327 float Plotter2::getViewSurfaceWidth() { 328 return width; 329 } 330 331 float Plotter2::getViewSurfaceAspect() { 332 return aspect; 333 } 334 335 void Plotter2::setViewSurface(const float inWidth, const float inAspect) { 336 width = inWidth; 337 aspect = inAspect; 322 338 } 323 339 … … 1127 1143 open(); 1128 1144 1145 if ((width > 0.0) && (aspect > 0.0)) { 1146 cpgpap(width, aspect); 1147 } 1148 1129 1149 cpgscr(0, 1.0, 1.0, 1.0); // set background color white 1130 1150 cpgscr(1, 0.0, 0.0, 0.0); // set foreground color black -
trunk/src/Plotter2.h
r2861 r2895 162 162 void setDevice(const std::string& inDevice); 163 163 164 float getViewSurfaceWidth(); 165 float getViewSurfaceAspect(); 166 void setViewSurface(const float width, const float aspect); 164 167 int addViewport(const float xmin, const float xmax, const float ymin, const float ymax); 165 168 void setViewport(const float xmin, const float xmax, const float ymin, const float ymax, const int id); … … 208 211 bool hasDefaultViewport; 209 212 int currentViewportId; 213 float width; 214 float aspect; 210 215 void open(); 211 216 void close(); -
trunk/src/python_Plotter2.cpp
r2830 r2895 44 44 .def("get_device",&Plotter2::getDevice) 45 45 .def("set_device",&Plotter2::setDevice) 46 .def("get_viewsurface_width",&Plotter2::getViewSurfaceWidth) 47 .def("get_viewsurface_aspect",&Plotter2::getViewSurfaceAspect) 48 .def("set_viewsurface",&Plotter2::setViewSurface) 46 49 .def("add_viewport",&Plotter2::addViewport) 47 50 .def("set_viewport",&Plotter2::setViewport)
Note:
See TracChangeset
for help on using the changeset viewer.