Changeset 1723
- Timestamp:
- 04/20/10 18:38:20 (15 years ago)
- Location:
- branches/alma/python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma/python/asaplotbase.py
r1717 r1723 570 570 571 571 572 def set_panels(self, rows=1, cols=0, n=-1, nplots=-1, ganged=True): 572 #def set_panels(self, rows=1, cols=0, n=-1, nplots=-1, ganged=True): 573 def set_panels(self, rows=1, cols=0, n=-1, nplots=-1, layout=None,ganged=True): 573 574 """ 574 575 Set the panel layout. … … 593 594 self.set_title() 594 595 596 if layout: 597 lef, bot, rig, top, wsp, hsp = layout 598 self.figure.subplots_adjust( 599 left=lef,bottom=bot,right=rig,top=top,wspace=wsp,hspace=hsp) 600 del lef,bot,rig,top,wsp,hsp 601 595 602 if rows < 1: rows = 1 596 603 … … 605 612 if 0 <= n < rows*cols: 606 613 i = len(self.subplots) 614 607 615 self.subplots.append({}) 608 616 … … 666 674 self.cols = cols 667 675 self.subplot(0) 676 del rows,cols,n,nplots,layout,ganged,i 668 677 669 678 def tidy(self): -
branches/alma/python/asapplotter.py
r1714 r1723 39 39 self._selection = selector() 40 40 self._hist = rcParams['plotter.histogram'] 41 self._panellayout = self.set_panellayout(refresh=False) 41 42 42 43 def _translate(self, instr): … … 476 477 rcp('font', size=size) 477 478 if refresh and self._data: self.plot(self._data) 479 480 def set_panellayout(self,layout=[],refresh=True): 481 """ 482 Set the layout of subplots. 483 Parameters: 484 layout: a list of subplots layout in figure coordinate (0-1), 485 i.e., fraction of the figure width or height. 486 The order of elements should be: 487 [left, bottom, right, top, horizontal space btw panels, 488 vertical space btw panels]. 489 refresh: True (default) or False. If True, the plot is 490 replotted based on the new parameter setting(s). 491 Otherwise,the parameter(s) are set without replotting. 492 Note 493 * When layout is not specified, the values are reset to the defaults 494 of matplotlib. 495 * If any element is set to be None, the current value is adopted. 496 """ 497 if layout == []: self._panellayout=self._reset_panellayout() 498 else: 499 self._panellayout=[None]*6 500 self._panellayout[0:len(layout)]=layout 501 #print "panel layout set to ",self._panellayout 502 if refresh and self._data: self.plot(self._data) 503 504 def _reset_panellayout(self): 505 ks=map(lambda x: 'figure.subplot.'+x, 506 ['left','bottom','right','top','hspace','wspace']) 507 return map(matplotlib.rcParams.get,ks) 478 508 479 509 def plot_lines(self, linecat=None, doppler=0.0, deltachan=10, rotate=90.0, … … 693 723 n = min(n,self._rows*self._cols) 694 724 self._plotter.set_panels(rows=self._rows,cols=self._cols, 695 nplots=n,ganged=ganged) 725 # nplots=n,ganged=ganged) 726 nplots=n,layout=self._panellayout,ganged=ganged) 696 727 else: 697 self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged) 728 # self._plotter.set_panels(rows=n,cols=0,nplots=n,ganged=ganged) 729 self._plotter.set_panels(rows=n,cols=0,nplots=n,layout=self._panellayout,ganged=ganged) 698 730 else: 699 self._plotter.set_panels() 731 # self._plotter.set_panels() 732 self._plotter.set_panels(layout=self._panellayout) 700 733 r=0 701 734 nr = scan.nrow() … … 856 889 #PL.ioff() 857 890 PL.clf() 891 # Adjust subplot layouts 892 if len(self._panellayout) !=6: self.set_panellayout(refresh=False) 893 lef, bot, rig, top, wsp, hsp = self._panellayout 894 PL.gcf().subplots_adjust(left=lef,bottom=bot,right=rig,top=top, 895 wspace=wsp,hspace=hsp) 896 858 897 tdel = max(t) - min(t) 859 898 ax = PL.subplot(2,1,1) … … 942 981 #PL.ioff() 943 982 PL.clf() 983 # Adjust subplot layouts 984 if len(self._panellayout) !=6: self.set_panellayout(refresh=False) 985 lef, bot, rig, top, wsp, hsp = self._panellayout 986 PL.gcf().subplots_adjust(left=lef,bottom=bot,right=rig,top=top, 987 wspace=wsp,hspace=hsp) 944 988 ax = PL.axes([0.1,0.1,0.8,0.8]) 945 989 ax = PL.axes([0.1,0.1,0.8,0.8]) … … 987 1031 # self._abcunit = self._data.get_unit() 988 1032 # self._datamask = None 1033 1034 # Adjust subplot layouts 1035 if len(self._panellayout) !=6: self.set_panellayout(refresh=False) 1036 lef, bot, rig, top, wsp, hsp = self._panellayout 1037 self._plotter.figure.subplots_adjust( 1038 left=lef,bottom=bot,right=rig,top=top,wspace=wsp,hspace=hsp) 989 1039 self._plottp(self._data) 990 1040 if self._minmaxy is not None: … … 1052 1102 # end matplotlib.Figure.text forwarding function 1053 1103 1104 1105 # printing header information 1106 def print_header(self, plot=True, fontsize=9, logger=False, selstr='', extrastr=''): 1107 """ 1108 print data (scantable) header on the plot and/or logger. 1109 Parameters: 1110 plot: whether or not print header info on the plot. 1111 fontsize: header font size (valid only plot=True) 1112 autoscale: whether or not autoscale the plot (valid only plot=True) 1113 logger: whether or not print header info on the logger. 1114 selstr: additional selection string (not verified) 1115 extrastr: additional string to print (not verified) 1116 """ 1117 if not plot and not logger: return 1118 if not self._data: raise RuntimeError("No scantable has been set yet.") 1119 # Now header will be printed on plot and/or logger. 1120 # Get header information and format it. 1121 ssum=self._data.__str__() 1122 # Print Observation header to the upper-left corner of plot 1123 if plot: 1124 srest=ssum[ssum.find('Rest Freqs:'):ssum.find('Abcissa:')] 1125 shead=ssum[ssum.find('Beams:'):ssum.find('Flux Unit:')] 1126 headstr=shead.split('\n\n') 1127 if extrastr != '': headstr[1]=extrastr+'\n'+headstr[1] 1128 #headstr[1]='Data File: '+(filestr or 'unknown')+'\n'+headstr[1] 1129 headstr[0]=headstr[0]+'\n'+srest 1130 headstr.reverse() 1131 ssel='***Selections***\n'+(selstr+self._data.get_selection().__str__() or 'none') 1132 headstr.append(ssel) 1133 nstcol=len(headstr) 1134 1135 self._plotter.hold() 1136 for i in range(nstcol): 1137 self._plotter.figure.text(0.03+float(i)/nstcol,0.98, 1138 headstr[i], 1139 horizontalalignment='left', 1140 verticalalignment='top', 1141 fontsize=fontsize) 1142 import time 1143 self._plotter.figure.text(0.99,0.0, 1144 time.strftime("%a %d %b %Y %H:%M:%S %Z"), 1145 horizontalalignment='right', 1146 verticalalignment='bottom',fontsize=8) 1147 self._plotter.release() 1148 del srest, shead, headstr, ssel 1149 if logger: 1150 asaplog.push("----------------\n Plot Summary\n----------------") 1151 asaplog.push(extrastr) 1152 asaplog.push(ssum[ssum.find('Beams:'):]) 1153 print_log() 1154 del ssum
Note:
See TracChangeset
for help on using the changeset viewer.