Assertion Error: Argument height must be length 22 or scalar python
I have five directories each with the same csv file(different data in
each) which contains data to create a histogram. My code takes this csv
file and makes histograms, so I get five histograms. I am trying to make a
code that will take these five histograms and make an average graph as a
bar graph. The code below shows what I have done:
data_list=[]
num_bins=[]
bin_heights=[]
average_bin_heights=[]
for base_dir in directory_list:
listing=os.listdir(base_dir)
for files in listing:
if files==file_name:
full_name = os.path.join(base_dir,file_name)
df=pd.read_csv(full_name,index_col=0)
data_list.append(df)
for i, column in enumerate(df):
fig1=plt.figure()
df['Measurement']=df[column]
bin_size = int((len(df.index))**.5)
(z,bins,patches)=plt.hist(df['Measurement'],bin_size)
num_bins.append(bin_size)
if (bins[0]<min_edge):
min_edge=bins[0]
if (bins[len(bins)-1]>max_edge):
max_edge=bins[len(bins)-1]
(out_file1, ext) = os.path.splitext(full_name)
out_file1 = out_file1 + "-"+column +'.png'
fig1.savefig(out_file1)
N=np.average(num_bins)
for df in data_list:
(z,bins,patches)=plt.hist(df['Measurement'],N,(min_edge,max_edge),normed=True)
bin_heights.append(z)
for i in range(0,(len(bins))-1):
T=0
for bh in bin_heights:
T=T+bh[i]
average_bin_heights.append(T/len(bin_heights))
fig2=plt.figure()
ax=fig2.add_subplot(1,1,1)
ax.bar(bins,height=average_bin_heights)
My problem is the last line. I keep getting an assertion error saying that
Argument height must be length 22 or scalar python. I don't quite
understand what this error message means, or where to look to fix the
problem. Any help?
No comments:
Post a Comment