问题
I want to plot multiple benchmarks, each on a separate plot. Here's my code:
for benchmark in benchmarks:
readFile = open(benchmark+'.txt')
text = readFile.read()
x = re.findall(r"(\d+)",text)
x = [int(i) for i in liveRatio]
pylab.plot(x)
F = pylab.gcf()
F.savefig('benchmark',dpi=200)
The code plots all the data on the same plot. But, I want individual separate plots for each benchmark.
回答1:
You need to clear the figure before each plot call:
for benchmark in benchmarks:
readFile = open(benchmark+'.txt')
text = readFile.read()
x = re.findall(r"(\d+)",text)
x = [int(i) for i in liveRatio]
#clear the figure
pylab.clf()
pylab.plot(x)
F = pylab.gcf()
F.savefig('benchmark',dpi=200)
On a second note each time you iterate the figure will be overwritten so I suggest something like this:
F.savefig(benchmark+'.png',dpi=200)
来源:https://stackoverflow.com/questions/25273365/matplotlib-plot-multiple-individual-plots-in-a-loop