我正在通過不同的方法解決優化問題(用于研究)。想法寫如下:instance = class_with_diff_methods()instance.create_some_func()instance.optimization_method_one()instance.create_data_for_plot()instance.display()instance.optimization_method_two()instance.create_data_for_plot()instance.display()所以我想迭代地添加新數據,而不保存,我這樣實現了我的想法:`import matplotlib.pyplot as plt def display(self): if not self.__plot_exists: self.figure = plt.figure() plt.scatter( self.data[0], self.data[1]) plt.plot( self.data[0], self.appdata) self.figure.show() self.__plot_exists = True else: plt.plot( self.data[0], self.appdata) plt.show( block=False)`這是可行的,但問題是我真的不明白,為什么我什至需要(有必要)在代碼的第一部分使用“self.figure”以及為什么我應該使用“plt.show()”而不是只是最后一行的“self.figure.show”。我將不勝感激鏈接,這將幫助我清楚地了解這是如何工作的。
添加回答
舉報
0/150
提交
取消