from data2 import trials from statistics import stdev,mean import matplotlib.pyplot as plt from numpy import arange stderr = [] avg = [] deps = {'nn':[[],[]], 'wid':[[],[]], 'dep':[[],[]], 'recl':[[],[]], 'dead':[[],[]]} varlist = tuple(deps.keys()) title = {'nn':'Nearest Neighbor', 'wid':'Pit Width', 'dep':'Pit Depth', 'recl':'Reclusive Population', 'dead':'Cannibalized Individuals'} names = [] plt.figure(figsize=(16,9)) def addvar(key, data): deps[key][0].append(mean(data)) deps[key][1].append(stdev(data)) for trial in trials: names.append(str(trial)) addvar('nn',trial.nearest_neighbor()) addvar('wid',[pit.diam for pit in trial.pits]) addvar('dep',[pit.depth for pit in trial.pits]) addvar('recl',[trial.recl for pit in trial.pits]) addvar('dead',[trial.dead for pit in trial.pits]) x = arange(len(names)) width = 0.8; plt.xticks(x,labels=names) plt.ylabel('Arbitrary Units') print(names,avg) #for var in varlist: stdscale = 1/2 for ind in range(len(varlist)): var = varlist[ind] div = mean(deps[var][0]) plt.bar(x-ind*width/len(varlist)+width/2, [dep/div for dep in deps[var][0]], yerr=[stdscale*dep/div for dep in deps[var][1]], capsize=6, label=title[var],alpha=0.5, width=width/len(varlist)) #plt.errorbar(names, [dep/div for dep in deps[var][0]], #yerr=[dep/div/4 for dep in deps[var][1]], capsize=12, label=title[var], marker="o") plt.legend() plt.savefig('lineplot.png', bbox_inches='tight')