savefig loop adds previous plots to figure

后端 未结 2 819
再見小時候
再見小時候 2020-12-15 19:51

I am trying to use a forloop to produce figures for each set of data I have, but while the .show() command produces the correct figure, .savefig() keeps adding the previous

2条回答
  •  有刺的猬
    2020-12-15 20:38

    You have to close current figure after saving with function plt.close(): http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.close

    Or you have to clean current figure after saving by plt.clf(): http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.clf

提交回复
热议问题