I want to save plots programmatically, using a variable + .png as the
filename. I don't see an example of the proper syntax, and my
trial-and-error approach hasn't yielded a solution, either.
If I want to write
pylab.save(curVar.png)
where 'curVar' is a variable assigned programmatically, how do I correctly
write it?
Rich
···
--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
Use string concatenation:
curVar+'.png'
<URL:http://docs.python.org/tut/node5.html#SECTION005120000000000000000>
hth,
Alan Isaac
···
On Thu, 31 Jan 2008, Rich Shepard apparently wrote:
If I want to write
pylab.save(curVar.png)
where 'curVar' is a variable assigned programmatically, how do I correctly
write it?
Hi Rich,
bit confused what your asking.
are you looking for the pylab API savefig
http://matplotlib.sourceforge.net/matplotlib.pyplot.html#-savefig
or you asking how to convert your variable+.png into a filename?
is your variable a number?, string?
for count in range(3):
count = count +1
fname = 'MyPlot_%d.png' %count
print fname
mystr = 'MyFirstPlot'
fname = '%s.png' % mystr
print fname
results in
>python -u "test.py"
MyPlot_1.png
MyPlot_2.png
MyPlot_3.png
MyFirstPlot.png
>Exit code: 0
pylab.savefig('%s.png'% curVar)
or
pylab.savefig('%d.png'% curVar)
Does anything here help?
Steve
Rich Shepard wrote:
···
I want to save plots programmatically, using a variable + .png as the
filename. I don't see an example of the proper syntax, and my
trial-and-error approach hasn't yielded a solution, either.
If I want to write
pylab.save(curVar.png)
where 'curVar' is a variable assigned programmatically, how do I correctly
write it?
Rich
bit confused what your asking.
are you looking for the pylab API savefig
Stephen/Alan/Chloe:
Yes, it turns out that I am.
or you asking how to convert your variable+.png into a filename?
is your variable a number?, string?
The variable is a string, and I do want to use it as a file name.
pylab.savefig('%s.png'% curVar)
I wasn't aware of the savefig() function, and was trying to use save()
instead. As soon as I made that change, it worked.
Thanks for the lesson!
Rich
···
On Fri, 1 Feb 2008, Stephen George wrote:
--
Richard B. Shepard, Ph.D. | Integrity Credibility
Applied Ecosystem Services, Inc. | Innovation
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863