diff options
Diffstat (limited to 'py')
-rw-r--r-- | py/boxplot.py | 2 | ||||
-rw-r--r-- | py/lineplot.py | 46 |
2 files changed, 47 insertions, 1 deletions
diff --git a/py/boxplot.py b/py/boxplot.py index 7d2cf1e..be1c024 100644 --- a/py/boxplot.py +++ b/py/boxplot.py @@ -10,4 +10,4 @@ for trial in trials: plt.boxplot(vecs, labels=names) plt.title('Nearest Neighbor for Each Pit in Different Trials') plt.ylabel('Distance to Nearest Neighbor (cm)') -plt.show() +plt.savefig('boxplot.png', bbox_inches='tight') diff --git a/py/lineplot.py b/py/lineplot.py new file mode 100644 index 0000000..efe6b67 --- /dev/null +++ b/py/lineplot.py @@ -0,0 +1,46 @@ +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 = [] + +ct = 0 + +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.yticks(x,labels=names) + +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), [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') |