# Plotting libraries

I have edited this post on the 14th of December 2011. I added a few things in matplolib and plplot section.

There are numerous choices to plot diagrams. Depending of the functionality you need and the language you are developing in, the choice might be difficult.

I have found six possible libraries: gnuplot, matplotlib, pgplot, plplot, dislin and R. Each of them have different requirements. Matplotlib is dedicated to python while plplot have numerous bindings. Their capabilities are also different, gnuplot does not seem to superimpose graphs very easily. Licensing is also important dislin and pgplot have the most restrictive license: it is free to use only for non-commercial application. In each libraries, except R and dislin, I tried to draw a Fourier Map (picture) superimposed by a contour plot.

My data are stored in a 2D array. It seems that this cause some troubles to some libraries.

### gnuplot

I could not find how to superimpose a contour plot. I only get an image. Also, I don’t know if I can apply a transformation to the coordinates in order to map the array indices to real coordinates.

### matplotlib

Matplotlib can only be used in python. The combination with python makes it very easy to try quickly a few thing. The documentation is well written although not very consistent in its conventions.

[codesyntax lang=”python”]

#!/bin/python

import numpy
import matplotlib.pyplot as plt
from pylab import *

cdict = {
'red'  :  ((0., 1., 1.), (0.5, 1.0, 1.0), (1., 0.4, 0.4)),
'green':  ((0., 0.4, 0.4), (0.5, 1.0, 1.0), (1., 1., 1.)),
'blue' :  ((0., 0.4, 0.4), (0.5, 1.0, 1.0), (1., 0.4, 0.4))
}
my_cmap = matplotlib.colors.LinearSegmentedColormap('my_colormap', cdict, 1024)

imshow(data[0:577,:], cmap=my_cmap)
contour(data[0:577,:],  colors='#00aa00', levels=(0.1,0.2,0.3,0.4,0.5))
contour(data[0:577,:],  colors='blue', levels=[0.0])
contour(data[0:577,:],  colors='#aa0000', linestyles='dashed', levels=(-0.1,-0.2,-0.3,-0.4,-0.5))
show()

[/codesyntax]

### pgplot

PGPLOT is used with low level languages Fortran and C. It’s an advantage or a disadvantage depending on what you want. My program is written in Fortran, so it’s good. However it makes the programming more difficult. The two main disadvantages are the license which I am not sure is compatible with the GPL and updates: the last version was released in 2001. I manage to get exactly what I wanted with this library, the documentation is really good. The only problem I have in about the layout: the resolution is limited and hard-coded, the placement of objects is troublesome.

### plplot

On the paper, this one my favourite. It’s LGPL, there are bindings for all kinds of languages including Fortran and python, it is actively developed with several commits every month and there are a large choices of output formats. I have two major problems: the documentation is really not sufficient and there are bugs (contour plot bug). However, with a few tricks I managed to get a working example.

There is also a bug in the linear gradient function in RGB. The workaround is to used HLS space.
There is no function to draw a circle, I used a polygon instead.

Although plplot looks promising, there are serious issues to fix.

## One thought on “Plotting libraries”

1. There is a bug in the gradient. RGB space is converted to HLS space which reults into a non linear gradient contradicting the doc:
http://plplot.sourceforge.net/docbook-manual/plplot-html-5.9.9/plscmap1l.html

A workaround is to use HLS space:
 call plscmap1l(.false., & & (/0.0_plflt, 0.499_plflt, 0.501_plflt, 1.0_plflt /),& & (/0.0_plflt, 0.0_plflt, 120.0_plflt, 120.0_plflt /),& & (/0.2_plflt, 1.0_plflt, 1.0_plflt, 0.2_plflt /),& & (/1.0_plflt, 1.0_plflt, 1.0_plflt, 1.0_plflt /) )