title: How do I get the bar chart value after using the Slider from matplotlib.widgets?
body: <p>I have a bar chart with bad (i.e. negative) and good values (i.e. positive). These values are decided by the threshold. Please refer to <a href="https://stackoverflow.com/questions/54576667/how-can-i-correctly-classify-the-number-of-positive-bright-color-circles-and-n">Postive_Negative_Circles</a></p>
  
  <p>The bar chart output is  <a href="https://i.stack.imgur.com/C7hAM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C7hAM.png" alt="Bar_Chart"></a></p>
  
  <p>which displays: Bad= 3472, Good = 664 and threshold = 164.094 </p>
  
  <p>If I change the threshold, these values should change. Here is what I have done so far:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import pylab as p
  from matplotlib.widgets import Slider, Button
  
  axcolor = 'lightgoldenrodyellow'
  axthreshold = plt.axes([0.2, 0.001, 0.65, 0.03], facecolor=axcolor)
  sthreshold = Slider(axthreshold, 'Threshold', 0.0, 300, 
                      valinit=threshold, valstep=None)
  
  fig_text1 = p.figtext(0.5, 0.65,  str(sthreshold.val))
  def update(val):
      thresh = int(sthreshold.val)
      data = [np.sum(values &lt;= thresh), np.sum(values &gt; thresh)]
      ax.clear ()
      ax.bar(labels, data, color=colors)
      np.set_printoptions(precision=2)
      fig_text1.set_text(str(sthreshold.val))
  
      fig.canvas.draw_idle()
  
  sthreshold.on_changed(update)
  resetax = plt.axes([0.7, 0.001, 0.1, 0.04])
  button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
  
  def reset(event):
      sthreshold.reset()
  
  button.on_clicked(reset)
  </code></pre>
  
  <p>The above code works fine and the bar chart also changes, but unfortunately, I am unable to display the value of the bar chart after the Slider update. I can only display the value for the threshold.</p>
  
  <p>Now, I have set the threshold to 114.24 using the Slider widget from matplotlib, and the bar chart <strong>should display values</strong>: Good = 2543 and Bad= 1593. As you can see that the change in the threshold value is displayed, but not the bar chart values</p>
  
  <p><a href="https://i.stack.imgur.com/8Xdzp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Xdzp.png" alt="Bar_Chart_after_Changed_Threshold"></a></p>
  
  <p>Please ignore the Reset button on top of the Slider. I tried to change the position of the Reset Button, but it doesn't work. I guess there is a problem with the %matplotlib notebook.</p>
  
  <p>Could someone help me out here? I looked online for the solution (like matplotlib demo or StackOverflow etc), but couldn't find what I was looking for. There are few StackOverflow questions on Slider update for the bar chart, but none talks about the bar chart value. Also, let me know if you need any further information on the code.</p>
  
  <p>If you know any good source or the solution, please let me know. Thank you</p>
  
  <p><strong><em>UPDATE:</em></strong> </p>
  
  <p>This is what I tried and it doesn't work:</p>
  
  <pre><code>def update(val):
      thresh = int(sthreshold.val)
      print(thresh)
      data = [np.sum(values &lt;= thresh), np.sum(values &gt; thresh)]
      ax.clear ()
      bars = ax.bar(labels, data, color=colors)
  
      for rect in bars:
          height = rect.get_height()
          plt.text(rect.get_x() + rect.get_width()/2.0, height, '%d' % 
                     int(height), ha='center', va='bottom')
  
     np.set_printoptions(precision=2)
     fig_text1.set_text(str(sthreshold.val))
  
     fig.canvas.draw_idle()
  </code></pre>