# Contour and Vector Plots

Hi,

My research is in computational fluid dynamics (specifically, the
meteorologies of planetary atmospheres). Working contour and vector plots
in matplotlib would make it possible for me to make 2D meteorological maps
of atmospheric layers, etc.

I noticed for the first time in the goals page that contour plots are
being worked on, apparently by STSci. I have been considering
implementing these two plot types as sets of line collections, but now
that I know contour plots are being worked on, and vector plots are
simpler to implement (in 2D), I will work on making vector plots. The
mathematics is fairly straightforward. I just need to learn how to use
the class library.

About contour plots, however, I have a couple of questions. How is it
being implemented? I was about to try to write a marching squares
contouring routine, although it might have been painfully slow in Python.
Does anyone have experience with this?

Cheers,
Curtis

Curtis Cooper writes:

My research is in computational fluid dynamics (specifically, the
meteorologies of planetary atmospheres). Working contour and vector plots
in matplotlib would make it possible for me to make 2D meteorological maps
of atmospheric layers, etc.

I noticed for the first time in the goals page that contour plots are
being worked on, apparently by STSci. I have been considering
implementing these two plot types as sets of line collections, but now
that I know contour plots are being worked on, and vector plots are
simpler to implement (in 2D), I will work on making vector plots. The
mathematics is fairly straightforward. I just need to learn how to use
the class library.

About contour plots, however, I have a couple of questions. How is it
being implemented? I was about to try to write a marching squares
contouring routine, although it might have been painfully slow in Python.
Does anyone have experience with this?

We are trying to adapt the C contour program that is used by gist
(and can be found in the contour routine used by xplt in scipy).
It would be best to look at the source for the precise description
of the algorithm it uses (note though that gist apparently uses
two different pieces of contour code for its contour tasks. The
one we are looking to adapt, mainly because it appears much easier
to isolate from the gist environment is the gcntr.c version).
I would be amazed if one could find a pure Python algorithm to do
contouring that was fast enough. Our current plan is to use these
C routines to generate the contour segments, and do the plotting
from within Python (as well as any contour labeling).

If you have expertise in this area you may be able to do it better
and faster than we can. Currently it is being worked on part time
so we aren't able to do it as fast as we would like. I'm hoping that we
will have at least a basic version (e.g., no labeling) in a couple
weeks.

If you want me to send or point you to the source code we are
using as the basis, let me know.

Perry Greenfield

We are trying to adapt the C contour program that is used by gist
(and can be found in the contour routine used by xplt in scipy).
It would be best to look at the source for the precise description
of the algorithm it uses (note though that gist apparently uses
two different pieces of contour code for its contour tasks. The
one we are looking to adapt, mainly because it appears much easier
to isolate from the gist environment is the gcntr.c version).
I would be amazed if one could find a pure Python algorithm to do
contouring that was fast enough. Our current plan is to use these
C routines to generate the contour segments, and do the plotting
from within Python (as well as any contour labeling).

If you have expertise in this area you may be able to do it better
and faster than we can. Currently it is being worked on part time
so we aren't able to do it as fast as we would like. I'm hoping that we
will have at least a basic version (e.g., no labeling) in a couple
weeks.

If you want me to send or point you to the source code we are
using as the basis, let me know.

Hi again,

Yes, I had the thought that using C for the algorithm would be easier as
well. There are actually some very well-written marching squares
contouring algorithms in C already out there. I will try to find such an
implementation and point you to it or send you the source code.

The second half is just the drawing, which should be implemented in
matplotlib using the line collections class. Since vector plotting is not
that hard, I will try to get that working first. Then, someone can take
my source code and adapt it easily to the contouring problem, once an
effective and sufficiently high-performance algorithm implementation can
be found.

Cheers,
Curtis

Hi again,

Yes, I had the thought that using C for the algorithm would be easier as
well. There are actually some very well-written marching squares
contouring algorithms in C already out there. I will try to find such an
implementation and point you to it or send you the source code.

Thanks, that would be helpful. In my search I didn't come across many.
Keep in mind the license needs to be compatible with that of matplotlib.

The second half is just the drawing, which should be implemented in
matplotlib using the line collections class. Since vector plotting is not

Yeah, that's what we have in mind.

that hard, I will try to get that working first. Then, someone can take
my source code and adapt it easily to the contouring problem, once an
effective and sufficiently high-performance algorithm implementation can
be found.

Cheers,
Curtis

OK, Perry