Changeset 1547


Ignore:
Timestamp:
03/27/09 15:59:45 (15 years ago)
Author:
Malte Marquarding
Message:

add interactive annotation capability. Also allow creation of masks interactively

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapplotter.py

    r1391 r1547  
    1 from asap import rcParams, print_log, selector
     1from asap import rcParams, print_log, selector, scantable
    22import matplotlib.axes
    33import re
     
    101101        return
    102102
     103    def create_mask(self, **kwargs):
     104        nwindows = 1
     105        if kwargs.has_key("nwindows"):
     106            nwindows = kwargs.pop("nwindows")
     107        outmask = []
     108        for w in xrange(nwindows):
     109            wpos = []
     110            wpos.append(self._plotter.get_point()[0])
     111            self.axvline(wpos[0], **kwargs)
     112            wpos.append(self._plotter.get_point()[0])
     113            del self._plotter.axes.lines[-1]
     114            kwargs["alpha"] = 0.1
     115            self.axvspan(wpos[0], wpos[1], **kwargs)
     116            outmask.append(wpos)
     117        return self._data.create_mask(*outmask)
    103118
    104119    # forwards to matplotlib axes
    105120    def text(self, *args, **kwargs):
     121        if kwargs.has_key("interactive"):
     122            if kwargs.pop("interactive"):
     123                pos = self._plotter.get_point()
     124                args = tuple(pos)+args
    106125        self._axes_callback("text", *args, **kwargs)
     126
    107127    text.__doc__ = matplotlib.axes.Axes.text.__doc__
    108128    def arrow(self, *args, **kwargs):
     129        if kwargs.has_key("interactive"):
     130            if kwargs.pop("interactive"):
     131                pos = self._plotter.get_region()
     132                dpos = (pos[0][0], pos[0][1],
     133                        pos[1][0]-pos[0][0],
     134                        pos[1][1] - pos[0][1])
     135                args = dpos + args
    109136        self._axes_callback("arrow", *args, **kwargs)
     137
    110138    arrow.__doc__ = matplotlib.axes.Axes.arrow.__doc__
    111139    def axvline(self, *args, **kwargs):
     140        if kwargs.has_key("interactive"):
     141            if kwargs.pop("interactive"):
     142                pos = self._plotter.get_point()
     143                args = (pos[0],)+args
    112144        self._axes_callback("axvline", *args, **kwargs)
    113145    axvline.__doc__ = matplotlib.axes.Axes.axvline.__doc__
     146
    114147    def axhline(self, *args, **kwargs):
     148        if kwargs.has_key("interactive"):
     149            if kwargs.pop("interactive"):
     150                pos = self._plotter.get_point()
     151                args = (pos[1],)+args
    115152        self._axes_callback("axhline", *args, **kwargs)
    116153    axhline.__doc__ = matplotlib.axes.Axes.axhline.__doc__
     154
    117155    def axvspan(self, *args, **kwargs):
     156        if kwargs.has_key("interactive"):
     157            if kwargs.pop("interactive"):
     158                pos = self._plotter.get_region()
     159                dpos = (pos[0][0], pos[1][0])
     160                args = dpos + args
    118161        self._axes_callback("axvspan", *args, **kwargs)
    119162        # hack to preventy mpl from redrawing the patch
    120163        # it seem to convert the patch into lines on every draw.
    121164        # This doesn't happen in a test script???
    122         del self._plotter.axes.patches[-1]
     165        #del self._plotter.axes.patches[-1]
     166
    123167    axvspan.__doc__ = matplotlib.axes.Axes.axvspan.__doc__
    124168
    125169    def axhspan(self, *args, **kwargs):
     170        if kwargs.has_key("interactive"):
     171            if kwargs.pop("interactive"):
     172                pos = self._plotter.get_region()
     173                dpos = (pos[0][1], pos[1][1])
     174                args = dpos + args
     175
    126176        self._axes_callback("axhspan", *args, **kwargs)
    127177        # hack to preventy mpl from redrawing the patch
    128178        # it seem to convert the patch into lines on every draw.
    129179        # This doesn't happen in a test script???
    130         del self._plotter.axes.patches[-1]
     180        #del self._plotter.axes.patches[-1]
    131181    axhspan.__doc__ = matplotlib.axes.Axes.axhspan.__doc__
    132182
     
    148198        self._plotter.axes.set_autoscale_on(True)
    149199    # end matplotlib.axes fowarding functions
     200
    150201
    151202    def set_mode(self, stacking=None, panelling=None):
     
    390441        if self._data: self.plot(self._data)
    391442
    392     def set_font(self, family=None, style=None, weight=None, size=None):
     443    def set_font(self, **kwargs):
    393444        """
    394445        Set font properties.
     
    401452        """
    402453        from matplotlib import rc as rcp
    403         if isinstance(family, str):
    404             rcp('font', family=family)
    405         if isinstance(style, str):
    406             rcp('font', style=style)
    407         if isinstance(weight, str):
    408             rcp('font', weight=weight)
    409         if isinstance(size, float) or isinstance(size, int):
    410             rcp('font', size=size)
    411         if self._data: self.plot(self._data)
     454        fdict = {}
     455        for k,v in kwargs.iteritems():
     456            if v:
     457                fdict[k] = v
     458        rcp('font', **fdict)
     459        if self._data:
     460            self.plot(self._data)
    412461
    413462    def plot_lines(self, linecat=None, doppler=0.0, deltachan=10, rotate=90.0,
     
    632681                ylab = self._ordinate and self._ordinate[panelcount] \
    633682                       or scan._get_ordinate_label()
    634                 self._plotter.set_axes('xlabel',xlab)
    635                 self._plotter.set_axes('ylabel',ylab)
     683                self._plotter.set_axes('xlabel', xlab)
     684                self._plotter.set_axes('ylabel', ylab)
    636685                lbl = self._get_label(scan, r, self._panelling, self._title)
    637686                if isinstance(lbl, list) or isinstance(lbl, tuple):
Note: See TracChangeset for help on using the changeset viewer.