Changeset 618


Ignore:
Timestamp:
05/05/05 12:08:27 (19 years ago)
Author:
mar637
Message:
  • Fixes for multipaneling labelling and layout
  • reworked set_limits.
  • support auto location for legend in matplotlib 0.8
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Release-1-fixes/python/asaplot.py

    r491 r618  
    6565        self.colours = [1, 'b', 'g', 'r', 'c', 'm', 'y', 'k']
    6666        self.attributes = {}
    67         self.loc = 1
     67        self.loc = 0
    6868
    6969        matplotlib.interactive = True
     
    8080        for i in range(1,len(self.lines)+1):
    8181           self.delete(i)
    82 
    8382        self.axes.clear()
    8483        self.colours[0] = 1
     
    103102                        line.set_linestyle('None')
    104103                        self.lines[number] = None
    105 
    106         self.show()
    107 
     104        self.show()       
    108105
    109106    def get_line(self):
     
    150147
    151148
    152     def legend(self, loc=1):
     149    def legend(self, loc=None):
    153150        """
    154151        Add a legend to the plot.
     
    167164
    168165        """
    169         if 1 > loc > 10: loc = 0
    170         self.loc = loc
     166        if isinstance(loc,int):
     167            if 0 > loc > 10: loc = 0
     168            self.loc = loc
    171169        self.show()
    172170
     
    512510        ylim = [ymin, ymax] as in axes.set_ylim().
    513511        """
    514 
    515512        for s in self.subplots:
    516513            self.axes  = s['axes']
    517514            self.lines = s['lines']
    518             if xlim is not None:
    519                 self.axes.set_xlim(xlim)
    520             if ylim is not None:
    521                 self.axes.set_ylim(ylim)
    522         return
     515            oldxlim =  list(self.axes.get_xlim())
     516            oldylim =  list(self.axes.get_ylim())
     517            if xlim is not None:
     518                for i in range(len(xlim)):
     519                    if xlim[i] is not None:
     520                        oldxlim[i] = xlim[i]
     521            if ylim is not None:                       
     522                for i in range(len(ylim)):
     523                    if ylim[i] is not None:
     524                        oldylim[i] = ylim[i]
     525            self.axes.set_xlim(oldxlim)
     526            self.axes.set_ylim(oldylim)
     527        return
    523528
    524529
     
    568573
    569574
    570     def set_panels(self, rows=1, cols=0, n=-1, nplots=-1):
     575    def set_panels(self, rows=1, cols=0, n=-1, nplots=-1, ganged=True):
    571576        """
    572577        Set the panel layout.
     
    626631                                                cols, i+1)
    627632                self.subplots[i]['lines'] = []
    628 
    629                 if rows > 1 or cols > 1:
    630                     # Squeeze the plots together.
    631                     pos = self.subplots[i]['axes'].get_position()
    632                     if cols > 1: pos[2] *= 1.1
    633                     if rows > 1: pos[3] *= 1.1
    634                     self.subplots[i]['axes'].set_position(pos)
    635 
    636                 # Suppress tick labelling for interior subplots.
    637                 if i <= (rows-1)*cols - 1:
    638                     # Suppress x-labels for frames not in the bottom row.
    639                     for tick in self.subplots[i]['axes'].xaxis.majorTicks:
    640                         tick.label1On = False
    641 
    642                 if i%cols:
    643                     # Suppress y-labels for frames not in the left column.
    644                     for tick in self.subplots[i]['axes'].yaxis.majorTicks:
    645                         tick.label1On = False
     633                xfsize = self.subplots[i]['axes'].xaxis.label.get_size()-cols/2
     634                yfsize = self.subplots[i]['axes'].yaxis.label.get_size()-rows/2
     635                self.subplots[i]['axes'].xaxis.label.set_size(xfsize)
     636                self.subplots[i]['axes'].yaxis.label.set_size(yfsize)
     637               
     638                if ganged:
     639                    if rows > 1 or cols > 1:
     640                        # Squeeze the plots together.
     641                        pos = self.subplots[i]['axes'].get_position()
     642                        if cols > 1: pos[2] *= 1.2
     643                        if rows > 1: pos[3] *= 1.2
     644                        self.subplots[i]['axes'].set_position(pos)
     645
     646                    # Suppress tick labelling for interior subplots.
     647                    if i <= (rows-1)*cols - 1:
     648                        if i+cols < nplots:
     649                            # Suppress x-labels for frames width
     650                            # adjacent frames
     651                            for tick in \
     652                                    self.subplots[i]['axes'].xaxis.majorTicks:
     653                                tick.label1On = False
     654                                self.subplots[i]['axes'].xaxis.label.set_visible(False)
     655                    if i%cols:
     656                        # Suppress y-labels for frames not in the left column.
     657                        for tick in self.subplots[i]['axes'].yaxis.majorTicks:
     658                            tick.label1On = False
     659                        self.subplots[i]['axes'].yaxis.label.set_visible(False)
     660                       
    646661
    647662                self.rows = rows
     
    650665            self.subplot(0)
    651666
    652 
    653667    def set_title(self, title=None):
    654668        """
     
    667681        """
    668682        if not self.buffering:
    669             if self.loc:
     683            if self.loc is not None:
    670684                for j in range(len(self.subplots)):
    671685                    lines  = []
     
    691705            self.canvas.show()
    692706
    693 
    694707    def subplot(self, i=None, inc=None):
    695708        """
Note: See TracChangeset for help on using the changeset viewer.