Thanks for using PyGAD.
Unfortunately, the plot_result()
method does not return the created figure and thus you cannot save it. But do not worry, you can still save the figure.
The plot_result()
simply plots the data saved in the best_solutions_fitness
attribute. This attribute can be accessed anywhere using the instance of the pygad.GA
class.
You can simply use the best_solutions_fitness
attribute to rebuild the figure and save it. Here is what you should do:
Rather than calling the plot_result()
method, simply use the next code which creates the figure, shows the same plot created using the plot_result()
method, and saves it.
import matplotlib.pyplot
matplotlib.pyplot.figure()
matplotlib.pyplot.plot(ga_instance.best_solutions_fitness)
matplotlib.pyplot.savefig("PyGAD_figure.jpg")
matplotlib.pyplot.show()
Please let me know if you have any other questions.
Again, thanks for using PyGAD :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…