title: pyplot/matplotlib Bar chart with fill color depending on value
body: <p>I want to produce <strong>in python</strong> with matplotlib/pyplot</p>
  
  <ul>
  <li>a bar chart with a fill depending on the value.</li>
  <li>legend color bar</li>
  </ul>
  
  <p>while keeping module dependencies at a minimum.</p>
  
  <p><br></p>
  
  <p>Is there something simpler than:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  def color_gradient ( val, beg_rgb, end_rgb, val_min = 0, val_max = 1):
      val_scale = (1.0 * val - val_min) / (val_max - val_min)
      return ( beg_rgb[0] + val_scale * (end_rgb[0] - beg_rgb[0]),
               beg_rgb[1] + val_scale * (end_rgb[1] - beg_rgb[1]),
               beg_rgb[2] + val_scale * (end_rgb[2] - beg_rgb[2]))
  
  # -----------------------------------------------
  x_lbls = [ "09:00", "09:15", "10:10"]
  y_vals = [       7,       9,       5]
  
  plt_idx = np.arange( len( x_lbls))
  bar_wd  = 0.35
  
  grad_beg, grad_end = ( 0.5, 0.5, 0.5), (1, 1, 0)
  col_list = [ color_gradient( val,
                               grad_beg,
                               grad_end,
                               min( y_vals),
                               max( y_vals)) for val in y_vals]
  
  plt.bar( plt_idx, y_vals, color = col_list)
  plt.xticks( plt_idx + bar_wd, x_lbls)
  plt.show()
  </code></pre>
  
  <p><strong>this is still missing the legend color bar</strong> </p>
  
  <p><br></p>
  
  <p>my solution in R with <strong>ggplot</strong> would be:</p>
  
  <pre><code>library(ggplot2)
  df = data.frame( time = 1:10, vals = abs(rnorm( n = 10)))
  ggplot( df, aes( x = time, y = vals, fill = vals)) + 
    geom_bar(stat = "identity") + 
    scale_fill_gradient(low="#888888",high="#FFFF00")
  </code></pre>
  
  <p>and produces the desired output: <img src="https://i.stack.imgur.com/d0Mbi.png" alt="Example in R with ggplot"></p>