Difference between plt.close() and plt.clf()

前端 未结 4 1660
猫巷女王i
猫巷女王i 2020-12-29 03:49

In Python, what is the difference between plt.clf() and plt.close()?

Will they function the same way?

4条回答
  •  星月不相逢
    2020-12-29 04:42

    I think it is worth mentioning that plt.close() releases the memory, thus is preferred when generating and saving many figures in one run.

    Using plt.clf() in such case will produce a warning after 20 plots (even if they are not going to be shown by plt.show()):

    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.

提交回复
热议问题