0

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.

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() 

enter image description here

DavidG
  • 24,279
  • 14
  • 89
  • 82
Juston Lantrip
  • 61
  • 1
  • 11
  • Just take the code from this question: http://stackoverflow.com/questions/43035368/interactive-slider-bar-chart-color-control And make sure that when trying assingment work to first seach if not one of the course's participants has already asked or solved the question. – ImportanceOfBeingErnest Mar 28 '17 at 15:59
  • Thanks. That answered my question. – Juston Lantrip Mar 28 '17 at 18:00

0 Answers0