RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface

问题描述

使用 matplotlib 绘制多幅图出现如下问题 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. (To control this warning, see the rcParam figure.max_open_warning). fig, ax = plt.subplots(figsize=(10, 10))

在这里插入图片描述

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. (To control this warning, see the rcParam `figure.max_open_warning`).
  fig, ax = plt.subplots(figsize=(10, 10))

原因分析:

出现这种问题就是你同时绘制了多幅子图会占用大量内存,提醒你不需要时将其关闭

解决方案:

在循环内,每次使用 plt.plot() 绘制结果后,使用代码将其关闭,再重新绘制新的子图

plt.close()

猜你喜欢

转载自blog.csdn.net/m0_47256162/article/details/129879577