Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit517612c

Browse files
authored
Two changes in the plot_result() method.
1) Rename the parameter to `save_dir`. If it is not None, then save.2) Keep the .show() function called regardless of saving the figure or not.
1 parentccfe679 commit517612c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

‎pygad.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,7 @@ def best_solution(self, pop_fitness=None):
25302530

25312531
returnbest_solution,best_solution_fitness,best_match_idx
25322532

2533-
defplot_result(self,title="PyGAD - Iteration vs. Fitness",xlabel="Generation",ylabel="Fitness",linewidth=3,save_as=None):
2533+
defplot_result(self,title="PyGAD - Iteration vs. Fitness",xlabel="Generation",ylabel="Fitness",linewidth=3,save_dir=None):
25342534

25352535
"""
25362536
Creates and shows a plot 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.
@@ -2540,7 +2540,7 @@ def plot_result(self, title="PyGAD - Iteration vs. Fitness", xlabel="Generation"
25402540
xlabel: Label on the X-axis.
25412541
ylabel: Label on the Y-axis.
25422542
linewidth: Line width of the plot.
2543-
save_as: save image instead of showing it.
2543+
save_dir: Directory to save the figure.
25442544
25452545
Returns the figure.
25462546
"""
@@ -2557,10 +2557,10 @@ def plot_result(self, title="PyGAD - Iteration vs. Fitness", xlabel="Generation"
25572557
matplotlib.pyplot.xlabel(xlabel)
25582558
matplotlib.pyplot.ylabel(ylabel)
25592559

2560-
ifsave_asisNone:
2561-
matplotlib.pyplot.show()# show plot
2562-
else:
2563-
fig.savefig(f'{save_as}.png')# save as image
2560+
ifnotsave_dirisNone:
2561+
matplotlib.pyplot.savefig(fname=save_dir,
2562+
bbox_inches='tight')
2563+
matplotlib.pyplot.show()
25642564

25652565
returnfig
25662566

@@ -2589,4 +2589,4 @@ def load(filename):
25892589
raiseFileNotFoundError("Error reading the file {filename}. Please check your inputs.".format(filename=filename))
25902590
except:
25912591
raiseBaseException("Error loading the file. Please check if the file exists.")
2592-
returnga_in
2592+
returnga_in

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp