matplotlib.pyplot plot()导致程序崩溃

时间:2018-07-28 16:43:42

标签: python matplotlib plot

我有一个情节,我每分钟更新一次,然后保存。它不断导致我的程序在50-300次迭代后崩溃。

如何防止程序崩溃?

代码:

        fig = plt.figure(2)
        plt.cla()
        epochs = range(1, len(self.loss) + 1)
        plt.plot(epochs, np.array(self.loss),
                 label='%s ( "%f" )' % ("loss", min(self.loss)))
        plt.plot(epochs, np.array(self.val_loss),
                 label='%s ( "%f" )' % ("validation loss", min(self.val_loss)))
        plt.title("loss")
        plt.xlabel('Epochs')
        plt.ylabel('loss')
        self._save_plot_show_without_blocking(fig, "loss")
        plt.legend()
        fig.savefig(self.figure_save_path + '/%s.png' % name, bbox_inches='tight')
        plt.pause(3)
        plt.close()

错误消息:

File "C:\Users\dan\AppData\Local\Programs\Python\Python36\lib\tkinter\__init__.py", line 3501, in __del__
    self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop

0 个答案:

没有答案