# how to use matplotlib contour()?

Robert Kern robert.kern at gmail.com
Wed May 24 23:40:27 CEST 2006

```Grant Edwards wrote:
>
> I've searched both the user guide and the Wiki for "contour"
> and got zero hits.
>
> http://matplotlib.sourceforge.net/matplotlib.pylab.html#-contour
> appears to be a good reference if you already know how to use
> contour(), but I could glean zero clues from it on how to
> actually use contour().  For example, it doesn't explain what
> the actual formats/types of the parameters.  It explains what
> the parameters do, but not what they _are_

Yes, unfortunately, much of the documentation was written by people who were
very familiar with the Matlab interfaces that these functions are emulating.

> For example one parameter is specied as "an array".  No clue as
> to how many dimensions or what the axis are.
>
> In another place it says "the X,Y parameters specify the (x,y)
> coordinates of a surface".  _How_ do they specify the surface?
> Are they just equal length lists of x and y coordinates that
> specify len(X) points.  Or do they specify a len(X) x len(Y)
> grid of points?

> Why would my Z values be a 2D array?

contour() only does contouring on gridded data. If you want to handle scattered
datapoints, you will have to do some interpolation.

http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data

So X, Y, and Z are all 2-D arrays laid out corresponding to the grid that you
have sampled. I thought the contour_demo.py example was reasonably clear on
this, but if you didn't get it to run, then I can see why you wouldn't have read it.

faster:

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma