在for循环中使用不同的名称保存。蟒蛇

时间:2015-10-02 14:18:44

标签: python

我计算盖子驱动腔体中的流量,然后用箭头绘制结果。我想在每个时间步骤中保存情节,但显然,因为名称相同,所以只保留最后一个,我该怎么做?

clear all

n = 201;


PP=[];
pathname = 'D:\';
addpath(pathname);

for Y = 1:20           
 for B = 1:2          
  for z = 1:50;          
   for R = 1:2;     
    for I = 1:5;

     filename = strcat('F', num2str(Y),'_',num2str(B),'_',num2str(z),'_',num2str(R),'_',num2str(I),'_',num2str(C),'.txt');

     aux = load(filename); 
     PP = [PP aux(1:n)];

   end
  end
 end 
end

rmpath(pathname)

所以,想象一下nt = 10,我想获得10个不同的png文件。有任何想法吗? 我恭喜你的所有帮助

2 个答案:

答案 0 :(得分:2)

你也可以这样做:

plt.savefig("Instand"+str(n)+".png")

答案 1 :(得分:1)

您每次都可以更改文件名:

plt.savefig("Instant{}.png".format(n))

另外,如果你有超过十个图,那么有一些前导零可能是个好主意,例如。所以" Instant5.png"并没有追随" Instant10.png"按字典顺序排列。

plt.savefig("Instant{:03}.png".format(n))