-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_graphs.py
45 lines (37 loc) · 1.32 KB
/
plot_graphs.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
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
import operator
def plot_boxplot(best_fitness, description):
fig1, ax1 = plt.subplots()
ax1.set_title(description)
ax1.boxplot(best_fitness, patch_artist=True, showfliers=False)
ax1.legend()
plt.savefig(f"{description}.png")
def plot_convergence_graphs(average_best_fitness, optimal, description):
fig, ax = plt.subplots()
ax.plot(list(range(0, 1000)), average_best_fitness, 'b', label=f"Optimal: {optimal}\n Best: {average_best_fitness[-1]:.2f}")
ax.set_title(description)
ax.set_xlabel("Iterations")
ax.set_ylabel("Best Cost")
ax.legend()
plt.savefig(f'{description}.png')
def plot_path(points, path, description):
x = []
y = []
for point in points:
x.append(point[0])
y.append(point[1])
# noinspection PyUnusedLocal
y = list(map(operator.sub, [max(y) for i in range(len(points))], y))
plt.plot(x, y, 'co')
for _ in range(1, len(path)):
i = path[_ - 1]
j = path[_]
# noinspection PyUnresolvedReferences
plt.arrow(x[i], y[i], x[j] - x[i], y[j] - y[i], color='r', length_includes_head=True)
# noinspection PyTypeChecker
plt.xlim(0, max(x) * 1.1)
# noinspection PyTypeChecker
plt.ylim(0, max(y) * 1.1)
plt.savefig(f'{description}.png')