Changeset 1101


Ignore:
Timestamp:
08/02/06 09:35:30 (18 years ago)
Author:
mar637
Message:

added default legend font size; added proper raise for wrong argument; fixed bug in set_range/slice indexing; added user defined fonts and sizes ( Ticket #56 )

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapplotter.py

    r1096 r1101  
    3838        self._selection = selector()
    3939        self._hist = rcParams['plotter.histogram']
     40        from matplotlib import rc as mplrc
     41        mplrc('legend',fontsize=8)
    4042
    4143    def _translate(self, instr):
     
    7274        from asap import scantable
    7375        if not self._data and not scan:
    74             print "please provide a scantable to plot"
     76            msg = "Input is not a scantable"
     77            if rcParams['verbose']:
     78                print msg
     79                return
     80            raise TypeError(msg)
    7581        if isinstance(scan, scantable):
    7682            if self._data is not None:
     
    181187        return
    182188
    183     def set_legend(self, mp=None, mode = 0):
     189    def set_legend(self, mp=None, fontsize = None, mode = 0):
    184190        """
    185191        Specify a mapping for the legend instead of using the default
    186192        indices:
    187193        Parameters:
    188             mp:    a list of 'strings'. This should have the same length
    189                     as the number of elements on the legend and then maps
    190                     to the indeces in order. It is possible to uses latex
    191                     math expression. These have to be enclosed in r'', e.g. r'$x^{2}$'
    192             mode:   where to display the legend
    193                     Any other value for loc else disables the legend:
     194            mp:        a list of 'strings'. This should have the same length
     195                       as the number of elements on the legend and then maps
     196                       to the indeces in order. It is possible to uses latex
     197                       math expression. These have to be enclosed in r'',
     198                       e.g. r'$x^{2}$'
     199            fontsize:  The font size of the label (default None)
     200            mode:      where to display the legend
     201                       Any other value for loc else disables the legend:
    194202                        0: auto
    195203                        1: upper right
     
    214222        self._lmap = mp
    215223        self._plotter.legend(mode)
     224        if isinstance(fontsize, int):
     225            from matplotlib import rc as rcp
     226            rcp('legend', fontsize=fontsize)
    216227        if self._data:
    217228            self.plot(self._data)
    218229        return
    219230
    220     def set_title(self, title=None):
     231    def set_title(self, title=None, fontsize=None):
    221232        """
    222233        Set the title of the plot. If multiple panels are plotted,
     
    227238        """
    228239        self._title = title
    229         if self._data: self.plot(self._data)
    230         return
    231 
    232     def set_ordinate(self, ordinate=None):
     240        if isinstance(fontsize, int):
     241            from matplotlib import rc as rcp
     242            rcp('axes', titlesize=fontsize)
     243        if self._data: self.plot(self._data)
     244        return
     245
     246    def set_ordinate(self, ordinate=None, fontsize=None):
    233247        """
    234248        Set the y-axis label of the plot. If multiple panels are plotted,
     
    242256        """
    243257        self._ordinate = ordinate
    244         if self._data: self.plot(self._data)
    245         return
    246 
    247     def set_abcissa(self, abcissa=None):
     258        if isinstance(fontsize, int):
     259            from matplotlib import rc as rcp
     260            rcp('axes', labelsize=fontsize)
     261            rcp('ytick', labelsize=fontsize)
     262        if self._data: self.plot(self._data)
     263        return
     264
     265    def set_abcissa(self, abcissa=None, fontsize=None):
    248266        """
    249267        Set the x-axis label of the plot. If multiple panels are plotted,
     
    257275        """
    258276        self._abcissa = abcissa
     277        if isinstance(fontsize, int):
     278            from matplotlib import rc as rcp
     279            rcp('axes', labelsize=fontsize)
     280            rcp('xtick', labelsize=fontsize)
    259281        if self._data: self.plot(self._data)
    260282        return
     
    277299        if self._data: self.plot(self._data)
    278300
    279     def set_histogram(self, hist=True):
     301    def set_histogram(self, hist=True, linewidth=None):
    280302        """
    281303        Enable/Disable histogram-like plotting.
     
    286308        """
    287309        self._hist = hist
    288         if self._data: self.plot(self._data)
    289 
    290     def set_linestyles(self, linestyles):
     310        if isinstance(linewidth, float) or isinstance(linewidth, int):
     311            from matplotlib import rc as rcp
     312            rcp('lines', linewidth=linewidth)
     313        if self._data: self.plot(self._data)
     314
     315    def set_linestyles(self, linestyles=None, linewidth=None):
    291316        """
    292317        Set the linestyles to be used. The plotter will cycle through
     
    309334            linestyles = linestyles.split()
    310335        self._plotter.palette(color=0,linestyle=0,linestyles=linestyles)
     336        if isinstance(linewidth, float) or isinstance(linewidth, int):
     337            from matplotlib import rc as rcp
     338            rcp('lines', linewidth=linewidth)
     339        if self._data: self.plot(self._data)
     340
     341    def set_font(self, family=None, style=None, weight=None, size=None):
     342        """
     343        Set font properties.
     344        Parameters:
     345            family:    one of 'sans-serif', 'serif', 'cursive', 'fantasy', 'monospace'
     346            style:     one of 'normal' (or 'roman'), 'italic'  or 'oblique'
     347            weight:    one of 'normal or 'bold'
     348            size:      the 'general' font size, individual elements can be adjusted
     349                       seperately
     350        """
     351        from matplotlib import rc as rcp
     352        if isinstance(family, str):
     353            rcp('font', family=family)
     354        if isinstance(style, str):
     355            rcp('font', style=style)
     356        if isinstance(weight, str):
     357            rcp('font', weight=weight)
     358        if isinstance(size, float) or isinstance(size, int):
     359            rcp('font', size=size)
    311360        if self._data: self.plot(self._data)
    312361
     
    379428            inc = -1
    380429        # find min index
    381         while data[start] < mn:
     430        while start > 0 and data[start] < mn:
    382431            start+= inc
    383432        # find max index
    384         while data[end] > mx:
     433        while end > 0 and data[end] > mx:
    385434            end-=inc
    386         end +=1
     435        if end > 0: end +=1
    387436        if start > end:
    388437            return end,start
     
    491540                plotit = self._plotter.plot
    492541                if self._hist: plotit = self._plotter.hist
    493                 plotit(x,y)
     542                if len(x) > 0: plotit(x,y)
    494543                xlim= self._minmaxx or [min(x),max(x)]
    495544                allxlim += xlim
Note: See TracChangeset for help on using the changeset viewer.