title: How can I delete a line from a plot by clicking on the legend using matplotlib?
body: <p>I have this plot that i created with matplotlib, How can I make invisible  a line from a plot by clicking on the legend ? I am using a python file</p>
  <pre><code>def detect (df_abs,a,b):
      
      X = df_abs.iloc[:, a:b].to_numpy()
      l = X.shape[0]
      D = np.zeros((l, l))
      idx = range(len(X))
      D = np.maximum(D, D.transpose())
      d = D.sum(0) / l
      t= np.dort(d)[np.where(diff &gt; c * np.median(diff))[0] + 1].min()
          return df_abs.iloc[np.where(d &gt;= t)].index
  
  def out (df_abs, a, b, c):
      o= detect(df_abs, a, b, c)
      colors = 'red'
      plt.figure(figsize=(20, 10))
      plt.plot(df_abs.to_numpy()[:, 1:].T, 'blue')
        
  </code></pre>