Matplotlib:在一个循环中绘制多个单独的图 [英] Matplotlib: plot multiple individual plots in a loop

查看:54
本文介绍了Matplotlib:在一个循环中绘制多个单独的图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

需要在每次 plot 调用前清除图形:

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)

这篇关于Matplotlib:在一个循环中绘制多个单独的图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆