Personal tools
You are here: Home / CarPy / Burns' Python Scripts / pygplot

Pygplot: A Wrapper for CPGPLOT

PGPLOT (http://www.astro.caltech.edu/~tjp/pgplot/) is a FORTRAN library for producing high-quality scientific plots (both interactive and hardcopy).  However, being a FORTRAN library, it is very procedure-based, whereas python is an object-oriented language.

There are several wrappers that interface PGPLOT into python.  There is Dan Kelson's CPGPLOT wrappers (part of his CarnegiePython distribution) which is the most up-to-date and easy to maintain (it uses the SWIG auto-wrapper).  Still, Dan's wrapper only makes hooks into the functions, so while you can run them inside python, it's still procedure-based.

Pygplot attempts to fix this by wrapping the wrappers up in an object-oriented framework.  One creates plot instances, adds line, point, and error-bar instances to it, fiddles with member variables and functions to set plot attributes, then runs a plot() function to generate the plot.

You can download the software here:  pygplot-releases

A manual (somewhat out of date) is available here:  pygplot manual

Requirements:

(Note:  both of these are built into Dan's CarnegiePython distro, as well as many others like scisoft).


Installation:

Once you have PGPLOT installed somewhere (and tested!), make sure you have your $PGPLOT_DIR environment variable set.  Then, unpack pygplot somewhere and run

python setup.py install
And that should do it.

Tips and Troubleshooting:

  • If you can't write to python's site-packages directory (because it's the system python and you don't have root access, for example), you can use the --home switch to have it installed somewhere you can write to.  For example:
    python setup.py install --home=/home/monty/

    This will create directories like /home/monty/lib and /home/monty/bin and install the module there.  If you take this route, make sure you put /home/monty/lib in your PYTHONPATH.

  • The setup.py script tries to make some guesses about what compiler and linker options are needed.  However, it may need help.  It may fail to find the pgplot librairies, or it may compile but fail to load due to missing symbols.  To help with this, you can set an environment variable called PGPLOT_LIBS that contains all the switches needed to compile and link with PGPLOT.  For example, PGPLOT from scisoft on Fedora might need something like:
    setenv PGPLOT_LIBS 'lm -lX11 -L/usr/X11R6/lib -lpng -L/scisoft/lib -lgfortran'

    It's best to delete the build/ directory to force a clean re-build of the module.