Changeset 2698
- Timestamp:
- 12/15/12 21:37:52 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapplotter.py
r2697 r2698 49 49 self._inikwg = kwargs 50 50 51 # plot settings 52 self._colormap = None 53 self._linestyles = None 54 self._fp = FontProperties() 55 self._rows = None 56 self._cols = None 57 self._minmaxx = None 58 self._minmaxy = None 59 self._margins = self.set_margin(refresh=False) 60 self._legendloc = None 61 # scantable plot settings 51 62 self._panelling = None 52 63 self._stacking = None 53 64 self.set_panelling() 54 65 self.set_stacking() 55 self._rows = None 56 self._cols = None 57 self._minmaxx = None 58 self._minmaxy = None 59 self._datamask = None 66 self._hist = rcParams['plotter.histogram'] 67 # scantable dependent settings 60 68 self._data = None 69 self._abcunit = None 70 self._headtext = {'string': None, 'textobj': None} 71 self._selection = selector() 72 self._usermask = [] 73 self._maskselection = None 74 self._offset = None 61 75 self._lmap = None 62 76 self._title = None 63 77 self._ordinate = None 64 78 self._abcissa = None 65 self._abcunit = None 66 self._usermask = [] 67 self._maskselection = None 68 self._selection = selector() 69 self._hist = rcParams['plotter.histogram'] 70 self._fp = FontProperties() 71 self._margins = self.set_margin(refresh=False) 72 self._offset = None 79 # cursors for page iteration 73 80 self._startrow = 0 74 81 self._ipanel = -1 75 82 self._panelrows = [] 76 self._headtext={'string': None, 'textobj': None}77 self._colormap = None78 self._linestyles = None79 self._legendloc = None80 83 81 84 def _translate(self, instr): … … 178 181 179 182 180 @asaplog_post_dec181 def plot(self, scan=None):182 """183 Plot a scantable.184 Parameters:185 scan: a scantable186 Note:187 If a scantable was specified in a previous call188 to plot, no argument has to be given to 'replot'189 NO checking is done that the abcissas of the scantable190 are consistent e.g. all 'channel' or all 'velocity' etc.191 """192 if not self._data and not scan:193 msg = "Input is not a scantable"194 raise TypeError(msg)195 196 self._assert_plotter(action="reload")197 self._plotter.hold()198 self._reset_counter()199 #self._plotter.clear()200 if scan:201 self.set_data(scan, refresh=False)202 self._plotter.palette(color=0,colormap=self._colormap,203 linestyle=0,linestyles=self._linestyles)204 self._plotter.legend(self._legendloc)205 self._plot(self._data)206 if self._minmaxy is not None:207 self._plotter.set_limits(ylim=self._minmaxy)208 if self.casabar_exists(): self._plotter.figmgr.casabar.enable_button()209 self._plotter.release()210 self._plotter.tidy()211 self._plotter.show(hardrefresh=False)212 return213 214 183 def gca(self): 215 184 errmsg = "No axis to retun. Need to plot first." … … 224 193 225 194 self._plotter.figure.show() 195 196 def save(self, filename=None, orientation=None, dpi=None): 197 """ 198 Save the plot to a file. The known formats are 'png', 'ps', 'eps'. 199 Parameters: 200 filename: The name of the output file. This is optional 201 and autodetects the image format from the file 202 suffix. If non filename is specified a file 203 called 'yyyymmdd_hhmmss.png' is created in the 204 current directory. 205 orientation: optional parameter for postscript only (not eps). 206 'landscape', 'portrait' or None (default) are valid. 207 If None is choosen for 'ps' output, the plot is 208 automatically oriented to fill the page. 209 dpi: The dpi of the output non-ps plot 210 """ 211 errmsg = "Cannot save figure. Need to plot first." 212 self._assert_plotter(action="halt",errmsg=errmsg) 213 214 self._plotter.save(filename,orientation,dpi) 215 return 226 216 227 217 def create_mask(self, nwin=1, panel=0, color=None): … … 389 379 # end matplotlib.axes fowarding functions 390 380 381 # forwards to matplotlib.Figure.text 382 def figtext(self, *args, **kwargs): 383 """ 384 Add text to figure at location x,y (relative 0-1 coords). 385 This method forwards *args and **kwargs to a Matplotlib method, 386 matplotlib.Figure.text. 387 See the method help for detailed information. 388 """ 389 self._assert_plotter(action="reload") 390 self._plotter.text(*args, **kwargs) 391 # end matplotlib.Figure.text forwarding function 392 393 # plot setttings 391 394 @asaplog_post_dec 392 395 def set_data(self, scan, refresh=True): … … 422 425 self._minmaxy = None 423 426 self._abcunit = self._data.get_unit() 424 self._datamask = None425 427 if refresh: self.plot() 426 428 … … 459 461 return 460 462 463 def set_stacking(self, what=None): 464 """Set the 'stacking' mode i.e. which type of spectra should be 465 overlayed. 466 """ 467 mode = what 468 if mode is None: 469 mode = rcParams['plotter.stacking'] 470 md = self._translate(mode) 471 if md: 472 self._stacking = md 473 self._lmap = None 474 # new mode is set. need to reset counters for multi page plotting 475 self._reset_counters() 476 return True 477 return False 478 461 479 def set_panelling(self, what=None): 462 480 """Set the 'panelling' mode i.e. which type of spectra should be … … 471 489 self._panelling = md 472 490 self._title = None 473 #if md == 'r': 474 # self._stacking = '_r' 475 # you need to reset counters for multi page plotting 491 # new mode is set. need to reset counters for multi page plotting 476 492 self._reset_counters() 477 493 return True … … 496 512 if refresh and self._data: self.plot(self._data) 497 513 return 498 499 def set_stacking(self, what=None):500 """Set the 'stacking' mode i.e. which type of spectra should be501 overlayed.502 """503 mode = what504 if mode is None:505 mode = rcParams['plotter.stacking']506 md = self._translate(mode)507 if md:508 self._stacking = md509 self._lmap = None510 #if md == 'r':511 # self._panelling = '_r'512 # you need to reset counters for multi page plotting513 self._reset_counters()514 return True515 return False516 517 def _reset_counters(self):518 self._startrow = 0519 self._ipanel = -1520 self._panelrows = []521 514 522 515 def set_range(self,xstart=None,xend=None,ystart=None,yend=None,refresh=True, offset=None): … … 860 853 861 854 862 def save(self, filename=None, orientation=None, dpi=None): 863 """ 864 Save the plot to a file. The known formats are 'png', 'ps', 'eps'. 865 Parameters: 866 filename: The name of the output file. This is optional 867 and autodetects the image format from the file 868 suffix. If non filename is specified a file 869 called 'yyyymmdd_hhmmss.png' is created in the 870 current directory. 871 orientation: optional parameter for postscript only (not eps). 872 'landscape', 'portrait' or None (default) are valid. 873 If None is choosen for 'ps' output, the plot is 874 automatically oriented to fill the page. 875 dpi: The dpi of the output non-ps plot 876 """ 877 errmsg = "Cannot save figure. Need to plot first." 878 self._assert_plotter(action="halt",errmsg=errmsg) 879 880 self._plotter.save(filename,orientation,dpi) 881 return 855 def set_selection(self, selection=None, refresh=True, **kw): 856 """ 857 Parameters: 858 selection: a selector object (default unset the selection) 859 refresh: True (default) or False. If True, the plot is 860 replotted based on the new parameter setting(s). 861 Otherwise,the parameter(s) are set without replotting. 862 """ 863 if selection is None: 864 # reset 865 if len(kw) == 0: 866 self._selection = selector() 867 else: 868 # try keywords 869 for k in kw: 870 if k not in selector.fields: 871 raise KeyError("Invalid selection key '%s', valid keys are %s" % (k, selector.fields)) 872 self._selection = selector(**kw) 873 elif isinstance(selection, selector): 874 self._selection = selection 875 else: 876 raise TypeError("'selection' is not of type selector") 877 878 order = self._get_sortstring([self._panelling,self._stacking]) 879 if order: 880 self._selection.set_order(order) 881 if refresh and self._data: 882 self.plot() 882 883 883 884 @asaplog_post_dec … … 953 954 return start,end 954 955 956 # reset methods 955 957 def _reset(self): 956 958 self._usermask = [] … … 970 972 if self.casabar_exists(): 971 973 self._plotter.figmgr.casabar.set_pagecounter(1) 974 975 def _reset_counters(self): 976 self._startrow = 0 977 self._ipanel = -1 978 self._panelrows = [] 979 980 # scantable plot methods 981 @asaplog_post_dec 982 def plot(self, scan=None): 983 """ 984 Plot a scantable. 985 Parameters: 986 scan: a scantable 987 Note: 988 If a scantable was specified in a previous call 989 to plot, no argument has to be given to 'replot' 990 NO checking is done that the abcissas of the scantable 991 are consistent e.g. all 'channel' or all 'velocity' etc. 992 """ 993 if not self._data and not scan: 994 msg = "Input is not a scantable" 995 raise TypeError(msg) 996 997 self._assert_plotter(action="reload") 998 self._plotter.hold() 999 self._reset_counter() 1000 #self._plotter.clear() 1001 if scan: 1002 self.set_data(scan, refresh=False) 1003 self._plotter.palette(color=0,colormap=self._colormap, 1004 linestyle=0,linestyles=self._linestyles) 1005 self._plotter.legend(self._legendloc) 1006 self._plot(self._data) 1007 if self._minmaxy is not None: 1008 self._plotter.set_limits(ylim=self._minmaxy) 1009 if self.casabar_exists(): self._plotter.figmgr.casabar.enable_button() 1010 self._plotter.release() 1011 self._plotter.tidy() 1012 self._plotter.show(hardrefresh=False) 1013 return 972 1014 973 1015 def _plot(self, scan): … … 1190 1232 #temporary switch-off for older matplotlib 1191 1233 #if self._fp is not None: 1192 if self._fp is not None and getattr(self._plotter.figure,'findobj',False): 1234 if self._fp is not None and \ 1235 getattr(self._plotter.figure,'findobj',False): 1193 1236 for o in self._plotter.figure.findobj(Text): 1194 1237 if not self._headtext['textobj'] or \ … … 1212 1255 return lsorts 1213 1256 return None 1214 1215 def set_selection(self, selection=None, refresh=True, **kw):1216 """1217 Parameters:1218 selection: a selector object (default unset the selection)1219 refresh: True (default) or False. If True, the plot is1220 replotted based on the new parameter setting(s).1221 Otherwise,the parameter(s) are set without replotting.1222 """1223 if selection is None:1224 # reset1225 if len(kw) == 0:1226 self._selection = selector()1227 else:1228 # try keywords1229 for k in kw:1230 if k not in selector.fields:1231 raise KeyError("Invalid selection key '%s', valid keys are %s" % (k, selector.fields))1232 self._selection = selector(**kw)1233 elif isinstance(selection, selector):1234 self._selection = selection1235 else:1236 raise TypeError("'selection' is not of type selector")1237 1238 order = self._get_sortstring([self._panelling,self._stacking])1239 if order:1240 self._selection.set_order(order)1241 if refresh and self._data:1242 self.plot()1243 1257 1244 1258 def _get_selected_n(self, scan): … … 1573 1587 # self._minmaxy = None 1574 1588 # self._abcunit = self._data.get_unit() 1575 # self._datamask = None1576 1589 1577 1590 self._assert_plotter(action="reload") … … 1636 1649 if len(x) > 0: 1637 1650 plotit(x,y) 1638 1639 1640 # forwards to matplotlib.Figure.text1641 def figtext(self, *args, **kwargs):1642 """1643 Add text to figure at location x,y (relative 0-1 coords).1644 This method forwards *args and **kwargs to a Matplotlib method,1645 matplotlib.Figure.text.1646 See the method help for detailed information.1647 """1648 self._assert_plotter(action="reload")1649 self._plotter.text(*args, **kwargs)1650 # end matplotlib.Figure.text forwarding function1651 1651 1652 1652
Note:
See TracChangeset
for help on using the changeset viewer.