savefig loop adds previous plots to figure

后端 未结 2 829
再見小時候
再見小時候 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.

提交回复
热议问题