小编use*_*346的帖子

在Python中使用savefig,名称中包含字符串和迭代索引

我需要在Python中使用“ savefig”来保存while循环的每次迭代的图,并且我希望给该图赋予的名称包含文字部分和数字部分。这是从数组中得出的,或者是与迭代索引关联的数字。我举一个简单的例子:

# index.py

from numpy import *
from pylab import *
from matplotlib import *
from matplotlib.pyplot import *
import os

x=arange(0.12,60,0.12).reshape(100,5)
y=sin(x)

i=0

while i<99
  figure()
  a=x[:,i]
  b=y[:,i]
  c=a[0]
  plot(x,y,label='%s%d'%('x=',c))

  savefig(#???#)      #I want the name is: x='a[0]'.png
                      #where 'a[0]' is the value of a[0]
Run Code Online (Sandbox Code Playgroud)

非常感谢。

python indexing image save figure

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

figure ×1

image ×1

indexing ×1

python ×1

save ×1