MeshRange
option. Here is a typical example, which also shows a use of the FrameLabel
option to put labels on the frame around the plot. Contour plots are drawn with a frame unless you include Frame
-> False
.
In[1]:= data = Table[y Cos[x], {y, 0, 1, .1}, {x, 0, 2 Pi, Pi/5}];
In[2]:= g = ListContourPlot[data, MeshRange -> {{0, 2 Pi}, {0, 1}},
FrameLabel -> {x, y}]
Out[2]= -ContourGraphics-
The first row in the data corresponds to the bottom of the image, and the first column corresponds to the left side of the image. If the data are not
on a regular grid, the most general approach is to triangulate the data and use a contouring algorithm for triangulated data. The contouring algorithm invoked by
ListContourPlot is designed for data on a regular grid. If the grid is not completely irregular, it is sometimes possible to get a useful plot using
ListContourPlot by interpolating and resampling the data onto a regular grid, or by an appropriate mapping of the graphics expression. For notes about
triangulation, see TriangularSurfacePlot , and the notes for
How do I generate a surface plot of irregularly spaced data?
Here is an example using a data set that consists of a list of x, y, z coordinates. To use ListContourPlot, it is necessary to
construct from this list an array of z-values. This can almost always be achieved using a simple combination of functions such as Map
, Partition
, Sort
, and Transpose
. The required operations will depend on the details of the example.
In[3]:= data = {{-2, 0,1}, {-1, 0,1}, {0, 0,2}, {1, 0,2}, {2, 0,2},
{-2, 50,1}, {-1, 50,2}, {0, 50,2}, {1, 50,2}, {2, 50,2},
{-2,100,1}, {-1,100,1}, {0,100,1}, {1,100,1}, {2,100,2}};
In[4]:= zdata = Partition[Map[Last, data], 5]
Out[4]= {{1, 1, 2, 2, 2}, {1, 2, 2, 2, 2}, {1, 1, 1, 1, 2}}
The first plot below shows a contour plot of zdata displayed using ListContourPlot with the MeshRange
, ContourShading
, Contours
, and FrameLabel
options. The second plot shows the raw data together with the contour plot. The angular nature of the contours in these plots is a consequence of the small number of data points.
In[5]:= c = ListContourPlot[zdata,
MeshRange -> {{-2, 2}, {0, 100}},
ContourShading -> False,
Contours -> {1.1, 1.6, 1.7, 1.8},
FrameLabel -> {x, y}]
Out[5]= -ContourGraphics-
In[6]:= tg = Graphics[Apply[Text[#3, {#1, #2}] &, Partition[data, 5], {2}]]
Out[6]= -Graphics-
In[7]:= Show[c, tg]
Out[7]= -Graphics-
Additional Online Documentation:
Mathematica 3.0
http://documents.wolfram.com/v3/RefGuide/ListContourPlot.html
Mathematica 4.0
http://documents.wolfram.com/v4/RefGuide/ListContourPlot.html
Questions or comments? Send email to support@wolfram.com.