Trouble in PNG file [cgi]

I have a trouble when displat a PNG file which generated from matplotlib

here is the script from http://www.scipy.org/Cookbook/Matplotlib/Using_MatPlotLib_in_a_CGI_script

there is no image in the web browser, is there anything wrog with the script?
please help me, I am a newbie in matplotlib :wink:


#!/usr/bin/python

import pylab

import matplotlib
import os,sys

import cgi
import cgitb

cgitb.enable()

os.environ[‘HOME’]=’/tmp/’

matplotlib.use(‘Agg’)
form = cgi.FieldStorage()

pylab.plot([1,2,3])
print “Content-Type: image/png\n”

pylab.savefig(sys.stdout,format=‘png’)

and then here is my computer specification
CentOS 5.1 – Linux localhost.localdomain 2.6.18-53.el5 #1 SMP Mon Nov 12 02:22:48 EST 2007 i686 i686 i386 GNU/Linux

python-2.4.3-19.el5
numpy-1.0.3.1-1.el5.kb
scipy-0.6.0-6.el5
matplotlib 0.91.4

···


Zainal Abidin, S.Si

Sub Bidang Informasi Meteorologi Publik
Badan Meteorologi dan Geofisika
Jl. Angkasa I No. 2
Jakarta - Indonesia
Visit Indonesia Year 2008 - Celebrating 100 Years of National Awakening

One mistake I see is that you are calling use('Agg') after importing
pylab. According to the use docstring:

    Note: this function must be called *before* importing pylab for
    the first time; or, if you are not using pylab, it must be called
    before importing matplotlib.backends.

Not sure if this will solve your problem, but it should be fixed.

JDH

···

On Tue, Aug 12, 2008 at 5:16 AM, Zainal Abidin <zainal.abi@...287...> wrote:

I have a trouble when displat a PNG file which generated from matplotlib
here is the script from
http://www.scipy.org/Cookbook/Matplotlib/Using_MatPlotLib_in_a_CGI_script
there is no image in the web browser, is there anything wrog with the
script?
please help me, I am a newbie in matplotlib :wink: