Hi, The code below when run from a file in the cgi-bin
> directory should generate a plot but it does not work:
It would help to have more information. What do you mean "does not
work"? Are there any errors displayed to the terminal or apache
logs. I know people have used mpl with apache, but it can be a little
tricky to get all the data paths set up properly.
matplotlib uses a couple of environment variables to find it's data
and store cache information. For example, if your fonts and
.matplotlibrc are in a nonstandard place, you need to set the env var
MATPLOTLIBDATA to point to them. Also, mpl tries to create a cache
file .ttffont.cache in your HOME dir by default, and in an apache
config HOME may not exist or may not be writable. If there is no
HOME, matplotlib will fall back on the MATPLOTLIBDATA dir, so make
sure env var is set, that it points to the directory that contains
Vera.ttf and the other mpl fonts, and that it is writable by the user
under which apache runs.
If you get this to work, please write a HOWTO and submit it to the list.
> import sys import matplotlib matplotlib.use('Agg') from
> pylab import *
> #print "Content-type: text/html\n\n" #print "<html>Hello
> print "Content-type: image/png\n\n"
> print savefig(sys.stdout)
This looks wrong. Doing
will also print the return value of savefig, which is None I believe.
I think you just want
But I can't vouch for the overall approach (setting the content type
and then dumping in a binary stream of the png). It may be correct,
but I haven't used it. Somehow I would expect the stream to be mime
or base64 encoded in an ascii file.
> However, it does not work and I am really struggling to get
> matplotlib to generate a plot dynamically in a
> cgi-script. If anyone has done this successfully I would
> really appreciate some help or a simple example. I am using
> Windows XP and Apache 2.0.53.
Hope this helps a little -- let us know if you have any more details
on the problem you are experiencing or if you make any progress.