savefig loop adds previous plots to figure

后端 未结 2 820
再見小時候
再見小時候 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:15

    I made some beautiful charts before I included plt.clf() to clear the plot each time through the loop. scatterplot1 scatterplot2

    In other words, my previous plots were being added to a single figure as shown in the lots above, within my for loop as well. adding [plt.clf()] to clear the plot each time through the loop fixed this problem being clearing the figure before starting the loop iteration at the top to create a new figure with new plots.

    TLDR; I included plt.clf() to clear the plot each time through the loop.

    0 讨论(0)
  • 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

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