Legend auto placement

Hello,

I was wondering if there were any tips for people like myself that generate
plot images to be rendered for CGI scripts. I'd like to offer some of the
things I have learned on the subject thus far:

Changed .matplotlibrc's backend parameter to Agg. This seems to yield the best
quality output results. This way, I can compile without Tk and GTK support. I
did not find any way to easily call distutils with arguments to disable these
things, so I had to comment out the setup.py script after I patched it with
the FreeBSD port patches. This is on a box without a monitor, so I won't be
doing any interactive graphing anytime soon. :slight_smile:

After realizing on my slower box (Pentium2 400MHz) that:

import pylab

takes a while. I just assumed most people don't restart matplotlib's runtime
initialization for every graph they produce, but rather, for interactive
graphing. This is pure guess, however.

Also, I'd like to know if using pylab directly is a bad idea for
non-interactive graphing. It seems to work okay but I've read through some
past mail on this list that importing matplotlib is better than pylab if
doing interface design(?) I also read that pylab tries to do more for setting
up the environment for interactive graphing, so maybe I don't need this.

I've done some profiling on the import using Python's profile
module and later found the hotshot module to help quite a bit with accuracy.
I'll try to post some of my speedups once I make sure they aren't pure hacks.
Some of it was the mathtext regexp work, but a surprising amount of time
was spent in a docstring magic/generation function!

I switched to using FastCGI to avoid some of the startup cost of matplotlib
on my slower server box. FastCGI is a way to speed up CGI programs, as the
name may imply. :slight_smile: Unfortunately, stdout with FastCGI is wrapped in a special
little request object that isn't a true file object. I had to use the tempfile
Python module for matplotlib to write its output to. I had tracked down where
matplotlib did this (it was in some C module) but it's been a while since I
messed with it.

A final issue I ran into was permissions in a Web server environment. I run
the CGI application through FastCGI under a restricted user because it doesn't
need much permission to do anything else. Unfortunately, I noticed I have to
do some magic at runtime of my script to set my HOME path so that the
matplotlib font manager will write its ttfcache file to a place that the
CGI script can write to. It's not a big deal, but I did have to look through
the font manager source to figure out why it was raising an exception.

I hope this information helps others who want to produce great graphical
output using matplotlib that is targetted for the Web. I had to figure it out
for myself by searching and testing quite a bit.

My apologies for the long email. It's my first post that I tried to offer
suggestions to others instead of being a read-only list subscriber. :slight_smile:

Thanks,

Brian