Changeset 1025


Ignore:
Timestamp:
04/20/06 16:47:00 (18 years ago)
Author:
mar637
Message:

a stab at making axis ticks and labels scale in multipanelling. Reverted the version depend save addition.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asaplotbase.py

    r1023 r1025  
    1313from matplotlib import rc, rcParams
    1414from asap import rcParams as asaprcParams
    15 
    1615from matplotlib.ticker import ScalarFormatter
    1716from matplotlib.ticker import NullLocator
     
    1918class MyFormatter(ScalarFormatter):
    2019    def __call__(self, x, pos=None):
    21         last = len(self.locs)-2
    22         if pos==last:
    23             print "Diabling tick no " , pos, last
    24             return ''  # pos=-1 is the last tick
     20        #last = len(self.locs)-2
     21        if pos==0:
     22            return ''
    2523        else: return ScalarFormatter.__call__(self, x, pos)
    2624
     
    206204        The argument list works a bit like the matlab plot() function.
    207205        """
    208 
    209206        if x is None:
    210207            if y is None: return
     
    215212            x = range(len(y))
    216213
     214        ax = self.axes
     215        s = ax.title.get_size()
     216        tsize = s-(self.cols+self.rows)/2
     217        ax.title.set_size(tsize)
     218        origx = rcParams['xtick.labelsize']
     219        origy = rcParams['ytick.labelsize']
     220        if self.cols > 1:
     221            xfsize = origx-(self.cols)/2
     222            #rc('xtick',labelsize=xfsize)
     223            ax.xaxis.label.set_size(xfsize)
     224        if self.rows > 1:
     225            yfsize = origy-(self.rows)/2
     226            #rc('ytick',labelsize=yfsize)
     227            ax.yaxis.label.set_size(yfsize)
    217228        if mask is None:
    218229            if fmt is None:
     
    238249
    239250            line = self.axes.plot(*segments)
     251        #rc('xtick',labelsize=origx)
     252        #rc('ytick',labelsize=origy)
     253
    240254        # Add to an existing line?
    241255        if add is None or len(self.lines) < add < 0:
     
    425439                        else:
    426440                            orientation = 'portrait'
    427                     # hack to circument ps bug in eraly versions of mpl
    428                     if int(mv.split(".")[1]) < 86:
    429                         a4w = 8.25
    430                         a4h = 11.25
    431                         ds = None
    432                         if orientation == 'landscape':
    433                             ds = min(a4h/w,a4w/h)
    434                         else:
    435                             ds = min(a4w/w,a4h/h)
    436                         ow = ds * w
    437                         oh = ds * h
    438                         self.figure.set_figsize_inches((ow,oh))
    439                     self.canvas.print_figure(fname,orientation=orientation)
     441                    a4w = 8.25
     442                    a4h = 11.25
     443                    ds = None
     444                    if orientation == 'landscape':
     445                        ds = min(a4h/w,a4w/h)
     446                    else:
     447                        ds = min(a4w/w,a4h/h)
     448                    ow = ds * w
     449                    oh = ds * h
     450                    self.figure.set_figsize_inches((ow,oh))
     451                    self.figure.savefig(fname, orientation=orientation,
     452                                        papertype="a4")
     453                    # reset the figure size
     454                    self.figure.set_figsize_inches((w,h))
    440455                    print 'Written file %s' % (fname)
    441456                else:
    442457                    if dpi is None:
    443458                        dpi =150
    444                     self.canvas.print_figure(fname,dpi=dpi)
     459                    self.figure.savefig(fname,dpi=dpi)
    445460                    print 'Written file %s' % (fname)
    446461            except IOError, msg:
     
    470485
    471486        getattr(self.axes, "set_%s"%what)(*args, **newargs)
    472         s = self.axes.title.get_size()
    473         tsize = s-(self.cols+self.rows)/2-1
    474         self.axes.title.set_size(tsize)
    475         if self.cols > 1:
    476             xfsize = self.axes.xaxis.label.get_size()-(self.cols+1)/2
    477             self.axes.xaxis.label.set_size(xfsize)
    478         if self.rows > 1:
    479             yfsize = self.axes.yaxis.label.get_size()-(self.rows+1)/2
    480             self.axes.yaxis.label.set_size(yfsize)
    481487
    482488        self.show()
     
    623629            if nplots < 1 or rows*cols < nplots:
    624630                nplots = rows*cols
    625 
     631            if ganged:
     632                hsp,wsp = None,None
     633                if rows > 1: hsp = 0.0001
     634                if cols > 1: wsp = 0.0001
     635                self.figure.subplots_adjust(wspace=wsp,hspace=hsp)
    626636            for i in range(nplots):
    627637                self.subplots.append({})
    628 
    629                 self.subplots[i]['axes']  = self.figure.add_subplot(rows,
     638                self.subplots[i]['axes'] = self.figure.add_subplot(rows,
    630639                                                cols, i+1)
    631640                self.subplots[i]['lines'] = []
    632641
    633642                if ganged:
    634                     if rows > 1 or cols > 1:
    635                         # Squeeze the plots together.
    636                         pos = self.subplots[i]['axes'].get_position()
    637                         if cols > 1: pos[2] *= 1.2
    638                         if rows > 1: pos[3] *= 1.2
    639                         self.subplots[i]['axes'].set_position(pos)
    640 
    641643                    # Suppress tick labelling for interior subplots.
    642644                    if i <= (rows-1)*cols - 1:
     
    651653                            tick.label1On = False
    652654                        self.subplots[i]['axes'].yaxis.label.set_visible(False)
    653                     if (i+1)%cols:
     655                    # disable the first tick of [1:ncol-1] of the last row
     656                    if (nplots-cols) < i <= nplots-1:
    654657                        self.subplots[i]['axes'].xaxis.set_major_formatter(MyFormatter())
    655658                self.rows = rows
    656659                self.cols = cols
    657 
    658660            self.subplot(0)
    659661
Note: See TracChangeset for help on using the changeset viewer.