From c6516db0a10df08fb96f546e8d705dc35004e3ce Mon Sep 17 00:00:00 2001 From: wjsjwr Date: Sat, 12 Sep 2020 22:39:03 +0800 Subject: [PATCH] fix font size --- decision_time.py | 16 +++++++++++----- eid_plot.py | 24 ++++++++++++------------ fc_plot.py | 21 +++++++++++++++------ food_loss.py | 9 ++++++--- sanitize.py | 14 ++++++++++++++ 5 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 sanitize.py diff --git a/decision_time.py b/decision_time.py index 43590e9..d85c002 100644 --- a/decision_time.py +++ b/decision_time.py @@ -36,13 +36,19 @@ colors = cm.get_cmap('OrRd') colors.set_bad('white') ax.set_xticklabels(np.arange(1, 46, 11)) dct = ax.imshow(ndata, cmap=colors, origin='lower')#, norm=colors.LogNorm()) -sc = ax.scatter(np.arange(7, 45), np.floor(45 / np.arange(8, 46)), s=20, facecolors='none', edgecolors='black', linewidths=0.75, linestyle='dotted', label='Maximal number of opponents') -plt.legend() +# sc = ax.scatter(np.arange(7, 45), np.floor(45 / np.arange(8, 46)), s=20, facecolors='none', edgecolors='black', linewidths=0.75, linestyle='dotted', label='Maximal number of opponents') +# ax.scatter(np.arange(0, 7), [5]*7, s=20, facecolors='none', edgecolors='black', linewidths=0.75, linestyle='dotted') +# for i in range(0,7): +# print(f"{i}: {floor(45/(i+1))}\n") +# plt.legend() # ax2 = ax.twinx() # ax2.set_ylabel("Maximal Number of opponents") -ax.set_xlabel("Decision time") -ax.set_ylabel("Number of partners") -fig.colorbar(dct, ax=ax, orientation='horizontal', aspect=40) +ax.set_xlabel("Average Decision time", fontsize=11) +ax.set_ylabel("Number of partners", fontsize=11) +ax.tick_params(labelsize=10) +ax.reset_position() +fig.set_size_inches(6,5) +fig.colorbar(dct, ax=ax, orientation='horizontal', aspect=30, shrink=1) # plt.show() # print(plt.rcParams) diff --git a/eid_plot.py b/eid_plot.py index fe29430..cf35aed 100644 --- a/eid_plot.py +++ b/eid_plot.py @@ -10,22 +10,22 @@ red = '#d63031' def error(f,x,y): return sp.sum((f(x)-y)**2) def p1(x, coopr, e, postfix, show=True): - fig = plt.figure(figsize=(4.5, 3)) + fig = plt.figure(figsize=(3, 2)) ax = fig.gca() - ax.plot(x, coopr, color=blue, linewidth=2, label="$f_c$") + ax.plot(x, coopr, color=blue, linewidth=2, label=r"f$_{\rm c}$") ax.set_ylim(0, 1) ax.set_yticks(sp.linspace(0, 1, 5)) ax2 = ax.twinx() - ax2.plot(x[:-1], e[:-1], color=red, linewidth=2, label=r"$\theta$") + ax2.plot(x[:-1], e[:-1], color=red, linewidth=2, label=r"${\rm \theta}$") ax2.set_ylim(-1500, 200) ax2.set_yticks(sp.linspace(-1500, 200, 5)) - ax2.tick_params(labelsize=14) - ax.tick_params(labelsize=14) + ax2.tick_params(labelsize=10) + ax.tick_params(labelsize=10) ax.set_xlim(1, 15) - ax.set_xlabel("Rounds", size=22) - ax.set_ylabel(r"$f_c$", family='sans-serif', color=blue, size=22) + ax.set_xlabel("Rounds", size=11) + ax.set_ylabel(r"f$_{\rm c}$", color=blue, size=11) ax.tick_params(axis='y', labelcolor=blue) - ax2.set_ylabel(r"$\theta$", family='sans-serif', color=red, size=22) + ax2.set_ylabel(r"${\rm \theta}$", color=red, size=11) ax2.tick_params(axis='y', labelcolor=red) ax.tick_params(direction='in') ax2.tick_params(direction='in') @@ -38,7 +38,7 @@ def p1(x, coopr, e, postfix, show=True): def p2(e, coopr, postfix, show=True, showline=True): # p2散点图 - fig = plt.figure(figsize=(4, 3)) + fig = plt.figure(figsize=(3, 2)) ax = fig.gca() if showline: fp1,residuals,rank,sv,rcond = sp.polyfit(e, coopr, 1, full=True) @@ -51,11 +51,11 @@ def p2(e, coopr, postfix, show=True, showline=True): plt.plot(fx,f1(fx),linewidth=2,color=red, ls='--', zorder=0) plt.scatter(e, coopr, color='white', edgecolors=blue, linewidths=2, zorder=101) - ax.set_xlabel(r'$\theta$', family='sans-serif', size=20) - ax.set_ylabel(r'$f_{c}$', family='sans-serif', size=20) + ax.set_xlabel(r"${\rm \theta}$", size=12) + ax.set_ylabel(r"f$_{\rm c}$", size=12) # ax.set_xlim(0, 1440) # ax.set_xticks(sp.linspace(int(min(e)*0.9), int(max(e)*1.1), 4)) - ax.tick_params(labelsize=14) + ax.tick_params(labelsize=10) ax.set_ylim(0.6, 1) ax.set_yticks(sp.linspace(0.6, 1, 5)) ax.tick_params(direction='in') diff --git a/fc_plot.py b/fc_plot.py index 72773d9..cc2a854 100644 --- a/fc_plot.py +++ b/fc_plot.py @@ -8,22 +8,31 @@ 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, 2.5)) + fig = plt.figure(figsize=(4.5, 1.8)) 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) + 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=14) - ax.set_ylabel(r"$f_c$", family='sans-serif', size=14) + 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: diff --git a/food_loss.py b/food_loss.py index d1d4e75..a451268 100644 --- a/food_loss.py +++ b/food_loss.py @@ -75,17 +75,20 @@ if __name__ == '__main__': hdl2 = pch.Patch(facecolor=vp2['bodies'][0].get_facecolor()[0]) vp1['cmeans'].set_edgecolor(black) vp1['cmeans'].set_linestyle(':') + vp1['cmedians'].set_linestyle('dashed') vp2['cmeans'].set_edgecolor(black) vp2['cmeans'].set_linestyle(':') - ax.set_ylabel('Distribution of Food Loss') + vp2['cmedians'].set_linestyle('dashed') + ax.set_ylabel('Distribution of the Payoff Loss', fontsize=11) ax.yaxis.grid(True, linestyle='--') # ax.set_title('Scores by group and gender') ax.set_xticks(index) ax.set_xticklabels(['C', 'D']) ax.set_ylim(-6, 6) - ax.set_xlabel("Previous Move") + ax.tick_params(labelsize=10) + ax.set_xlabel("Previous Move", fontsize=11) ax.tick_params(direction='in') - ax.legend([hdl1, hdl2], labels, ncol=2) + ax.legend([hdl1, hdl2], labels, ncol=2, fontsize=10) fig.tight_layout() # plt.show() diff --git a/sanitize.py b/sanitize.py new file mode 100644 index 0000000..f9d26e7 --- /dev/null +++ b/sanitize.py @@ -0,0 +1,14 @@ +import json +import os.path + +with open('profile.csv') as fp: + for l in fp: + fn = l.split(',')[0] + with open(fn, encoding='utf-8') as js: + data = [] + for item in json.load(js): + if item['cat'] != 'chat': + data.append(item) + with open(os.path.join('wos-data-sanitized', os.path.basename(fn)), 'w') as out: + json.dump(data, out) + print("Finish: ", fn)