52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
import numpy as np
|
|
from matplotlib import pyplot as plt
|
|
import scipy as sp
|
|
from scipy.stats import pearsonr
|
|
from matplotlib import markers
|
|
from sys import argv
|
|
import json
|
|
import random
|
|
blue = '#0984e3'
|
|
red = '#d63031'
|
|
|
|
def p1(x, coopr, crawx, crawy, postfix, show=True):
|
|
fig = plt.figure(figsize=(4.5, 2.5))
|
|
ax = fig.gca()
|
|
ax.plot(x, coopr, marker='o', linestyle='dotted', color=blue, linewidth=2, label="$f_c$")
|
|
ax.scatter(crawx, crawy, s=15, c='dimgray', marker='x', linewidth=0.5)
|
|
ax.set_ylim(0, 1)
|
|
ax.set_yticks(sp.linspace(0, 1, 5))
|
|
ax.tick_params(labelsize=14)
|
|
ax.tick_params(direction='in')
|
|
ax.set_xlim(0, 16)
|
|
ax.set_xticks([1, 5, 10, 15])
|
|
# ax.set_xticklabels([''])
|
|
ax.set_xlabel("Rounds", size=14)
|
|
ax.set_ylabel(r"$f_c$", family='sans-serif', size=14)
|
|
ax.yaxis.grid(True, linestyle='--')
|
|
|
|
plt.tight_layout()
|
|
if show:
|
|
plt.show()
|
|
else:
|
|
plt.savefig("graph/fc_plot_%s.eps" % postfix)
|
|
|
|
|
|
def plot(mode, show):
|
|
coopr = np.loadtxt("outputs/CR_%s.csv" % mode, delimiter=',')
|
|
crawx, crawy = [],[]
|
|
with open("outputs/CRAW_%s.json" % mode) as f:
|
|
data = json.load(f)
|
|
for l in data:
|
|
for i in range(len(l)):
|
|
crawx.append((i + 1) + random.uniform(-0.25, 0.25))
|
|
crawy.append(l[i])
|
|
x = np.arange(1, 16)
|
|
p1(x, coopr, crawx, crawy, mode, show)
|
|
|
|
if __name__ == '__main__':
|
|
# fc_plot c/s t/f
|
|
mode = 'CLASSIC' if argv[1] == 'c' else 'SURVIVE'
|
|
show = argv[2] == 't'
|
|
plot(mode, show)
|