Changeset 1723


Ignore:
Timestamp:
04/20/10 18:38:20 (14 years ago)
Author:
Kana Sugimoto
Message:

New Development: No

JIRA Issue: Yes (CAS-1801, CAS-2064)

Ready to Release: Yes

Interface Changes: Yes

What Interface Changed:
Three methods, print_headder(), set_panellayout() and _reset_panellayout()
are added to the class asapplotter.
A parameter layout (list) is added to set_layout() in asaplotbase class.

Test Programs: run sdplot with header & plotstyle=True + layout parameter set.

Put in Release Notes: Yes

Module(s): sdplot() task.

Description:

  1. asapplotter.print_header(plot=True, fontsize=9, logger=False, selstr=, extrastr=): prints scantable header on the plot and/or logger (see help doc for parameter details). Note that the header information will not overlayed to the plot by plotazel() and plotpointing().
  2. set_panellayout(layout=[],refresh=True): sets the layout of subplots. layout is a list of subplots layout in figure coordinate (0-1) in order of [left, bottom, right, top, horizontal space btw panels, vertical space btw panels]
  3. _reset_panellayout(): resets the layout of subplots to matplotlib rc value.
  4. a member variable 'asapplotter._panellayout' (list) is specified to store layout values.


Location:
branches/alma/python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/alma/python/asaplotbase.py

    r1717 r1723  
    570570
    571571
    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):
    573574        """
    574575        Set the panel layout.
     
    593594            self.set_title()
    594595
     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
    595602        if rows < 1: rows = 1
    596603
     
    605612        if 0 <= n < rows*cols:
    606613            i = len(self.subplots)
     614
    607615            self.subplots.append({})
    608616
     
    666674                self.cols = cols
    667675            self.subplot(0)
     676        del rows,cols,n,nplots,layout,ganged,i
    668677
    669678    def tidy(self):
  • branches/alma/python/asapplotter.py

    r1714 r1723  
    3939        self._selection = selector()
    4040        self._hist = rcParams['plotter.histogram']
     41        self._panellayout = self.set_panellayout(refresh=False)
    4142
    4243    def _translate(self, instr):
     
    476477            rcp('font', size=size)
    477478        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)
    478508
    479509    def plot_lines(self, linecat=None, doppler=0.0, deltachan=10, rotate=90.0,
     
    693723                n = min(n,self._rows*self._cols)
    694724                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)
    696727            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)
    698730        else:
    699             self._plotter.set_panels()
     731#            self._plotter.set_panels()
     732            self._plotter.set_panels(layout=self._panellayout)
    700733        r=0
    701734        nr = scan.nrow()
     
    856889        #PL.ioff()
    857890        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       
    858897        tdel = max(t) - min(t)
    859898        ax = PL.subplot(2,1,1)
     
    942981        #PL.ioff()
    943982        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)
    944988        ax = PL.axes([0.1,0.1,0.8,0.8])
    945989        ax = PL.axes([0.1,0.1,0.8,0.8])
     
    9871031        #    self._abcunit = self._data.get_unit()
    9881032        #    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)
    9891039        self._plottp(self._data)
    9901040        if self._minmaxy is not None:
     
    10521102    # end matplotlib.Figure.text forwarding function
    10531103
     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.