Png stream through Stdout to the web

I could not find anywhere an example of exactly how I would call the py
script and get the png to appear in a web page.

I have py scripts working for cgi, which is great. So I placed my simple
script in the cgi-bin folder and I tried calling it directly:
Localhost/cgi-bin/stdoutTest.py
No image file shows up.

So, I gathered I should refer to the location like any other graphic file.
So I made a test html file and put an image tag and set the src attribute.
<img alt="Test Alt" src="http://localhost/cgi-bin/stdout.py">

I then called the html file:
Localhost/pngTest.html

Still no image appears.

Lastly, if I call stdout.py from the command prompt, then I will see the
stream of data that makes up the png image. So at least I am no longer
getting the traceback error.

Does anyone try to show their graphs without actually saving the png file?

Any help would be greatly appreciated.
-Rodney

Sorry, my file name is stdout.py, in both places. And here it is:

#!c:/Python25/python.exe -u
import sys
import matplotlib
matplotlib.use('Agg')
from pylab import *
plot ([1 ,2 ,3])
savefig( sys.stdout )

···

-----Original Message-----
From: matplotlib-users-bounces@lists.sourceforge.net
[mailto:matplotlib-users-bounces@lists.sourceforge.net] On Behalf Of Rodney
Haynie
Sent: Monday, May 19, 2008 10:10 PM
To: matplotlib-users@lists.sourceforge.net
Subject: [Matplotlib-users] Png stream through Stdout to the web

I could not find anywhere an example of exactly how I would call the py
script and get the png to appear in a web page.

I have py scripts working for cgi, which is great. So I placed my simple
script in the cgi-bin folder and I tried calling it directly:
Localhost/cgi-bin/stdoutTest.py
No image file shows up.

So, I gathered I should refer to the location like any other graphic file.
So I made a test html file and put an image tag and set the src attribute.
<img alt="Test Alt" src="http://localhost/cgi-bin/stdout.py">

I then called the html file:
Localhost/pngTest.html

Still no image appears.

Lastly, if I call stdout.py from the command prompt, then I will see the
stream of data that makes up the png image. So at least I am no longer
getting the traceback error.

Does anyone try to show their graphs without actually saving the png file?

Any help would be greatly appreciated.
-Rodney

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges.
Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Ok, I found the answer and just wanted to post it for the archives.

My script now begins with:

#!c:/Python25/python.exe -u
import os,sys
import cgi
import cgitb; cgitb.enable()
# set HOME environment variable to a directory the httpd server can write to
os.environ[ 'HOME' ] = 'c:/www/app/tmp/'

Then, before the savefig(), I had to set the content type:

print "Content-Type: image/png\n"

Then all worked well.

I'll keep the agg backend script installed until the next release of
matplotlib.

Thanks John and Michael... So much help, short response times.

-Rodney

···

-----Original Message-----
From: matplotlib-users-bounces@lists.sourceforge.net
[mailto:matplotlib-users-bounces@lists.sourceforge.net] On Behalf Of Rodney
Haynie
Sent: Monday, May 19, 2008 10:21 PM
To: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] Png stream through Stdout to the web

Sorry, my file name is stdout.py, in both places. And here it is:

#!c:/Python25/python.exe -u
import sys
import matplotlib
matplotlib.use('Agg')
from pylab import *
plot ([1 ,2 ,3])
savefig( sys.stdout )

Thanks Rodney -- when posting for the archives, be sure to reply to
the original thread and not change the subject (eg adding "answer")
since that will break threading in many news readers and hence may
destroy the context for future googlers.

Thanks for posting the answer -- if you have the time, consider
writing a matplotlib cookook recipe for your webapp server at
http://www.scipy.org/Cookbook/Matplotlib

JDH

···

On Mon, May 19, 2008 at 10:26 PM, Rodney Haynie <RHaynie@...614...> wrote:

Ok, I found the answer and just wanted to post it for the archives.