-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathplots.py
325 lines (233 loc) · 9.7 KB
/
plots.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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
'''
Plot functions to graphically present simulation results
'''
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
def setup_plots(suptitle):
'''
Basic setup of plots so it can be reused on plot functions
Parameters
----------
suptitle: string
Description of the plot that will appear on the top
Returns
-------
Figure and axis matplotlib structs
'''
plt.rc('font', family='serif')
plt.rc('font', size=44)
plt.rc('xtick', labelsize='x-small')
plt.rc('ytick', labelsize='x-small')
plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0), useMathText=True)
fig, ax = plt.subplots(1, 1, figsize=(16, 12))
# fig.suptitle(suptitle)
# for item in ([ax.title, ax.xaxis.label, ax.yaxis.label]):
# item.set_fontsize(30)
# for item in (ax.get_xticklabels() + ax.get_yticklabels()):
# item.set_fontsize(26)
# item.set_fontweight("normal")
# font = {'weight' : 'normal'}
# matplotlib.rc('font', **font)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
# Provide tick lines across the plot to help viewers trace along
# the axis ticks.
plt.grid(True, 'major', 'y', ls='--', lw=.5, c='k', alpha=.3)
# Remove the tick marks; they are unnecessary with the tick lines we just
# plotted.
plt.tick_params(axis='both', which='both', bottom=True, top=False,
labelbottom=True, left=False, right=False, labelleft=True)
return fig, ax
def plot_b_converging(b_converging, params):
'''
Plot the data each user is trying to offload till convergence
Parameters
----------
b_converging: 2-d array
Contains on each row the amount of data each user is trying to offload. Each row is
a different iteration
Returns
-------
Plot
'''
result = b_converging
# Each row on the transposed matrix contains the data the user offloads
# in each iteration. Different rows mean different user.
result = np.transpose(result)
suptitle = "Data each user is trying to offload in each iteration"
if params["ONE_FIGURE"] == False:
fig, ax = setup_plots(suptitle)
for index, row in enumerate(result):
# # display only some of the users on the plot
# if index%11 == 0:
# line = plt.plot(row, lw=4)
line = plt.plot(row, '-', lw=2, color='0.5')
average = np.mean(result, axis=0)
line = plt.plot(average, '-', lw=4, color='black')
plt.xlabel('iterations', fontweight='normal')
plt.ylabel('Amount of Offloaded Data [bits]', fontweight='normal')
plt.ticklabel_format(style='sci', axis='y', scilimits=(7,7), useMathText=True)
grey_lines = mlines.Line2D([], [], lw = 2, color='0.5', label='each user')
black_line = mlines.Line2D([], [], lw = 4, color='k', label='average')
plt.legend(handles=[grey_lines, black_line], loc=1, prop={'size': 24})
path_name = "b_converging"
if params["SAVE_FIGS"] == True and params["ONE_FIGURE"] == False:
plt.savefig("plots/" + path_name + ".png")
else:
plt.show(block=False)
def plot_expected_utility_converging(expected_utility_converging, params):
'''
Plot the expected utility of each user till convergence
Parameters
----------
expected_utility_converging: 2-d array
Contains on each row the expected utility of each user. Each row is
a different iteration
Returns
-------
Plot
'''
result = expected_utility_converging
# Each row on the transposed matrix contains the data the user offloads
# in each iteration. Different rows mean different user.
result = np.transpose(result)
suptitle = "Expected utility of each user in each iteration"
if params["ONE_FIGURE"] == False:
fig, ax = setup_plots(suptitle)
for index, row in enumerate(result):
# # display only some of the users on the plot
# if index%11 == 0:
# line = plt.plot(row, lw=4)
line = plt.plot(row, '-', lw=2, color='0.5')
average = np.mean(result, axis=0)
line = plt.plot(average, '-', lw=4, color='k')
plt.xlabel('iterations', fontweight='normal')
plt.ylabel("User's Expected Utility", fontweight='normal')
grey_lines = mlines.Line2D([], [], lw = 2, color='0.5', label='each user')
black_line = mlines.Line2D([], [], lw = 4, color='k', label='average')
plt.legend(handles=[grey_lines, black_line], loc=1, prop={'size': 24})
path_name = "expected_utility"
if params["SAVE_FIGS"] == True and params["ONE_FIGURE"] == False:
plt.savefig("plots/" + path_name + ".png")
else:
plt.show(block=False)
def plot_pricing_converging(pricing_converging, params):
'''
Plot the pricing set for each user till convergence
Parameters
----------
pricing_converging: 2-d array
Contains on each row the pricing for each user. Each row is
a different iteration
Returns
-------
Plot
'''
result = pricing_converging
# Each row on the transposed matrix contains the data the user offloads
# in each iteration. Different rows mean different user.
result = np.transpose(result)
suptitle = "Pricing each user in each iteration"
if params["ONE_FIGURE"] == False:
fig, ax = setup_plots(suptitle)
plt.ticklabel_format(style='sci', axis='y', scilimits=(7,7), useMathText=True)
for index, row in enumerate(result):
# # display only some of the users on the plot
# if index%11 == 0:
# line = plt.plot(row, lw=4)
line = plt.plot(row, '-', lw=2, color='0.5')
average = np.mean(result, axis=0)
line = plt.plot(average, '-', lw=4, color='k')
plt.xlabel('iterations', fontweight='normal')
plt.ylabel('Pricing', fontweight='normal')
grey_lines = mlines.Line2D([], [], lw = 2, color='0.5', label='each user')
black_line = mlines.Line2D([], [], lw = 4, color='k', label='average')
plt.legend(handles=[grey_lines, black_line], loc=1, prop={'size': 24})
path_name = "pricing"
if params["SAVE_FIGS"] == True and params["ONE_FIGURE"] == False:
plt.savefig("plots/" + path_name + ".png")
else:
plt.show(block=False)
def plot_PoF_converging(PoF_converging, params):
'''
Plot the probability of failure of MEC server till convergence
Parameters
----------
PoF_converging: 1-d array
Contains the probability of failure of the MEC server in each iteration
Returns
-------
Plot
'''
result = PoF_converging
# Each row on the transposed matrix contains the data the user offloads
# in each iteration. Different rows mean different user.
result = np.transpose(result)
suptitle = "Probability of failure of MEC server in each iteration"
if params["ONE_FIGURE"] == False:
fig, ax = setup_plots(suptitle)
line = plt.plot(result, '--', lw=4, color='k')
plt.xlabel('iterations', fontweight='normal')
plt.ylabel('PoF', fontweight='normal')
path_name = "PoF"
if params["SAVE_FIGS"] == True and params["ONE_FIGURE"] == False:
plt.savefig("plots/" + path_name + ".png")
else:
plt.show(block=False)
def plot_expected_utility_and_pricing_converging(expected_utility_converging, pricing_converging, params):
'''
Plot the average explitic utility and pricing of users till convergence
Parameters
----------
expected_utility_converging: 2-d array
Contains on each row the expected utility of each user. Each row is
a different iteration
pricing_converging: 2-d array
Contains on each row the pricing for each user. Each row is
a different iteration
Returns
-------
Plot
'''
# colors = ['k', '0.5']
# line_types = ['--', ':']
colors = ['darkorange', 'darkgreen']
line_types = ['-', '-']
result1 = expected_utility_converging
result2 = pricing_converging
# Each row on the transposed matrix contains the data the user offloads
# in each iteration. Different rows mean different user.
result1 = np.transpose(result1)
result2 = np.transpose(result2)
suptitle = "Average expected utility and expected pricing for each user in each iteration"
if params["ONE_FIGURE"] == False:
plt.rc('font', family='serif')
plt.rc('font', size=44)
plt.rc('xtick', labelsize='x-small')
plt.rc('ytick', labelsize='x-small')
plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0), useMathText=True)
fig = plt.figure(figsize=(16,12))
host = host_subplot(111, axes_class=AA.Axes)
plt.subplots_adjust(right=0.85)
ax2 = host.twinx() # instantiate a second axes that shares the same x-axis
ax2.axis["right"].toggle(all=True)
ax2.ticklabel_format(style='sci', axis='y', scilimits=(7,7), useMathText=True)
average1 = np.mean(result1, axis=0)
line1, = host.plot(average1, line_types[0], lw=4, color=colors[0], label='expected utility')
host.set_xlabel('iterations', fontweight='normal')
host.set_ylabel('Average Expected Utility', fontweight='normal')
ax2.set_ylabel('Average Pricing', fontweight='normal')
average2 = np.mean(result2, axis=0)
line2, = ax2.plot(average2, line_types[1], lw=4, color=colors[1], label="pricing")
# host.axis["left"].label.set_color(line1.get_color())
# ax2.axis["right"].label.set_color(line2.get_color())
host.legend(loc=1, prop={'size': 24})
path_name = "expected_utility_and_pricing"
if params["SAVE_FIGS"] == True and params["ONE_FIGURE"] == False:
plt.savefig("plots/" + path_name + ".png")
else:
plt.show(block=False)