【发布时间】:2020-07-17 04:29:01
【问题描述】:
我有一个重复运行的脚本,在此过程中它会将图形保存到文件夹中。过了一会儿,我开始收到有关内存中打开的数字过多的警告。
我检查了有关该主题的其他问题,例如,this one 并将plt.close('all') 添加到我的代码中,所以现在它看起来像这样:
fig, ax = plt.subplots(figsize=(17,8))
plt.hist(results_df['Diff'], bins=100, density=True, histtype='step')
plt.savefig(f'backtester_results/figures/rf_model_{n_days}_data_and_{lag}_lag.png',
format='png')
plt.close('all')
但一段时间后,我不断在记忆中堆积数字和警告。我哪里做错了?
这是警告:
RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (matplotlib.pyplot.figure) are retained until explicitly closed and may consume too much memory.
【问题讨论】:
-
请包括您收到的警告。
标签: python matplotlib