matplotlib.pyplot will not forget previous plots - how can I flush/refresh?

前端 未结 2 1878
灰色年华
灰色年华 2020-11-28 04:46

How do you get matplotlib.pyplot to \"forget\" previous plots

I am trying to plot multiple time using matplotlib.pyplot

The code lo

相关标签:
2条回答
  • 2020-11-28 05:00

    I would rather use plt.clf() after every plt.show() to just clear the current figure instead of closing and reopening it, keeping the window size and giving you a better performance and much better memory usage.

    Similarly, you could do plt.cla() to just clear the current axes.

    To clear a specific axes, useful when you have multiple axes within one figure, you could do for example:

    fig, axes = plt.subplots(nrows=2, ncols=2)
    
    axes[0, 1].clear()
    
    0 讨论(0)
  • 2020-11-28 05:05

    I discovered that this behaviour only occurs after running a particular script, similar to the one in the question. I have no idea why it occurs.

    It works (refreshes the graphs) if I put

    plt.clf()
    plt.cla()
    plt.close()
    

    after every plt.show()

    0 讨论(0)
提交回复
热议问题