Changeset 1147


Ignore:
Timestamp:
08/16/06 11:36:23 (18 years ago)
Author:
mar637
Message:

added linecatalog plotting; soem font scaling fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asaplotbase.py

    r1100 r1147  
    99
    1010from matplotlib.figure import Figure, Text
    11 from matplotlib.font_manager import FontProperties
     11from matplotlib.font_manager import FontProperties as FP
    1212from matplotlib.numerix import sqrt
    1313from matplotlib import rc, rcParams
     
    1515from matplotlib.ticker import ScalarFormatter
    1616from matplotlib.ticker import NullLocator
     17from matplotlib.transforms import blend_xy_sep_transform
     18
    1719if int(matplotlib.__version__.split(".")[1]) < 87:
    1820    print "Warning: matplotlib version < 0.87. This might cause errors. Please upgrade."
     
    8284    def clear(self):
    8385        """
    84         Delete all lines from the plot.  Line numbering will restart from 1.
     86        Delete all lines from the plot.  Line numbering will restart from 0.
    8587        """
    8688
     
    410412
    411413                    if orientation is None:
    412                         # auto oriented
     414                        # oriented
    413415                        if w > h:
    414416                            orientation = 'landscape'
     
    666668
    667669                    if len(lines):
     670                        fp = FP(size=rcParams['legend.fontsize'])
     671                        fsz = fp.get_size_in_points() - len(lines)
     672                        fp.set_size(max(fsz,6))
    668673                        sp['axes'].legend(tuple(lines), tuple(labels),
    669                                           self.loc)
    670 ##                                           ,prop=FontProperties(size=lsiz) )
     674                                          self.loc, prop=fp)
    671675                    else:
    672676                        sp['axes'].legend((' '))
    673677
    674678            from matplotlib.artist import setp
    675             xts = rcParams['xtick.labelsize']-(self.cols)/2
    676             yts = rcParams['ytick.labelsize']-(self.rows)/2
     679            fp = FP(size=rcParams['xtick.labelsize'])
     680            xts = fp.get_size_in_points()- (self.cols)/2
     681            fp = FP(size=rcParams['ytick.labelsize'])
     682            yts = fp.get_size_in_points() - (self.rows)/2
    677683            for sp in self.subplots:
    678684                ax = sp['axes']
     
    680686                tsize = s-(self.cols+self.rows)
    681687                ax.title.set_size(tsize)
     688                fp = FP(size=rcParams['axes.labelsize'])
    682689                setp(ax.get_xticklabels(), fontsize=xts)
    683690                setp(ax.get_yticklabels(), fontsize=yts)
    684                 origx = rcParams['axes.labelsize'] #ax.xaxis.label.get_size()
    685                 origy = rcParams['axes.labelsize'] #ax.yaxis.label.get_size()
     691                origx =  fp.get_size_in_points()
     692                origy = origx
    686693                off = 0
    687694                if self.cols > 1: off = self.cols
    688695                xfsize = origx-off
    689                 #rc('xtick',labelsize=xfsize)
    690696                ax.xaxis.label.set_size(xfsize)
    691697                off = 0
    692698                if self.rows > 1: off = self.rows
    693699                yfsize = origy-off
    694                 #rc('ytick',labelsize=yfsize)
    695700                ax.yaxis.label.set_size(yfsize)
    696701
     
    712717            self.lines = self.subplots[self.i]['lines']
    713718
    714 
    715719    def text(self, *args, **kwargs):
    716720        """
     
    719723        self.figure.text(*args, **kwargs)
    720724        self.show()
     725
     726    def vline_with_label(self, x, y, label,
     727                         location='bottom', rotate=0.0, **kwargs):
     728        """
     729        Plot a vertical line with label.
     730        It takes "world" values fo x and y.
     731        """
     732        ax = self.axes
     733        # need this to suppress autoscaling during this function
     734        self.axes.set_autoscale_on(False)
     735        ymin = 0.0
     736        ymax = 1.0
     737        valign = 'center'
     738        if location.lower() == 'top':
     739            y = max(0.0, y)
     740        elif location.lower() == 'bottom':
     741            y = min(0.0, y)
     742        lbloffset = 0.06
     743        # a rough estimate for the bb of the text
     744        if rotate > 0.0: lbloffset = 0.03*len(label)
     745        peakoffset = 0.01
     746        xy0 = ax.transData.xy_tup((x,y))
     747        # get relative coords
     748        xy = ax.transAxes.inverse_xy_tup(xy0)
     749        if location.lower() == 'top':
     750            ymax = 1.0-lbloffset
     751            ymin = xy[1]+peakoffset
     752            valign = 'bottom'
     753            ylbl = ymax+0.01
     754        elif location.lower() == 'bottom':
     755            ymin = lbloffset
     756            ymax = xy[1]-peakoffset
     757            valign = 'top'
     758            ylbl = ymin-0.01
     759        trans = blend_xy_sep_transform(ax.transData, ax.transAxes)
     760        l = ax.axvline(x, ymin, ymax, color='black', **kwargs)
     761        t = ax.text(x, ylbl ,label, verticalalignment=valign,
     762                                    horizontalalignment='center',
     763                    rotation=rotate,transform = trans)
     764        self.axes.set_autoscale_on(True)
Note: See TracChangeset for help on using the changeset viewer.