Python Matplotlib:在循环中打印多个单独的打印

Python Matplotlib:在循环中打印多个单独的打印,python,matplotlib,plot,graphing,Python,Matplotlib,Plot,Graphing,我想绘制多个基准,每个基准都在一个单独的绘图上。这是我的密码: 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('benchmar

我想绘制多个基准,每个基准都在一个单独的绘图上。这是我的密码:

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)

代码将所有数据绘制在同一绘图上。但是,我希望每个基准都有单独的绘图。

在每次绘图调用之前,您需要清除该图:

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)
另一个注意事项是,每次迭代时,图形都会被覆盖,因此我建议如下:

   F.savefig(benchmark+'.png',dpi=200)