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' green = '#227D51' sim = [0.79844266, 0.8377947, 0.87015217, 0.91429971, 0.94337877, 0.89212607, 0.99805755, 0.98048562, 0.98530593, 0.99598291, 0.87856398, 0.99217795, 0.62392839, 0.99253731, 0.99703892] ana = [0.8, 0.8290884722222223, 0.8581769444444445, 0.8872654166666667, 0.9163538888888889, 0.9454423611111111, 0.9745308333333333, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 1.0, 1.0] def p1(x, coopr, crawx, crawy, postfix, show=True): fig = plt.figure(figsize=(4.5, 1.8)) ax = fig.gca() if postfix == 'SURVIVE': ax.plot(x, sim, marker='s', linestyle='dotted', markerfacecolor='none', color=red, linewidth=2, label="Simulation") ax.plot(x, ana, marker='^', linestyle='dotted', markerfacecolor='none', color=green, linewidth=2, label="Analytical") ax.plot(x, coopr, marker='o', linestyle='dotted', markerfacecolor='none', color=blue, linewidth=2, label="Human") ax.scatter(crawx, crawy, s=15, c='dimgray', marker='x', linewidth=0.5, alpha=0.4) ax.set_ylim(-0.05, 1.05) ax.set_yticks(sp.linspace(0, 1, 5)) ax.tick_params(labelsize=10) 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=11) ax.set_ylabel(r"f$_{\rm c}$", size=11, fontstyle='normal') ax.yaxis.grid(True, linestyle='--') # if postfix == 'SURVIVE': # ax.legend(loc='best', fontsize=10, ncol=3) 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)