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

前端 未结 2 1897
灰色年华
灰色年华 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()
    

提交回复
热议问题