delete instance of axvspan

I am using span selector to identify an area and then highlight in in green. I want the user to be able to validate this (or not) and then select another area (or not). However, when the user selects the alternate area I want the previous instance of axvspan to be deleted/removed. How do I remove this instance? of do I have to delete the whole plot and replot?

Removing the instance is strongly preferred becauase the user may of altered the display using the canvas widgets.

f=Figure(figsize=(12,8), dpi=72)
    a=f.add_subplot(111)
    ...
    a.plot(aTime, aDensity, 'k', aTime, aElec, 'b')
    ...
    canvas = FigureCanvasTkAgg(f, master=root)
    canvas.show()
    canvas.get_tk_widget().pack(side=Tk.TOP)
    .....
    def onselect(timemin,timemax):
        indmin,indmax=npy.searchsorted(glbl.act_time[glbl.newjob],(timemin,timemax))
        indmax=min(len(glbl.act_time[glbl.newjob])-1,indmax)
        thistime=glbl.act_time[glbl.newjob][indmin:indmax]
        exec("thisDens=glbl.%s_d[%d][indmin:indmax]" % (newcolor, glbl.newjob))
        exec("thisElect=glbl.%s_d[%d][indmin:indmax]" % (newcolor, glbl.newjob))
        print thisDens
        #creates a reference green area to validate area chosen
        lo=glbl.act_time[glbl.newjob][indmin]
        hi=glbl.act_time[glbl.newjob][indmax]
        a.axvspan(lo,hi,facecolor='g',alpha=0.5)
        canvas.show()
...
    span=SpanSelector(a,onselect,'horizontal',useblit=True,
                      rectprops=dict(alpha=0.5,facecolor='red'))

···

____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs

Michael,
I have more or less the same issue: I need to be able to highlight one
particular curve among many. I have implemented a special subclass of Axes
for my particular problem. This subclass has a method "highlight"
Here's a rough draft of what I do:

def __init__(self,*args,**kwargs)
        Subplot.__init__(self,*args,**kwargs)
        sefl.highlightedfreq = None

def highlight(bandwidth, **options):
        if (self.highlightedfreq is not None) and \
           (self.highlightedfreq != bandwidth):
            del self.lines[self.highlightedline]
        self.highlightedfreq = bandwidth
        self.plot(current._dates-shift, current._series, lw=lw, ls=ls, c=c,
                  scalex=False, scaley=False)
        self.highlightedline = len(self.lines)-1 #
        return self.highlightedline

As you see, I have an extra attribute (highlightedfreq) that stores the index
of the highlighted line: when I need to deselect the highlighted curve, I
just delete the corresponding element of the lines list.

HIH
P.

···

On Tuesday 12 February 2008 12:07:21 Michael Frauens wrote:

I am using span selector to identify an area and then highlight in in
green. I want the user to be able to validate this (or not) and then
select another area (or not). However, when the user selects the alternate
area I want the previous instance of axvspan to be deleted/removed. How do
I remove this instance? of do I have to delete the whole plot and replot?

Removing the instance is strongly preferred becauase the user may of
altered the display using the canvas widgets.

I haven't tested this, but a more direct route may be (plot returns a
list of lines and the "myline," idiom extracts the first element into
the variable "myline")

  myline, = ax.plot(x, y, ...)

and then later when you want to remove:

  ax.lines.remove(myline)

Hope this helps,
JDH

···

On Feb 12, 2008 12:23 PM, Pierre GM <pgmdevlist@...287...> wrote:

        self.plot(current._dates-shift, current._series, lw=lw, ls=ls, c=c,
                  scalex=False, scaley=False)
        self.highlightedline = len(self.lines)-1 #
        return self.highlightedline

As you see, I have an extra attribute (highlightedfreq) that stores the index
of the highlighted line: when I need to deselect the highlighted curve, I
just delete the corresponding element of the lines list.