title: python tkinter - interactive plot and listbox with span widget
body: <p>Following steps i try to do:<br>
  1. insert a list of value pairs [xmin, xmax]<br>
  2. create a initial list of span objects<br>
  3. plot the spans and write the labels into a listbox<br>
  4. add spans to plot (via onlick event) and update the listbox<br>
  5. remove and higlight spans</p>
  
  <p>Here is a sample code:</p>
  
  <pre><code>from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  from matplotlib.figure import Figure
  from matplotlib.widgets import SpanSelector
  import tkinter as tk
  import numpy as np
  
  class App:
       def __init__(self, master, l_val_pair):
           # Create a container
           frame = tk.Frame(master)
  
           # Create fields
           self.button_left = tk.Button(frame,text="Export")
           self.button_left.pack(side="left")
           self.button_right = tk.Button(frame,text="Delete", command = 
                                         lambda: self.delete(self.l_spans))
           self.button_right.pack(side="left")
  
           self.listbox = tk.Listbox(master)
           self.listbox.pack(side='bottom', fill=tk.X) 
  
           #define figure
           self.fig = Figure()
           self.ax = self.fig.add_subplot(111)
  
           #sample data for a line
           self.x = np.arange(0.0, 5.0, 0.01)
           self.y = np.sin(2*np.pi*self.x) + 0.5*np.random.randn(len(self.x))
  
           #plot line and list of spans
           self.ax.plot(self.x,self.y)
  
           self.l_spans = [self.ax.axes.axvspan(
                   val_pair[0],val_pair[1], facecolor='red', alpha=0.3, label=val_pair) 
                      for val_pair in l_val_pair]
  
           #create a listbox      
           [self.listbox.insert(tk.END, item.get_label()) for item in self.l_spans]
           self.listbox.bind('&lt;&lt;ListboxSelect&gt;&gt;', self.highlight_span)         
  
           #plot figure
           self.canvas = FigureCanvasTkAgg(self.fig,master=master)
           self.canvas.show()
           self.canvas.get_tk_widget().pack(side='top', fill='both', expand=1)
           frame.pack()
  
           #use span selector
           self.span = SpanSelector(self.ax, self.sel_span, 'horizontal', useblit=True,
                               rectprops=dict(alpha=0.5, facecolor='red'), span_stays=False)
  
           #connect
           self.canvas.mpl_connect('key_press_event', self.span)
  
  
       def sel_span(self,xmin, xmax):
           indmin, indmax = np.searchsorted(self.x, (xmin, xmax))
           indmax = min(len(self.x) - 1, indmax)
  
           span = self.ax.axes.axvspan(xmin=self.x[indmin], xmax=self.x[indmax], 
                                alpha = 0.5, facecolor='red')
  
           #add actual span to list of spans
           self.l_spans.append(span)
  
           #update view (spans and listbox) with central list of spans          
           self.update_view()
  
  
       def update_view(self):
           #clear visualisation
           self.listbox.delete(0,tk.END)
           [span.remove() for span in self.l_spans]
  
  
           #fill with new data
           [self.listbox.insert(tk.END, span.get_label()) for span in self.l_spans]
           [span.draw(self.ax) for span in self.l_spans] #HERE IS THE PROBLEM!!!
  
           #update view
           #...
  
  
       def highlight_span():
           pass
  
       def delete(self,item):
           pass
  
  list_vals= [[1,2],[2.5,4]]
  root = tk.Tk()
  app = App(root, list_vals)
  root.mainloop()
  </code></pre>
  
  <p>Problem in function update_view:<br>
  What is that renderer i need to insert into span.draw()?</p>
  
  <p>I'm unsure if my approach is good as I have no experience with tkinter. What do you think?</p>