My question is kind of the 'too broad' category, but I already have been searching for hours, and my problem is still present.
I am making multiple (say 10) plots in a for cycle with my own Plotter function, and then saving them using savefig(). After that, I would like to make another plot and show it. No matter what I do, I still get 9 or 10 additional valid/empty plots.
for ...:
pyplot = Plotter.plotStuff(data[i])
pyplot.savefig(path)
pyplot.clf()
pyplot.plot(new_data)
pyplot.show() # showing additional plots
My main question is: how could I "get a fresh start" and erase my previous plots? I tried pyplot.clf(), pyplot.cla() and pyplot.hold(False) with no luck.
Also, could someone please explain how the pyplot/figure/subplot dynamics work, when is it making a new plot, where is stored my data/previous plots? I had the "additional empty plot" problem before, but I reordered my commands until it worked, but I still have no clue why.
For example, I have figure(), subplots_adjust(), plot(), xticks(), yticks() commands (in this order). What should be the order and why?
Thank you very much, I'm pulling my hair out.
pyplot = Plotter.plotStuff(data[i])you are assigning over the top ofpyplot, so if you were expectingpyplotto contain the same functions as thematplotlib.pyplotmodule you will be disappointed. I can't say much more without knowing what sort of objectPlotter.plotStuffreturns.plotStufffunction containspyplot.figure(), ...,pyplot.yticks()what I mentioned, and thenreturn pyplot. Actually, when I put apyplot.close()as @cmmnn mentioned in the answer below, it is working, and it's not a problem to overdefine thepyplotmodule with a modifiedpyplotmodule. Still renamed it just to be sure.pyplot.figure(number). Then you just call the pyplot functions likepyplot.function(), and it will make the effect on the selected figure. However, if I try to change the colour cycle, in the following way, it makes an empty figure 4, and puts the plots on figure 5:pyplot.figure(4), ax = pyplot.subplots()[1], ax.set_prop_cycle(cycler('color', ['y', 'r'])), pyplot.plot(data)