You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pygad/visualize/plot.py
+78-21Lines changed: 78 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@
5
5
importnumpy
6
6
importwarnings
7
7
importmatplotlib.pyplot
8
+
importpygad
8
9
9
10
classPlot:
10
11
defplot_result(self,
@@ -14,7 +15,7 @@ def plot_result(self,
14
15
linewidth=3,
15
16
font_size=14,
16
17
plot_type="plot",
17
-
color="#3870FF",
18
+
color="#64f20c",
18
19
save_dir=None):
19
20
20
21
ifnotself.suppress_warnings:
@@ -30,14 +31,15 @@ def plot_result(self,
30
31
save_dir=save_dir)
31
32
32
33
defplot_fitness(self,
33
-
title="PyGAD - Generation vs. Fitness",
34
-
xlabel="Generation",
35
-
ylabel="Fitness",
36
-
linewidth=3,
37
-
font_size=14,
38
-
plot_type="plot",
39
-
color="#3870FF",
40
-
save_dir=None):
34
+
title="PyGAD - Generation vs. Fitness",
35
+
xlabel="Generation",
36
+
ylabel="Fitness",
37
+
linewidth=3,
38
+
font_size=14,
39
+
plot_type="plot",
40
+
color="#64f20c",
41
+
label=None,
42
+
save_dir=None):
41
43
42
44
"""
43
45
Creates, shows, and returns a figure that summarizes how the fitness value evolved by generation. Can only be called after completing at least 1 generation. If no generation is completed, an exception is raised.
@@ -47,9 +49,10 @@ def plot_fitness(self,
47
49
xlabel: Label on the X-axis.
48
50
ylabel: Label on the Y-axis.
49
51
linewidth: Line width of the plot. Defaults to 3.
50
-
font_size: Font size for the labels and title. Defaults to 14.
52
+
font_size: Font size for the labels and title. Defaults to 14. Can be a list/tuple/numpy.ndarray if the problem is multi-objective optimization.
51
53
plot_type: Type of the plot which can be either "plot" (default), "scatter", or "bar".
52
-
color: Color of the plot which defaults to "#3870FF".
54
+
color: Color of the plot which defaults to "#64f20c". Can be a list/tuple/numpy.ndarray if the problem is multi-objective optimization.
55
+
label: The label used for the legend in the figures of multi-objective problems. It is not used for single-objective problems.
53
56
save_dir: Directory to save the figure.
54
57
55
58
Returns the figure.
@@ -60,15 +63,69 @@ def plot_fitness(self,
60
63
raiseRuntimeError("The plot_fitness() (i.e. plot_result()) method can only be called after completing at least 1 generation but ({self.generations_completed}) is completed.")
0 commit comments