【问题标题】:Matplotlib: plot multiple individual plots in a loopMatplotlib:在一个循环中绘制多个单独的图
【发布时间】:2014-08-12 20:18:25
【问题描述】:

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

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)

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

【问题讨论】:

    标签: python matplotlib plot graphing


    【解决方案1】:

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

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-16
      • 2019-06-30
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      相关资源
      最近更新 更多