Ignore:
Timestamp:
08/21/06 10:48:45 (18 years ago)
Author:
mar637
Message:

lots of changes to support soft refresh, for things like text overlays, linecatlogs etc. reworked plot_lines to to auto-peak detection. added forwarding functions to matplotlib.axes. drawing functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapplotter.py

    r1148 r1153  
    11from asap import rcParams, print_log, selector
    22from asap import NUM
     3import matplotlib.axes
    34
    45class asapplotter:
     
    9596            self._plotter.set_limits(ylim=self._minmaxy)
    9697        self._plotter.release()
     98        self._plotter.tidy()
     99        self._plotter.show(hardrefresh=False)
    97100        print_log()
    98101        return
     102
     103
     104    # forwards to matplotlib axes
     105    def text(self, *args, **kwargs):
     106        self._axes_callback("text", *args, **kwargs)
     107    text. __doc__ = matplotlib.axes.Axes.text.__doc__
     108    def arrow(self, *args, **kwargs):
     109        self._axes_callback("arrow", *args, **kwargs)
     110    arrow. __doc__ = matplotlib.axes.Axes.arrow.__doc__
     111    def axvline(self, *args, **kwargs):
     112        self._axes_callback("axvline", *args, **kwargs)
     113    axvline. __doc__ = matplotlib.axes.Axes.axvline.__doc__
     114    def axhline(self, *args, **kwargs):
     115        self._axes_callback("axhline", *args, **kwargs)
     116    axhline. __doc__ = matplotlib.axes.Axes.axhline.__doc__
     117    def axvspan(self, *args, **kwargs):
     118        self._axes_callback("axvspan", *args, **kwargs)
     119        # hack to preventy mpl from redrawing the patch
     120        # it seem to convert the patch into lines on every draw.
     121        # This doesn't happen in a test script???
     122        del self._plotter.axes.patches[-1]
     123    axvspan. __doc__ = matplotlib.axes.Axes.axvspan.__doc__
     124    def axhspan(self, *args, **kwargs):
     125        self._axes_callback("ahvspan", *args, **kwargs)
     126        # hack to preventy mpl from redrawing the patch
     127        # it seem to convert the patch into lines on every draw.
     128        # This doesn't happen in a test script???
     129        del self._plotter.axes.patches[-1]
     130    axhspan. __doc__ = matplotlib.axes.Axes.axhspan.__doc__
     131
     132    def _axes_callback(self, axesfunc, *args, **kwargs):
     133        panel = 0
     134        if kwargs.has_key("panel"):
     135            panel = kwargs.pop("panel")
     136        coords = None
     137        if kwargs.has_key("coords"):
     138            coords = kwargs.pop("coords")
     139            if coords.lower() == 'world':
     140                kwargs["transform"] = self._plotter.axes.transData
     141            elif coords.lower() == 'relative':
     142                kwargs["transform"] = self._plotter.axes.transAxes
     143        self._plotter.subplot(panel)
     144        self._plotter.axes.set_autoscale_on(False)
     145        getattr(self._plotter.axes, axesfunc)(*args, **kwargs)
     146        self._plotter.show(False)
     147        self._plotter.axes.set_autoscale_on(True)
     148    # end matplotlib.axes fowarding functions
    99149
    100150    def set_mode(self, stacking=None, panelling=None):
     
    357407        if self._data: self.plot(self._data)
    358408
    359     def plot_lines(self, linecat=None, offset=0.0, peak=5.0, rotate=0.0,
     409    def plot_lines(self, linecat=None, offset=0.0, deltachan=10, rotate=0.0,
    360410                   location=None):
    361411        """
     
    365415        if not isinstance(linecat, linecatalog): return
    366416        if not self._data.get_unit().endswith("GHz"): return
    367         self._plotter.hold()
     417        #self._plotter.hold()
     418        from matplotlib.numerix import ma
    368419        for j in range(len(self._plotter.subplots)):
    369420            self._plotter.subplot(j)
    370421            lims = self._plotter.axes.get_xlim()
    371             for i in range(linecat.nrow()):
    372                 freq = linecat.get_frequency(i)/1000.0 + offset
     422            for row in range(linecat.nrow()):
     423                freq = linecat.get_frequency(row)/1000.0 + offset
    373424                if lims[0] < freq < lims[1]:
    374425                    if location is None:
    375426                        loc = 'bottom'
    376                         if i%2: loc='top'
     427                        if row%2: loc='top'
    377428                    else: loc = location
    378                     self._plotter.vline_with_label(freq, peak, linecat.get_name(i),
     429                    maxys = []
     430                    for line in self._plotter.axes.lines:
     431                        v = line._x
     432                        asc = v[0] < v[-1]
     433
     434                        idx = None
     435                        if not asc:
     436                            if v[len(v)-1] <= freq <= v[0]:
     437                                i = len(v)-1
     438                                while i>=0 and v[i] < freq:
     439                                    idx = i
     440                                    i-=1
     441                        else:
     442                           if v[0] <= freq <= v[len(v)-1]:
     443                                i = 0
     444                                while  i<len(v) and v[i] < freq:
     445                                    idx = i
     446                                    i+=1
     447                        if idx is not None:
     448                            lower = idx - deltachan
     449                            upper = idx + deltachan
     450                            if lower < 0: lower = 0
     451                            if upper > len(v): upper = len(v)
     452                            s = slice(lower, upper)
     453                            y = line._y_orig[s]
     454                            maxys.append(ma.maximum(y))
     455                    peak = max(maxys)
     456                    self._plotter.vline_with_label(freq, peak, linecat.get_name(row),
    379457                                             location=loc, rotate=rotate)
    380         self._plotter.release()
     458        #        self._plotter.release()
     459        self._plotter.show(hardrefresh=False)
     460
    381461
    382462    def save(self, filename=None, orientation=None, dpi=None):
     
    619699
    620700    def _get_label(self, scan, row, mode, userlabel=None):
     701        if isinstance(userlabel, list) and len(userlabel) == 0:
     702            userlabel = " "
    621703        pms = dict(zip(self._selection.get_pols(),self._selection.get_poltypes()))
    622704        if len(pms):
     
    630712             't': scan._gettime(row) }
    631713        return userlabel or d[mode]
     714
Note: See TracChangeset for help on using the changeset viewer.