-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
50 lines (42 loc) · 1.35 KB
/
plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import matplotlib.pyplot as plt
from statistics import mean, variance
from math import sqrt
import glob
import csv
import os
dirpath = os.getcwd()
#time = range(0,10000)
targetdir = '/home/claire/Desktop/res/pars3-bign0/'
meancoop = []
varcoop = []
for i in range(9):
parvalue = (i + 1) / 10
#fileslist = glob.glob('{0}/res/test/out-d{1}*'.format(dirpath,dispersal))
fileslist = glob.glob(targetdir+'out-d{0}_demography.txt'.format(parvalue))
#fileslist = glob.glob('/home/claire/Desktop/pol-demog/rawdat/out-p{0}-[0123456789].txt_d*'.format(parvalue))
fig = plt.figure(figsize=(20,10))
ax1 = fig.add_subplot(111)
dispcoopmean = []
dispcoopvar = []
for simfile in fileslist:
coop = []
with open(simfile,'r') as sf:
res = csv.reader(sf, delimiter=',')
for row in res:
coop.append(float(row[0]))
time = range(0,len(coop))
plt.plot(time,coop, label=simfile)
filelength = len(coop)
dispcoopmean.append(mean(coop[filelength-1000:filelength]))
dispcoopvar.append(variance(coop[filelength-1000:filelength]))
plt.xlabel('Generations')
plt.ylabel('Value')
plt.ylim(0,max(coop))
plt.title('Simulation, dispersal={0}'.format(parvalue))
plt.legend()
plt.savefig('{0}-plot.png'.format(simfile), dpi=300, bbox_inches='tight')
#plt.show()
meancoop.append(mean(dispcoopmean))
varcoop.append(mean(dispcoopvar))
print(meancoop)
print(varcoop)