/
open_fig_7.py
136 lines (118 loc) · 4.54 KB
/
open_fig_7.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import os
from matplotlib import colors
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
SMALL_SIZE = 16
MEDIUM_SIZE = 20
BIGGER_SIZE = 25
plt.rc('font', size=SMALL_SIZE) # controls default text sizes
plt.rc('axes', titlesize=BIGGER_SIZE) # fontsize of the axes title
plt.rc('axes', labelsize=BIGGER_SIZE) # fontsize of the x and y labels
plt.rc('xtick', labelsize=MEDIUM_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=MEDIUM_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE) # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title
blue_div = np.array([61 / 255, 139 / 255, 240 / 255])
blue = np.array([67 / 255, 114 / 255, 189 / 255])
red = np.array([159 / 255, 58 / 255, 65 / 255])
red_div = np.array([240 / 255, 58 / 255, 65 / 255])
gmin = -1
gmax = 2
n = 50
def color(t):
i = int(n * (t + 1) / 3)
if t == float('inf'):
c = np.array([0 / 255, 0 / 255, 0 / 255])
elif i < n * (-gmin) / (gmax - gmin):
a = n * (-gmin) / (gmax - gmin)
c = (a - i) / a * blue_div + i / a * blue
elif i < n * (1 - gmin) / (gmax - gmin):
a = n * (1 - gmin) / (gmax - gmin)
b = n * (-gmin) / (gmax - gmin)
c = (a - i) / (a - b) * blue + (i - b) / (a - b) * red
else:
a = n
b = n * (1 - gmin) / (gmax - gmin)
c = (a - i) / (a - b) * red + (i - b) / (a - b) * red_div
return c[0], c[1], c[2]
L = []
for t in np.linspace(-1, 2, n):
L.append(color(t))
cm = LinearSegmentedColormap.from_list(
'cmap', L, N=n)
res = 250
R_tm = np.zeros((res, res))
R_tf = np.zeros((res, res))
R_sd = np.zeros((res, res))
thisdir = 'results/fig_7'
for r, d, f in os.walk(thisdir): # r=root, d=directories, f = files
for file in f:
if file != '.DS_Store':
f = file.split("_")
X = np.load(thisdir + '/' + f[0] + '_' + f[1][:-4] + '.npy')
R_tm[int(f[0]), int(f[1][:-4])] = X[0]
R_tf[int(f[0]), int(f[1][:-4])] = X[1]
R_sd[int(f[0]), int(f[1][:-4])] = np.abs(X[0] - X[1])
eps = 0.01
fig, ax = plt.subplots(1)
plt.imshow(R_tm.T, extent=[0, 20, 0, 0.1], aspect=20 / 0.1, origin='lower', cmap=cm, vmin=-1,
vmax=2) # , interpolation='bicubic')
plt.colorbar()
# plt.title(r'$\overline{t}_m$')
plt.xlabel(r'$N$')
plt.ylabel(r'$\lambda$')
plt.xticks([0, 10, 20])
plt.yticks([0, 0.05, 0.1])
# ax.axhline(0.1, 0, 1, color='yellow', linestyle='--')
plt.tight_layout()
fig, ax = plt.subplots(1)
plt.imshow(R_tf.T, extent=[0, 20, 0, 0.1], aspect=20 / 0.1, origin='lower', cmap=cm, vmin=-1,
vmax=2) # , interpolation='bicubic')
plt.colorbar()
# plt.title(r'$\overline{t}_f$')
plt.xlabel(r'$N$')
plt.ylabel(r'$\lambda$')
plt.xticks([0, 10, 20])
plt.yticks([0, 0.05, 0.1])
# ax.axhline(0.1, 0, 1, color='yellow', linestyle='--')
plt.tight_layout()
SMALL_SIZE = 8
MEDIUM_SIZE = 12
BIGGER_SIZE = 17
plt.rc('font', size=SMALL_SIZE) # controls default text sizes
plt.rc('axes', titlesize=BIGGER_SIZE) # fontsize of the axes title
plt.rc('axes', labelsize=BIGGER_SIZE) # fontsize of the x and y labels
plt.rc('xtick', labelsize=MEDIUM_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=MEDIUM_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE) # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title
fig, ax = plt.subplots(1)
plt.imshow(R_sd.T, extent=[0, 20, 0, 0.1], aspect=20 / 0.1, origin='lower') # , interpolation='bicubic')
plt.colorbar()
pas = 20 / res
x = np.linspace(0 + pas, 20 - pas, res)
pas = 0.1 / res
y = np.linspace(0 + pas, 0.1 - pas, res)
X, Y = np.meshgrid(x, y)
Z = R_sd.T
# CS = ax.contour(x, y, Z, levels=[0.31, 0.325, 0.35, 0.4], colors = 'tab:red')
CS = ax.contour(x, y, Z, levels=[0.3], colors='tab:red')
ax.clabel(CS, inline=True, fontsize=10)
# plt.title('female-limited mimicry caused by RI')
plt.xlabel(r'$N$')
plt.ylabel(r'$\lambda$')
# ax.axhline(0.1, 0, 1, color='yellow', linestyle='--')
plt.tight_layout()
# cmap = plt.get_cmap()
# bounds=np.linspace(np.min(R_sd), np.max(R_sd), 25)
# norm = colors.BoundaryNorm(bounds, cmap.N)
#
# fig, ax = plt.subplots(1)
# plt.imshow(R_sd.T, extent=[0, 20, 0, 0.1], aspect= 20 / 0.1, origin='lower', norm=norm) # , interpolation='bicubic')
# plt.colorbar(ticks=[0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4])
# #plt.title('female-limited mimicry caused by sexually constrasted predation')
# plt.xlabel(r'$N$')
# plt.ylabel(r'$\lambda$')
# # ax.axhline(0.1, 0, 1, color='yellow', linestyle='--')
# plt.tight_layout()