-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraficos_real3.py
74 lines (61 loc) · 2.65 KB
/
graficos_real3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
def plot_kde(data, cols, per, target, vline=False, lab=None):
fig, ax = plt.subplots()
for col in cols:
ax = sns.kdeplot(data[data[per] == col][target], shade=True, label=col)
sns.despine()
ax.legend(frameon=False, fontsize='x-large')
if vline:
ax.axvline(x=0, color='gray', linewidth=3, alpha=.5)
if not lab:
lab = target
# ax.set_title(lab)
plt.show()
fig.savefig(f"output/{lab.replace(' ', '_')}.png")
# fig.savefig(f"output/{lab.replace(' ', '_')}.pdf")
def plotting(data, col1='w_avg_dice', col2='o_avg_dice', choice='strategy', tie=False):
fig, ax = plt.subplots()
colors = {'blitz': 'blue', 'minimalist': 'red', 'sensible': 'green'}
for key in colors.keys():
ax.scatter(x=col1, y=col2, c=colors[key],
data=data.loc[data[choice] == key], alpha=min(1/len(data)*15000, 1), marker='.',
s=min(1/len(data)*90000, 2), label=key, )
horizontal = min(data[col1]), max(data[col1])
vertical = min(data[col2]), max(data[col2])
ax.plot([horizontal[0], horizontal[1]], [0, 0], c='black', lw=2, alpha=.5)
ax.plot([0, 0], [vertical[0], vertical[1]], c='black', lw=2, alpha=.5)
leg = ax.legend(frameon=False, markerscale=5, fontsize='x-large', loc='upper right')
for lh in leg.legendHandles:
lh.set_alpha(1)
ls = [x.replace('_', ' ').replace('o', "Other players'").replace('w', 'Winner').replace('avg', 'average')
for x in [col1, col2]]
ax.set(xlabel=ls[0], ylabel=ls[1])
for each in ['top', 'bottom', 'right', 'left']:
ax.spines[each].set_visible(False)
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()
plt.grid(True, 'major', 'y', ls='--', lw=.5, c='k', alpha=.3)
plt.tick_params(axis='both', which='both', bottom=True, top=False,
labelbottom=True, left=False, right=False, labelleft=True)
plt.savefig('output/{}_{}_{}.png'.format(col1, col2, tie), bbox_inches='tight')
# plt.savefig('{}_{}.pdf'.format(col1, col2), bbox_inches='tight')
plt.show()
if __name__ == '__main__':
c = pd.read_csv('data/simulation_output.csv', sep=';')
plotting(c)
plotting(c[c.tie], col2='2nd_avg_dice')
plotting(c[c.tie == False], col2='2nd_avg_dice')
p = 'strategy'
cs = ['sensible', 'minimalist', 'blitz']
t = 'n_countries'
plot_kde(c, cs, p, t)
t = 'o_avg_dice'
plot_kde(c, cs, p, t)
t = 'w_avg_dice'
plot_kde(c, cs, p, t)
p = 'goal'
cs = ['territory18', 'territory24', 'continent', 'destroy']
t = 'n_countries'
plot_kde(c, cs, p, t, 'n_countries_goal')