您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

5b51 2022/1/14 8:20:48 python 字数 2221 阅读 475 来源 www.jb51.cc/python

我需要在Python中使用“savefig”来保存while循环的每次迭代的图,我希望我给图的名称包含一个文字部分和一个数字部分.这个是从数组中出来的,或者是与迭代索引相关联的数字.我举一个简单的例子:# index.py from numpy import * from pylab import * from matplotlib import * fr

概述

我需要在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]

非常感谢.

savefig(str(a[0]))

这是一个玩具的例子.适合我.

import pylab as pl
import numpy as np

# some data
x = np.arange(10)

pl.figure()
pl.plot(x)
pl.savefig('x=' + str(10) + '.png')

总结

以上是编程之家为你收集整理的在Python中使用savefig,名称中包含字符串和迭代索引全部内容,希望文章能够帮你解决在Python中使用savefig,名称中包含字符串和迭代索引所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶