Changes in trunk/python/asapplotter.py [2453:2290]
- File:
-
- 1 edited
-
trunk/python/asapplotter.py (modified) (36 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapplotter.py
r2453 r2290 45 45 if visible is not None: 46 46 self._visible = visible 47 self._plotter = None 48 self._inikwg = kwargs 47 self._plotter = self._newplotter(**kwargs) 48 # additional tool bar 49 self._plotter.figmgr.casabar=self._new_custombar() 49 50 50 51 self._panelling = None … … 54 55 self._rows = None 55 56 self._cols = None 57 self._autoplot = False 56 58 self._minmaxx = None 57 59 self._minmaxy = None … … 74 76 self._panelrows = [] 75 77 self._headtext={'string': None, 'textobj': None} 76 self._colormap = None77 self._linestyles = None78 self._legendloc = None79 78 80 79 def _translate(self, instr): … … 86 85 return None 87 86 88 def _reload_plotter(self): 89 if self._plotter is not None: 90 if not self._plotter.is_dead: 91 # clear lines and axes 92 self._plotter.clear() 93 if self.casabar_exists(): 94 del self._plotter.figmgr.casabar 95 self._plotter.quit() 96 del self._plotter 97 self._plotter = new_asaplot(self._visible,**self._inikwg) 98 self._plotter.figmgr.casabar=self._new_custombar() 99 # just to make sure they're set 100 self._plotter.palette(color=0,colormap=self._colormap, 101 linestyle=0,linestyles=self._linestyles) 102 self._plotter.legend(self._legendloc) 87 def _newplotter(self, **kwargs): 88 return new_asaplot(self._visible,**kwargs) 103 89 104 90 def _new_custombar(self): … … 121 107 return False 122 108 123 def _assert_plotter(self,action="status",errmsg=None):124 """125 Check plot window status. Returns True if plot window is alive.126 Parameters127 action: An action to take if the plotter window is not alive.128 ['status'|'reload'|'halt']129 The action 'status' simply returns False if asaplot130 is not alive. When action='reload', plot window is131 reloaded and the method returns True. Finally, an132 error is raised when action='halt'.133 errmsg: An error (warning) message to send to the logger,134 when plot window is not alive.135 """136 if self._plotter and not self._plotter.is_dead:137 return True138 # Plotter is not alive.139 haltmsg = "Plotter window has not yet been loaded or is closed."140 if type(errmsg)==str and len(errmsg) > 0:141 haltmsg = errmsg142 143 if action.upper().startswith("R"):144 # reload plotter145 self._reload_plotter()146 return True147 elif action.upper().startswith("H"):148 # halt149 asaplog.push(haltmsg)150 asaplog.post("ERROR")151 raise RuntimeError(haltmsg)152 else:153 if errmsg:154 asaplog.push(errmsg)155 asaplog.post("WARN")156 return False157 158 159 109 @asaplog_post_dec 160 110 def plot(self, scan=None): … … 169 119 are consistent e.g. all 'channel' or all 'velocity' etc. 170 120 """ 121 self._startrow = 0 122 self._ipanel = -1 123 self._reset_header() 124 if self._plotter.is_dead: 125 if self.casabar_exists(): 126 del self._plotter.figmgr.casabar 127 self._plotter = self._newplotter() 128 self._plotter.figmgr.casabar=self._new_custombar() 129 if self.casabar_exists(): 130 self._plotter.figmgr.casabar.set_pagecounter(1) 131 self._panelrows = [] 132 self._plotter.hold() 133 #self._plotter.clear() 171 134 if not self._data and not scan: 172 135 msg = "Input is not a scantable" 173 136 raise TypeError(msg) 174 self._startrow = 0175 self._ipanel = -1176 self._reset_header()177 self._panelrows = []178 179 self._assert_plotter(action="reload")180 if self.casabar_exists():181 self._plotter.figmgr.casabar.set_pagecounter(1)182 183 self._plotter.hold()184 #self._plotter.clear()185 137 if scan: 186 138 self.set_data(scan, refresh=False) 187 self._plotter.palette(color=0,colormap=self._colormap,188 linestyle=0,linestyles=self._linestyles)189 self._plotter.legend(self._legendloc)190 191 139 self._plot(self._data) 192 140 if self._minmaxy is not None: … … 199 147 200 148 def gca(self): 201 errmsg = "No axis to retun. Need to plot first."202 if not self._assert_plotter(action="status",errmsg=errmsg):203 return None204 149 return self._plotter.figure.gca() 205 150 206 151 def refresh(self): 207 152 """Do a soft refresh""" 208 errmsg = "No figure to re-plot. Need to plot first."209 self._assert_plotter(action="halt",errmsg=errmsg)210 211 153 self._plotter.figure.show() 212 154 … … 221 163 if different IFs are spread over panels (default 0) 222 164 """ 223 ## this method relies on already plotted figure 224 if not self._assert_plotter(action="status") or (self._data is None): 225 msg = "Cannot create mask interactively on plot. Can only create mask after plotting." 226 asaplog.push( msg ) 227 asaplog.post( "ERROR" ) 165 if self._data is None: 228 166 return [] 229 167 outmask = [] … … 272 210 # forwards to matplotlib axes 273 211 def text(self, *args, **kwargs): 274 self._assert_plotter(action="reload")275 212 if kwargs.has_key("interactive"): 276 213 if kwargs.pop("interactive"): … … 282 219 283 220 def arrow(self, *args, **kwargs): 284 self._assert_plotter(action="reload")285 221 if kwargs.has_key("interactive"): 286 222 if kwargs.pop("interactive"): … … 295 231 296 232 def annotate(self, text, xy=None, xytext=None, **kwargs): 297 self._assert_plotter(action="reload")298 233 if kwargs.has_key("interactive"): 299 234 if kwargs.pop("interactive"): … … 307 242 308 243 def axvline(self, *args, **kwargs): 309 self._assert_plotter(action="reload")310 244 if kwargs.has_key("interactive"): 311 245 if kwargs.pop("interactive"): … … 317 251 318 252 def axhline(self, *args, **kwargs): 319 self._assert_plotter(action="reload")320 253 if kwargs.has_key("interactive"): 321 254 if kwargs.pop("interactive"): … … 327 260 328 261 def axvspan(self, *args, **kwargs): 329 self._assert_plotter(action="reload")330 262 if kwargs.has_key("interactive"): 331 263 if kwargs.pop("interactive"): … … 342 274 343 275 def axhspan(self, *args, **kwargs): 344 self._assert_plotter(action="reload")345 276 if kwargs.has_key("interactive"): 346 277 if kwargs.pop("interactive"): … … 357 288 358 289 def _axes_callback(self, axesfunc, *args, **kwargs): 359 self._assert_plotter(action="reload")360 290 panel = 0 361 291 if kwargs.has_key("panel"): … … 574 504 """ 575 505 self._lmap = mp 576 #self._plotter.legend(mode) 577 self._legendloc = mode 506 self._plotter.legend(mode) 578 507 if isinstance(fontsize, int): 579 508 from matplotlib import rc as rcp … … 584 513 def set_title(self, title=None, fontsize=None, refresh=True): 585 514 """ 586 Set the title of sub-plots. If multiple sub-plots are plotted,515 Set the title of the plot. If multiple panels are plotted, 587 516 multiple titles have to be specified. 588 517 Parameters: 589 title: a list of titles of sub-plots.590 fontsize: a font size of titles (integer)591 518 refresh: True (default) or False. If True, the plot is 592 519 replotted based on the new parameter setting(s). … … 594 521 Example: 595 522 # two panels are visible on the plotter 596 plotter.set_title([ 'First Panel','Second Panel'])523 plotter.set_title(["First Panel","Second Panel"]) 597 524 """ 598 525 self._title = title … … 610 537 ordinate: a list of ordinate labels. None (default) let 611 538 data determine the labels 612 fontsize: a font size of vertical axis labels (integer)613 539 refresh: True (default) or False. If True, the plot is 614 540 replotted based on the new parameter setting(s). … … 616 542 Example: 617 543 # two panels are visible on the plotter 618 plotter.set_ordinate([ 'First Y-Axis','Second Y-Axis'])544 plotter.set_ordinate(["First Y-Axis","Second Y-Axis"]) 619 545 """ 620 546 self._ordinate = ordinate … … 633 559 abcissa: a list of abcissa labels. None (default) let 634 560 data determine the labels 635 fontsize: a font size of horizontal axis labels (integer)636 561 refresh: True (default) or False. If True, the plot is 637 562 replotted based on the new parameter setting(s). … … 639 564 Example: 640 565 # two panels are visible on the plotter 641 plotter.set_ordinate([ 'First X-Axis','Second X-Axis'])566 plotter.set_ordinate(["First X-Axis","Second X-Axis"]) 642 567 """ 643 568 self._abcissa = abcissa … … 659 584 Otherwise,the parameter(s) are set without replotting. 660 585 Example: 661 plotter.set_colors( 'red green blue')586 plotter.set_colors("red green blue") 662 587 # If for example four lines are overlaid e.g I Q U V 663 588 # 'I' will be 'red', 'Q' will be 'green', U will be 'blue' 664 589 # and 'V' will be 'red' again. 665 590 """ 666 #if isinstance(colmap,str): 667 # colmap = colmap.split() 668 #self._plotter.palette(0, colormap=colmap) 669 self._colormap = colmap 591 if isinstance(colmap,str): 592 colmap = colmap.split() 593 self._plotter.palette(0, colormap=colmap) 670 594 if refresh and self._data: self.plot(self._data) 671 595 … … 680 604 is taken from the .asaprc setting 681 605 plotter.histogram 682 linewidth: a line width683 606 refresh: True (default) or False. If True, the plot is 684 607 replotted based on the new parameter setting(s). … … 697 620 only one color has been set. 698 621 Parameters: 699 linestyles:a list of linestyles to use.622 linestyles: a list of linestyles to use. 700 623 'line', 'dashed', 'dotted', 'dashdot', 701 624 'dashdotdot' and 'dashdashdot' are 702 625 possible 703 linewidth: a line width704 626 refresh: True (default) or False. If True, the plot is 705 627 replotted based on the new parameter setting(s). 706 628 Otherwise,the parameter(s) are set without replotting. 707 629 Example: 708 plotter.set_colors( 'black')709 plotter.set_linestyles( 'line dashed dotted dashdot')630 plotter.set_colors("black") 631 plotter.set_linestyles("line dashed dotted dashdot") 710 632 # If for example four lines are overlaid e.g I Q U V 711 633 # 'I' will be 'solid', 'Q' will be 'dashed', 712 634 # U will be 'dotted' and 'V' will be 'dashdot'. 713 635 """ 714 #if isinstance(linestyles,str): 715 # linestyles = linestyles.split() 716 #self._plotter.palette(color=0,linestyle=0,linestyles=linestyles) 717 self._linestyles = linestyles 636 if isinstance(linestyles,str): 637 linestyles = linestyles.split() 638 self._plotter.palette(color=0,linestyle=0,linestyles=linestyles) 718 639 if isinstance(linewidth, float) or isinstance(linewidth, int): 719 640 from matplotlib import rc as rcp … … 786 707 If the spectrum is flagged no line will be drawn in that location. 787 708 """ 788 errmsg = "Cannot plot spectral lines. Need to plot scantable first."789 self._assert_plotter(action="halt",errmsg=errmsg)790 709 if not self._data: 791 710 raise RuntimeError("No scantable has been plotted yet.") … … 865 784 dpi: The dpi of the output non-ps plot 866 785 """ 867 errmsg = "Cannot save figure. Need to plot first."868 self._assert_plotter(action="halt",errmsg=errmsg)869 870 786 self._plotter.save(filename,orientation,dpi) 871 787 return … … 875 791 """ 876 792 Set a plotting mask for a specific polarization. 877 This is useful for masking out 'noise'Pangle outside a source.793 This is useful for masking out "noise" Pangle outside a source. 878 794 Parameters: 879 795 mask: a mask from scantable.create_mask … … 884 800 Example: 885 801 select = selector() 886 select.setpolstrings( 'Pangle')802 select.setpolstrings("Pangle") 887 803 plotter.set_mask(mymask, select) 888 804 """ … … 1340 1256 PL.ion() 1341 1257 PL.draw() 1342 if matplotlib.get_backend() == 'Qt4Agg':PL.gcf().show()1258 PL.gcf().show() 1343 1259 if (self._outfile is not None): 1344 1260 PL.savefig(self._outfile) … … 1379 1295 [xmin,xmax,ymin,ymax] = PL.axis() 1380 1296 PL.axis([xmax,xmin,ymin,ymax]) 1381 PL.ion()1297 #PL.ion() 1382 1298 PL.draw() 1383 if matplotlib.get_backend() == 'Qt4Agg':PL.gcf().show()1299 PL.gcf().show() 1384 1300 if (self._outfile is not None): 1385 1301 PL.savefig(self._outfile) … … 1389 1305 @asaplog_post_dec 1390 1306 def plottp(self, scan=None, outfile=None): 1391 self._assert_plotter(action="reload") 1307 if self._plotter.is_dead: 1308 if self.casabar_exists(): 1309 del self._plotter.figmgr.casabar 1310 self._plotter = self._newplotter() 1311 self._plotter.figmgr.casabar=self._new_custombar() 1392 1312 self._plotter.hold() 1393 1313 self._plotter.clear() … … 1479 1399 See the method help for detailed information. 1480 1400 """ 1481 self._assert_plotter(action="reload")1482 1401 self._plotter.text(*args, **kwargs) 1483 1402 # end matplotlib.Figure.text forwarding function … … 1518 1437 1519 1438 if plot: 1520 errmsg = "Can plot header only after the first call to plot()."1521 self._assert_plotter(action="halt",errmsg=errmsg)1522 1439 self._plotter.hold() 1523 1440 self._header_plot(headstr,fontsize=fontsize) … … 1552 1469 asaplog.push("No header has been plotted. Exit without any operation") 1553 1470 asaplog.post("WARN") 1554 el if self._assert_plotter(action="status"):1471 else: 1555 1472 self._plotter.hold() 1556 1473 for textobj in self._headtext['textobj']:
Note:
See TracChangeset
for help on using the changeset viewer.
