title: Change bar colors based of value and CI
body: <p>For an assignment, I have some random data indexed by year.  I've plotted the bars of the means with a 95% CI.  I now need to coose a random value a then have the bars change colors indicating if each bars CI covers the random value I chose.  Here's my code.  I'm lost.  Any help would be greatly appreciated.  Thanks.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  #create random data and a pd.df
  np.random.seed(12345)
  df = pd.DataFrame([np.random.normal(33500,150000,3650), 
                 np.random.normal(41000,90000,3650), 
                 np.random.normal(41000,120000,3650), 
                 np.random.normal(48000,55000,3650)], 
                index=[1992,1993,1994,1995])
  
  #mean values for bars
  df['Mean'] = df.mean(axis=1).tolist()
  
  #confidence intervals
  from scipy.stats import sem
  yerr=df.T.sem().values*1.96  
  yerr
  
  %matplotlib notebook
  import matplotlib as mpl
  import matplotlib.pyplot as plt
  import matplotlib.cm as cm
  import matplotlib.colors as col
  
  #plot variables
  x = df.index.values
  y = (df['Mean'])
  
  #title, labels and bars
  plt.title('Easiest')
  labels = ['1992', '1993', '1994', '1995']
  plt.xticks(x, labels)
  plt.bar(x, y, width=1, edgecolor='k')
  
  #errorbar
  plt.errorbar(x, y, yerr, capsize=12, ls='none', color='black', 
          elinewidth=1.2, label='_nolegend_')
   plt.axhline(y=39650, xmin=0, xmax=1, linewidth=1, color = 'gray', 
  label='39,650')
  
  #colormap
  import matplotlib.colors as col
  import matplotlib.cm as cm
  norm = col.Normalize(vmin = (39650), vmax = (35650))
  cm1 = cm.ScalarMappable(norm=True, cmap='RdBu')
  
  
  plt.legend()
  plt.show() 
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/1cSVw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1cSVw.png" alt="enter image description here"></a></p>