import json from matplotlib import pyplot as plt from island.match import Match from island.matches import Matches matches = Matches('wos-data-new') max_round = 17 alive = [] yerr_min = [] yerr_max = [] x = [] al_al = [] survivals = {} with open('winner.json','r') as f: survivals = json.load(f) for i in range(max_round): defects = [] for j in range(len(matches.data)): defector = set() for row in matches.data[j].query('action', 'done').where(lambda x: x['rno']==i+1 and (x['act_a']=='D' or x['act_b']=='D')).raw_data: if row['act_a']=='D': defector.add(row['a']) if row['act_b'] == 'D': defector.add(row['b']) if defector: # print("[%d,%d] %s" % (i,j,str(defector))) incr = 0 for k in survivals[matches.names[j]]: if k in defector: incr += 1 # print(k) defects.append(float(incr) / float(len(defector))) print(i) print(defects) if defects: al_al.append(defects) alive.append(sum(defects) / len(defects)) yerr_min.append(alive[-1] - min(defects)) yerr_max.append(max(defects) - alive[-1]) print("%f, %f, %f"%(yerr_min[-1], yerr_max[-1], alive[-1])) x.append(i+1) else: al_al.append([]) plt.figure() # plt.errorbar(x, alive, yerr=[yerr_min, yerr_max], fmt='o', capsize=4) plt.boxplot(al_al, showmeans=True, meanline=True) plt.show() # plt.savefig('graph/survive_after_defect.png')