Ignore:
Timestamp:
12/08/04 12:17:15 (19 years ago)
Author:
cal103
Message:

Added a histogram plotting function hist(); modified subplot() so that an
increment may be specified.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asaplot.py

    r118 r119  
    3131        """
    3232        Create a new instance of the ASAPlot plotting class.
     33
     34        If rows < 1 then a separate call to set_panels() is required to define
     35        the panel layout; refer to the doctext for set_panels().
    3336        """
    3437        self.window = Tk.Tk()
     
    101104        """
    102105        return self.attributes
     106
     107
     108    def hist(self, x=None, y=None, fmt=None):
     109        """
     110        Plot a histogram.  N.B. the x values refer to the start of the
     111        histogram bin.
     112
     113        fmt is the line style as in plot().
     114        """
     115
     116        if x is None:
     117            if y is None: return
     118            x = range(0,len(y))
     119
     120        if len(x) != len(y):
     121            return
     122
     123        l2 = 2*len(x)
     124        x2 = range(0,l2)
     125        y2 = range(0,l2)
     126
     127        for i in range(0,l2):
     128            x2[i] = x[i/2]
     129
     130        y2[0] = 0
     131        for i in range(1,l2):
     132            y2[i] = y[(i-1)/2]
     133
     134        self.plot(x2, y2, fmt)
    103135
    104136
     
    230262        # Add to an existing line?
    231263        if add is None or len(self.lines) < add < 0:
     264            # Don't add.
    232265            self.lines.append(line)
    233266            i = len(self.lines) - 1
     
    406439            self.subplots[i]['lines'] = []
    407440
    408             if i == 0: self.subplot()
     441            if i == 0: self.subplot(0)
    409442
    410443        else:
     
    416449                self.subplots[i]['lines'] = []
    417450
    418             self.subplot()
     451            self.subplot(0)
    419452
    420453
     
    457490
    458491
    459     def subplot(self, i=0):
     492    def subplot(self, i=None, inc=None):
    460493        """
    461494        Set the subplot to the 0-relative panel number as defined by one or
     
    464497        l = len(self.subplots)
    465498        if l:
    466             i = i%l
    467             self.axes  = self.subplots[i]['axes']
    468             self.lines = self.subplots[i]['lines']
     499            if i is not None:
     500                self.i = i
     501
     502            if inc is not None:
     503                self.i += inc
     504
     505            self.i %= l
     506            self.axes  = self.subplots[self.i]['axes']
     507            self.lines = self.subplots[self.i]['lines']
    469508
    470509
Note: See TracChangeset for help on using the changeset viewer.