更改字体大小,优化图像
This commit is contained in:
parent
1f5cde5761
commit
1ccb752566
@ -20,7 +20,7 @@ NEW VERSION
|
||||
bt_s = [13.717872086072923, 86.26126126126125]
|
||||
bt_c = [8.331150117893634, 42.07858048162231]
|
||||
|
||||
fig = plt.figure(figsize=(4, 4))
|
||||
fig = plt.figure(figsize=(3.3, 3))
|
||||
ax = fig.gca()
|
||||
|
||||
index = np.arange(2)
|
||||
|
||||
@ -238,7 +238,7 @@ def draw_faces(ctx, p, f, r, lw):
|
||||
draw_dead_face(ctx, p[k], r, lw)
|
||||
|
||||
draw_food_bar(ctx, p[k].new_rel_point(r / SQRT2 + 20, r / SQRT2), f[k], 5, 10, r * SQRT2)
|
||||
draw_text(ctx, str(k), Point(p[k].x, p[k].y - r - 15), Point(p[k].x, p[k].y - r - 5), CENTER_ALIGNED|MIDDLE_ALIGNED, 12)
|
||||
# draw_text(ctx, str(k), Point(p[k].x, p[k].y - r - 15), Point(p[k].x, p[k].y - r - 5), CENTER_ALIGNED|MIDDLE_ALIGNED, 12)
|
||||
|
||||
def draw_text(ctx, text, tl, br, align, font_size=None, color=Color(0,0,0,1), font_face=None, font_matrix=None, font_options=None):
|
||||
"""
|
||||
@ -316,16 +316,14 @@ def draw_picture(fin,fout):
|
||||
P[r['pid']] = Point(len(F) * FACE_WIDTH + FACE_INTERVAL + ROUND_NO_WIDTH, ROUND_HEIGHT / 2)
|
||||
F[r['pid']] = 5
|
||||
|
||||
# surface = SVGSurface("example.svg", len(P)*(FACE_WIDTH)+FACE_WIDTH, (game_end_at+2)*ROUND_HEIGHT)
|
||||
surface = PSSurface(fout, (len(P)+1)*(FACE_WIDTH) + ROUND_NO_WIDTH, (game_end_at+2)*ROUND_HEIGHT)
|
||||
surface.set_eps(True)
|
||||
surface = SVGSurface(fout, (len(P) + 1) * (FACE_WIDTH) + ROUND_NO_WIDTH, (game_end_at + 2) * ROUND_HEIGHT)
|
||||
# surface = PSSurface(fout, (len(P)+1)*(FACE_WIDTH) + ROUND_NO_WIDTH, (game_end_at+2)*ROUND_HEIGHT)
|
||||
# surface.set_eps(True)
|
||||
context = Context(surface)
|
||||
|
||||
bottom = 0
|
||||
|
||||
for i in range(1, game_end_at + 2):
|
||||
next_f = F.copy()
|
||||
draw_text(context, "Round %d" % i, Point(5, ROUND_HEIGHT/2+(i-1)*ROUND_HEIGHT), Point(ROUND_NO_WIDTH, ROUND_HEIGHT/2+(i-1)*ROUND_HEIGHT), LEFT_ALIGNED | MIDDLE_ALIGNED, 20)
|
||||
draw_text(context, "R# %d" % i, Point(5, ROUND_HEIGHT/2+(i-1)*ROUND_HEIGHT), Point(ROUND_NO_WIDTH, ROUND_HEIGHT/2+(i-1)*ROUND_HEIGHT), LEFT_ALIGNED | MIDDLE_ALIGNED, 40)
|
||||
for r in M.query('action', 'done').where(lambda row: row['rno'] == i).raw_data:
|
||||
draw_action_arrow(context, P[r['a']], P[r['b']], LINEWIDTH, 15, R, AKE.shade(r['tr'] / 1440) if r['act_a'] == 'D' else TOKIWA.shade(r['tr']/1440))
|
||||
draw_action_arrow(context, P[r['b']], P[r['a']], LINEWIDTH, 15, R, AKE.shade(r['tr'] / 1440) if r['act_b'] == 'D' else TOKIWA.shade(r['tr']/1440))
|
||||
@ -355,5 +353,5 @@ if __name__ == '__main__':
|
||||
p = Path(file)
|
||||
if p.suffix == '.json':
|
||||
name = p.stem
|
||||
draw_picture(str(p), str(p.parent.parent / 'graph' / ("%s.eps"%name)))
|
||||
# draw_picture("wos-data-new/G285.json", "graph/G285.eps")
|
||||
draw_picture(str(p), str(p.parent.parent / 'graph' / ("%s.svg"%name)))
|
||||
# draw_picture("wos-data-new/G285.json", "graph/G285.eps")
|
||||
|
||||
@ -63,7 +63,7 @@ if __name__ == '__main__':
|
||||
green = '#00b894'
|
||||
c = [blue, red]
|
||||
labels = ['Dissipative', 'Classic']
|
||||
fig = plt.figure(figsize=(8, 6))
|
||||
fig = plt.figure(figsize=(4, 3))
|
||||
ax = fig.gca()
|
||||
index = np.arange(2)
|
||||
widths = 0.3
|
||||
@ -81,9 +81,9 @@ if __name__ == '__main__':
|
||||
# ax.set_title('Scores by group and gender')
|
||||
ax.set_xticks(index)
|
||||
ax.set_xticklabels(['C', 'D'])
|
||||
ax.set_ylim(-6, 4)
|
||||
ax.set_ylim(-6, 6)
|
||||
ax.set_xlabel("Previous Move")
|
||||
ax.legend([hdl1, hdl2], labels)
|
||||
ax.legend([hdl1, hdl2], labels, ncol=2)
|
||||
|
||||
fig.tight_layout()
|
||||
# plt.show()
|
||||
|
||||
@ -38,16 +38,19 @@ def p2c(tau, rewires, show):
|
||||
ax = fig.gca()
|
||||
|
||||
plt.scatter(tau, rewires, color=green, linewidths=2, zorder=100)
|
||||
ax.set_xlabel('$\\tau_{p}$', family='sans-serif')
|
||||
ax.set_ylabel('Rewiring Rate')
|
||||
ax.set_xlabel('$\\tau_{f}$', family='sans-serif', size=20)
|
||||
ax.set_ylabel('Rewiring Rate', size=20)
|
||||
ax.set_xlim(0, 1440)
|
||||
ax.set_xticks(sp.linspace(0, 1440, 7))
|
||||
ax.set_ylim(0, 0.6)
|
||||
ax.set_xticks(sp.linspace(0, 1440, 5))
|
||||
ax.tick_params(labelsize=14)
|
||||
ax.set_ylim(0, 0.6)
|
||||
ax.set_yticks(sp.linspace(0, 0.6, 5))
|
||||
plt.tight_layout()
|
||||
if show:
|
||||
plt.show()
|
||||
else:
|
||||
plt.savefig("graph/tau_p_rewire_sca_c.eps")
|
||||
plt.savefig("graph/tau_f_rewire_sca_c.eps")
|
||||
|
||||
# 皮尔逊相关系数
|
||||
print("pearson: %f, p-value: %f" % pearsonr(tau, rewires))
|
||||
@ -68,23 +71,26 @@ def p2(tau, rewires, postfix, show):
|
||||
plt.plot(fx,f1(fx),linewidth=2,color=red, ls='--', zorder=0)
|
||||
plt.scatter(tau, rewires, color=green, linewidths=2, zorder=100)
|
||||
# plt.scatter(tau_r, coopr_r, color='white', edgecolors=green, linewidths=2, zorder=101)
|
||||
ax.set_xlabel('$\\tau_{p}$', family='sans-serif')
|
||||
ax.set_ylabel('Rewiring Rate')
|
||||
ax.set_xlabel('$\\tau_{f}$', family='sans-serif', size=20)
|
||||
ax.set_ylabel('Rewiring Rate', size=20)
|
||||
ax.set_xlim(0, 1440)
|
||||
ax.set_xticks(sp.linspace(0, 1440, 7))
|
||||
ax.set_ylim(0, 0.6)
|
||||
ax.set_xticks(sp.linspace(0, 1440, 5))
|
||||
ax.tick_params(labelsize=14)
|
||||
ax.set_ylim(0, 0.6)
|
||||
ax.set_yticks(sp.linspace(0, 0.6, 5))
|
||||
plt.tight_layout()
|
||||
if show:
|
||||
plt.show()
|
||||
else:
|
||||
plt.savefig("graph/tau_p_rewire_sca_%s.eps" % postfix)
|
||||
plt.savefig("graph/tau_f_rewire_sca_%s.eps" % postfix)
|
||||
|
||||
# 皮尔逊相关系数
|
||||
print("pearson: %f, p-value: %f" % pearsonr(tau, rewires))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
mode = 'SURVIVE'
|
||||
mode = 'CLASSIC'
|
||||
matches = Matches.from_profile_expr(lambda r: mode in r)
|
||||
max_round = 15
|
||||
|
||||
@ -153,7 +159,7 @@ if __name__ == '__main__':
|
||||
else:
|
||||
trs = matches.data[j].get_tr(i, k, neighbors[matches.names[j]][k], survivals[matches.names[j]][str(i)])
|
||||
for l in neighbors[matches.names[j]][k]:
|
||||
if l in trs:
|
||||
if l in trs and trs[l] > 0:
|
||||
t += trs[l]
|
||||
tp.append(t if t < 1440 else 1440)
|
||||
mwTau["%s-%d"%(j,i)] = tp[-1]
|
||||
@ -169,8 +175,8 @@ if __name__ == '__main__':
|
||||
|
||||
# p1折线图
|
||||
# p1(x, rewires, tau, mode, True)
|
||||
# p2c(tau, rewires, False)
|
||||
p2(tau[:12], rewires[:12], mode, False)
|
||||
p2c(tau, rewires, False)
|
||||
# p2(tau[:12], rewires[:12], mode, False)
|
||||
|
||||
|
||||
'''
|
||||
@ -182,9 +188,9 @@ Other parameters: rank=2, sv=[ 1.41291267 0.06064473], rcond=3.10862446895e-15
|
||||
pearson: -0.507660, p-value: 0.063859
|
||||
|
||||
survive
|
||||
残差: [ 0.00293523]
|
||||
Model parameter: [ 0.00016483 -0.02259405]
|
||||
error= 0.002935
|
||||
Other parameters: rank=2, sv=[ 1.33437859 0.46843758], rcond=2.6645352591e-15
|
||||
pearson: 0.947167, p-value: 0.000003
|
||||
残差: [ 0.00291864]
|
||||
Model parameter: [ 0.0001647 -0.02264606]
|
||||
error= 0.002919
|
||||
Other parameters: rank=2, sv=[ 1.33444456 0.46824962], rcond=2.6645352591e-15
|
||||
pearson: 0.947474, p-value: 0.000003
|
||||
'''
|
||||
|
||||
81
tau_f_co.py
81
tau_f_co.py
@ -8,33 +8,37 @@ from scipy.stats import pearsonr
|
||||
from matplotlib import markers
|
||||
|
||||
'''
|
||||
计算tau_p和合作频率之间的关系
|
||||
计算tau_f和合作频率之间的关系
|
||||
'''
|
||||
|
||||
def error(f,x,y):
|
||||
return sp.sum((f(x)-y)**2)
|
||||
|
||||
def p1(x, coopr, tau, postfix, show=True):
|
||||
fig = plt.figure(figsize=(2.5, 2))
|
||||
fig = plt.figure(figsize=(4.5, 3))
|
||||
ax = fig.gca()
|
||||
ax.plot(x, coopr, color=blue, linewidth=2, label="$f_c$")
|
||||
ax.set_ylim(0, 1)
|
||||
ax.set_yticks(sp.linspace(0, 1, 5))
|
||||
ax2 = ax.twinx()
|
||||
ax2.plot(x, tau, color=red, linewidth=2, label=r"$\tau_f$")
|
||||
ax2.set_ylim(0, 1440)
|
||||
ax2.set_yticks(sp.linspace(0, 1440, 5))
|
||||
ax2.tick_params(labelsize=18)
|
||||
ax.tick_params(labelsize=18)
|
||||
ax.set_xlim(1, 15)
|
||||
ax.set_xlabel("Rounds")
|
||||
ax.set_ylabel(r"$f_c$", color=blue)
|
||||
ax.set_xlabel("Rounds", size=22)
|
||||
ax.set_ylabel(r"$f_c$", family='sans-serif', color=blue, size=22)
|
||||
ax.tick_params(axis='y', labelcolor=blue)
|
||||
ax2.set_ylabel(r"$\tau_{f}$", family='sans-serif', color=red)
|
||||
ax2.set_ylabel(r"$\tau_{f}$", family='sans-serif', color=red, size=22)
|
||||
ax2.tick_params(axis='y', labelcolor=red)
|
||||
|
||||
fig.legend()
|
||||
fig.legend(fontsize=18)
|
||||
plt.tight_layout()
|
||||
if show:
|
||||
plt.show()
|
||||
else:
|
||||
plt.savefig("graph/tau_p_co_plot_%s.eps" % postfix)
|
||||
plt.savefig("graph/tau_f_co_plot_%s.eps" % postfix)
|
||||
|
||||
def p2(tau, coopr, limited, postfix, show=True):
|
||||
tau2 = []
|
||||
@ -49,39 +53,45 @@ def p2(tau, coopr, limited, postfix, show=True):
|
||||
tau_r.append(tau[i])
|
||||
coopr_r.append(coopr[i])
|
||||
|
||||
print(tau, coopr)
|
||||
print(tau2, coopr2)
|
||||
# p2散点图
|
||||
fig = plt.figure(figsize=(4, 3))
|
||||
ax = fig.gca()
|
||||
# ax.set_ylim(0.5, 1)
|
||||
fp1,residuals,rank,sv,rcond = sp.polyfit(tau2, coopr2, 1, full=True)
|
||||
print("残差:",residuals)
|
||||
print('Model parameter:',fp1)
|
||||
print("Other parameters: rank=%s, sv=%s, rcond=%s"%(str(rank), str(sv), str(rcond)))
|
||||
f1 = sp.poly1d(fp1)
|
||||
print("error= %f" % error(f1, tau2, coopr2))
|
||||
fx = sp.linspace(0, limited, 2)
|
||||
if tau2:
|
||||
# ax.set_ylim(0.5, 1)
|
||||
fp1,residuals,rank,sv,rcond = sp.polyfit(tau2, coopr2, 1, full=True)
|
||||
print("残差:",residuals)
|
||||
print('Model parameter:',fp1)
|
||||
print("Other parameters: rank=%s, sv=%s, rcond=%s"%(str(rank), str(sv), str(rcond)))
|
||||
f1 = sp.poly1d(fp1)
|
||||
print("error= %f" % error(f1, tau2, coopr2))
|
||||
fx = sp.linspace(0, limited, 2)
|
||||
|
||||
plt.plot(fx,f1(fx),linewidth=2,color=red, ls='--', zorder=0)
|
||||
plt.scatter(tau2, coopr2, color=blue, linewidths=2, zorder=100)
|
||||
|
||||
plt.plot(fx,f1(fx),linewidth=2,color=red, ls='--', zorder=0)
|
||||
plt.scatter(tau2, coopr2, color=blue, linewidths=2, zorder=100)
|
||||
plt.scatter(tau_r, coopr_r, color='white', edgecolors=blue, linewidths=2, zorder=101)
|
||||
ax.set_xlabel(r'$\tau_{p}$', family='sans-serif')
|
||||
ax.set_ylabel(r'$f_{c}$', family='sans-serif')
|
||||
ax.set_xlabel(r'$\tau_{f}$', family='sans-serif', size=20)
|
||||
ax.set_ylabel(r'$f_{c}$', family='sans-serif', size=20)
|
||||
ax.set_xlim(0, 1440)
|
||||
ax.set_xticks(sp.linspace(0, 1440, 7))
|
||||
ax.set_xticks(sp.linspace(0, 1440, 5))
|
||||
ax.tick_params(labelsize=14)
|
||||
ax.set_ylim(0.5, 1)
|
||||
ax.set_yticks(sp.linspace(0.5, 1, 5))
|
||||
plt.tight_layout()
|
||||
if show:
|
||||
plt.show()
|
||||
else:
|
||||
plt.savefig("graph/tau_p_co_sca_%s.eps" % postfix)
|
||||
plt.savefig("graph/tau_f_co_sca_%s.eps" % postfix)
|
||||
|
||||
# 皮尔逊相关系数
|
||||
print("pearson: %f, p-value: %f" % pearsonr(tau2, coopr2))
|
||||
if tau2:
|
||||
print("pearson: %f, p-value: %f" % pearsonr(tau2, coopr2))
|
||||
else:
|
||||
print("pearson: %f, p-value: %f" % pearsonr(tau_r, coopr_r))
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
# matches = Matches.from_profile_expr(lambda r: 'CLASSIC' in r)
|
||||
matches = Matches.from_profile_expr(lambda r: 'SURVIVE' in r)
|
||||
max_round = 15
|
||||
|
||||
@ -172,26 +182,21 @@ if __name__ == '__main__':
|
||||
|
||||
# p1折线图
|
||||
# p1(x, coopr, tau, 'classic', False)
|
||||
p1(x, coopr, tau, 'survive', True)
|
||||
# p1(x, coopr, tau, 'survive', False)
|
||||
|
||||
# p2(tau[:12], coopr[:12], 720, 'survive', True)
|
||||
# p2(tau, coopr, 1440, 'classic', False)
|
||||
p2(tau[:12], coopr[:12], 720, 'survive', False)
|
||||
# p2(tau, coopr, 720, 'classic', False)
|
||||
|
||||
|
||||
'''
|
||||
|
||||
survive
|
||||
残差: [ 0.00548837]
|
||||
Model parameter: [ -2.71223484e-04 1.00851422e+00]
|
||||
Other parameters: rank=2, sv=[ 1.36321571 0.37635479], rcond=1.99840144433e-15
|
||||
error= 0.005488
|
||||
pearson: -0.829102, p-value: 0.005723
|
||||
残差: [ 0.0054399]
|
||||
Model parameter: [ -2.69062302e-04 1.00822767e+00]
|
||||
Other parameters: rank=2, sv=[ 1.36265876 0.37836635], rcond=1.99840144433e-15
|
||||
error= 0.005440
|
||||
pearson: -0.830766, p-value: 0.005540
|
||||
|
||||
classic
|
||||
残差: [ 0.00489393]
|
||||
Model parameter: [ -1.38823596e-04 9.82787424e-01]
|
||||
Other parameters: rank=2, sv=[ 1.41298532 0.05892772], rcond=3.33066907388e-15
|
||||
error= 0.004894
|
||||
pearson: -0.582154, p-value: 0.022790
|
||||
|
||||
pearson: -0.622448, p-value: 0.013207
|
||||
'''
|
||||
|
||||
Loading…
Reference in New Issue
Block a user