How to clear memory completely of all Matplotlib plots

后端 未结 3 593
粉色の甜心
粉色の甜心 2020-12-05 17:50

I have data analysis module that contains functions which call on Matplotlib pyplot API multiple times to generate up to 30 figures in each run. These figures get immediatel

3条回答
  •  执念已碎
    2020-12-05 18:26

    Especially when you are running multiple processes or threads, it is much better to define your figure variable and work with it directly:

    from matplotlib import pyplot as plt
    
    f = plt.figure()
    f.clear()
    plt.close(f)
    

    In any case, you must combine the use of plt.clear() and plt.close()

提交回复
热议问题