-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGMCA_plotting_functions.py
More file actions
220 lines (179 loc) · 8.77 KB
/
GMCA_plotting_functions.py
File metadata and controls
220 lines (179 loc) · 8.77 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 2 14:12:58 2025
@author: Victoria Johnson
"""
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
gamma = np.array(pd.read_csv('Model_Data/gamma.csv', header = None))
red_hex = "#EDB120"
blue_hex = "#0072BD"
yellow_hex = "#D95319"
xticklabels = ['BOL', 'BUR', 'MAN', 'OLD', 'ROC', 'SAL', 'STO', 'TAM', 'TRA', 'WIG']
current_funding = [5.859925, 3.576419, 25.182064, 6.074565, 4.743212, 6.191460, 1.210294, 3.659896, 5.819492, 4.323831]
LA_params = pd.read_csv('Model_Data/LA_params.csv')
xticklabels = LA_params["xticklabels"].to_list()
def plot_scatter_exploded(F):
pointsize = 5
highest_HLE = np.argmax(-F[:,0])
lowest_HLE_inequality = np.argmax(-F[:,1])
lowest_cost = np.argmax(-F[:,2])
fig, ([ax1, ax2, ax3]) = plt.subplots(3, 1, figsize =(7, 12))
# Scatter plot 1: Average HLE (x), HLE inequality (y)
ax1.scatter(-F[:, 0], F[:, 1], s = pointsize, c = 'k')
ax1.scatter(-F[lowest_cost, 0], F[lowest_cost, 1], s = 100, c = blue_hex)
ax1.scatter(-F[lowest_HLE_inequality, 0], F[lowest_HLE_inequality, 1], s = 100, c = red_hex)
ax1.scatter(-F[highest_HLE, 0], F[highest_HLE, 1], s = 100, c = yellow_hex)
ax1.set_xlabel('Average HLE')
ax1.set_ylabel('HLE inequality')
# Scatter plot 2: Average HLE (x), cost (y)
ax2.scatter(F[:, 2], -F[:, 0], s = pointsize, c = 'k')
ax2.scatter(F[lowest_cost, 2], -F[lowest_cost, 0], s = 100, c = blue_hex)
ax2.scatter(F[lowest_HLE_inequality, 2], -F[lowest_HLE_inequality, 0], s = 100, c = red_hex)
ax2.scatter(F[highest_HLE, 2], -F[highest_HLE, 0], s = 100, c = yellow_hex)
ax2.set_ylabel('Average HLE')
ax2.set_xlabel('Cost (£m)')
# Scatter plot 2: HLE inequality (x), cost (y)
ax3.scatter(F[:, 2], F[:, 1], s = pointsize, c = 'k')
ax3.scatter(F[lowest_cost, 2], F[lowest_cost, 1], s = 100, c = blue_hex)
ax3.scatter(F[lowest_HLE_inequality, 2], F[lowest_HLE_inequality, 1], s = 100, c = red_hex)
ax3.scatter(F[highest_HLE, 2], F[highest_HLE, 1], s = 100, c = yellow_hex)
ax3.set_ylabel('HLE inequality')
ax3.set_xlabel('Cost (£m)')
ax1.legend(['Non-dominated point',
'Lowest cost solution',
'Lowest HLE inequality solution',
'Highest average HLE solution'])
plt.savefig('Plots/objective_scatter_2d.eps', bbox_inches="tight")
plt.savefig('Plots/objective_scatter_2d.png', bbox_inches="tight")
plt.show()
def plot_boxplot_funding(X):
fig, ([ax1, ax2]) = plt.subplots(2, 1, figsize =(9, 6))
plt.suptitle("Funding (£m)")
ax2.boxplot(X[:, 0:20:2])
ax2.set_ylabel('Labour remuneration')
ax2.set_xticklabels(xticklabels)
ax1.boxplot(X[:, 1:20:2] + current_funding)
ax1.set_ylabel('Adult skills')
ax1.set_xticklabels(xticklabels)
plt.savefig('Plots/boxplot_funding.eps', bbox_inches="tight")
plt.savefig('Plots/boxplot_funding.png', bbox_inches="tight")
plt.show()
def plot_3d_scatter(F):
highest_HLE = np.argmax(-F[:,0])
lowest_HLE_inequality = np.argmax(-F[:,1])
lowest_cost = np.argmax(-F[:,2])
fig = plt.figure(figsize = (8,8))
ax = fig.add_subplot(projection='3d')
ax.scatter(-F[:, 0], F[:, 1], F[:, 2], c = 'k', s = 3)
ax.scatter(-F[lowest_cost, 0], F[lowest_cost, 1], F[lowest_cost, 2], c = blue_hex, s = 50)
ax.scatter(-F[lowest_HLE_inequality, 0], F[lowest_HLE_inequality, 1], F[lowest_HLE_inequality, 2], s = 50, c = red_hex)
ax.scatter(-F[highest_HLE, 0], F[highest_HLE, 1], F[highest_HLE, 2], c = yellow_hex, s = 50)
plt.title("Objective space")
ax.set_xlabel("f_1: maximise weighted average HLE")
ax.set_ylabel("f_2: minimise HLE inequality")
ax.set_zlabel("f_3: minimise cost")
plt.savefig('Plots/objective_scatter_3d.eps', bbox_inches="tight", pad_inches = 0.5)
plt.savefig('Plots/objective_scatter_3d.png', bbox_inches="tight", pad_inches = 0.5)
plt.show()
def plot_boxplot_percentages(u_transformed):
fig, ([ax1, ax2]) = plt.subplots(2, 1, figsize =(9, 8))
ax1.boxplot(u_transformed[:, 1:20:2])
ax1.set_xticklabels(xticklabels)
ax1.set_ylabel('% NVQ2+')
ax1.scatter(np.arange(1, 11), gamma[:,2], c = 'r', marker = 'x')
ax1.set_title("Adult skills")
ax2.boxplot(u_transformed[:, 0:20:2])
ax2.set_xticklabels(xticklabels)
ax2.set_ylabel('% below real living wage')
ax2.scatter(np.arange(1, 11), gamma[:,0], c = 'r', marker = 'x')
ax2.set_title("Labour remuneration")
fig.subplots_adjust(hspace=0.3)
plt.savefig('Plots/boxplot_percentages.eps', bbox_inches="tight")
plt.savefig('Plots/boxplot_percentages.png', bbox_inches="tight")
plt.show()
def plot_constraint_evolution(opt_G):
plt.plot(range(0, len(opt_G)), opt_G)
plt.xlabel("Generations")
plt.ylabel("G constraint")
plt.title("Constraint progress")
plt.show()
def plot_key_parcoord(F, X):
highest_HLE = np.argmax(-F[:,0])
lowest_HLE_inequality = np.argmax(-F[:,1])
lowest_cost = np.argmax(-F[:,2])
fig, ([ax1, ax2]) = plt.subplots(2, 1, figsize =(12, 7))
ax1.plot(np.arange(0, 10), X[lowest_cost, 0:20:2], c = blue_hex, linewidth = 3)
ax1.plot(np.arange(0, 10), X[lowest_HLE_inequality, 0:20:2], c = red_hex, linewidth = 3)
ax1.plot(np.arange(0, 10), X[highest_HLE, 0:20:2], c = yellow_hex, linewidth = 3)
ax1.set_xticks(np.arange(0, 10))
ax1.set_xticklabels(xticklabels)
ax1.set_xlabel("LAD")
ax1.set_ylabel("Funding (£m)")
ax1.set_title("Labour remuneration funding")
ax2.plot(np.arange(0, 10), X[lowest_cost, 1:20:2] + current_funding, c = blue_hex, linewidth = 3)
ax2.plot(np.arange(0, 10), X[lowest_HLE_inequality, 1:20:2] + current_funding, c = red_hex, linewidth = 3)
ax2.plot(np.arange(0, 10), X[highest_HLE, 1:20:2] + current_funding, c = yellow_hex, linewidth = 3)
ax2.set_xticks(np.arange(0, 10))
ax2.set_xticklabels(xticklabels)
ax2.set_xlabel("LAD")
ax2.set_ylabel("Funding (£m)")
ax2.set_title("Adult skills funding")
ax2.legend(['Lowest cost solution',
'Lowest HLE inequality solution',
'Highest average HLE solution'],
loc = 'upper right')
fig.subplots_adjust(hspace=0.3)
plt.suptitle("Absolute funding (£m)")
plt.savefig('Plots/key_solutions_parcoord_absolute.eps', bbox_inches="tight")
plt.savefig('Plots/key_solutions_parcoord_absolute.png', bbox_inches="tight")
plt.show()
fig, ([ax1, ax2]) = plt.subplots(2, 1, figsize =(12, 7))
ax1.plot(np.arange(0, 10), X[lowest_cost, 0:20:2], c = blue_hex, linewidth = 3)
ax1.plot(np.arange(0, 10), X[lowest_HLE_inequality, 0:20:2], c = red_hex, linewidth = 3)
ax1.plot(np.arange(0, 10), X[highest_HLE, 0:20:2], c = yellow_hex, linewidth = 3)
ax1.set_xticks(np.arange(0, 10))
ax1.set_xticklabels(xticklabels)
ax1.set_xlabel("LAD")
ax1.set_ylabel("Funding (£m)")
ax1.set_title("Labour remuneration funding")
ax2.plot(np.arange(0, 10), X[lowest_cost, 1:20:2], c = blue_hex, linewidth = 3)
ax2.plot(np.arange(0, 10), X[lowest_HLE_inequality, 1:20:2], c = red_hex, linewidth = 3)
ax2.plot(np.arange(0, 10), X[highest_HLE, 1:20:2], c = yellow_hex, linewidth = 3)
ax2.set_xticks(np.arange(0, 10))
ax2.set_xticklabels(xticklabels)
ax2.plot(np.arange(0, 10), np.zeros(10), c = "#A3A3A3", linewidth = 3, linestyle = "--")
ax2.set_xlabel("LAD")
ax2.set_ylabel("Funding (£m)")
ax2.set_title("Adult skills funding")
ax2.legend(['Lowest cost solution',
'Lowest HLE inequality solution',
'Highest average HLE solution'],
loc = 'lower right')
fig.subplots_adjust(hspace=0.3)
plt.suptitle("Relative funding (£m)")
plt.savefig('Plots/key_solutions_parcoord_relative.eps', bbox_inches="tight")
plt.savefig('Plots/key_solutions_parcoord_relative.png', bbox_inches="tight")
plt.show()
def violin_plot(X):
g = sns.violinplot([X[:, 20], X[:, 21] + sum(current_funding)], cut = 0, inner = "quart")
g.set_xticks([0,1])
g.set_xticklabels(["Labour remuneration", "Adult skills"])
plt.ylabel("Absolute funding (£m)")
plt.show()
fig = g.get_figure()
fig.savefig('Plots/violin_funding_absolute.eps', bbox_inches="tight")
fig.savefig('Plots/violin_funding_absolute.png', bbox_inches="tight")
def get_max_min():
max_vals = np.zeros((21, 3))
min_vals = np.zeros((21, 3))
for rep_no in range(0, 21):
F = np.array(pd.read_csv(f'Results/rep{str(rep_no)}_F.csv'))
F[:, 0] = -F[:, 0]
max_vals[rep_no, :] = np.max(F, 0)
min_vals[rep_no, :] = np.min(F, 0)
min_all = np.min(min_vals, 0)
max_all = np.max(max_vals, 0)
return min_all, max_all