MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How do I plot contours from measurements taken on a rectangular 2D lattice ?

  • To: mathgroup at
  • Subject: [mg50385] Re: [mg50371] How do I plot contours from measurements taken on a rectangular 2D lattice ?
  • From: "David Park" <djmp at>
  • Date: Wed, 1 Sep 2004 01:49:24 -0400 (EDT)
  • Sender: owner-wri-mathgroup at


Here is an example. First I will make up some data. First I define a
function that makes a hill (You can copy all these statements into a
Mathematica notebook and evaluate them)...

hill[{x0_, y0_}, height_, \[Sigma]_][x_, y_] :=
  height*Exp[(-\[Sigma]/10)*((x - x0)^2 + (y - y0)^2)]

and then add a number of hills together to obtain a terrain...

f[x_, y_] :=
  hill[{0, 0}, 5, 0.1][x, y] +
    hill[{10, 10}, 10, 0.2][x, y] +
    hill[{10, 20}, 7, 0.1][x, y] +
    hill[{20, 1}, 8, 0.2][x, y] +
    hill[{25, 30}, 10, 0.1][x, y] +
    hill[{25, 40}, 8, 0.1][x, y]

Here is a 3D plot of our sample terrain.

Plot3D[f[x, y], {x, 0, 40}, {y, 0, 40}, PlotRange -> All];

Then I generate some data by sampling the grid at 1 meter intervals. Having
40 and 41 points is a little complication. I hope I handled it correctly. I
add in some random error to each point.

data = Table[
      f[x, y] + 0.2Random[Real, {-1, 1}], {x, -0.5, 40.5, 1}, {y, 0, 40,

That should simulate your data. We can make a 3D plot of the data.

ListPlot3D[data1, MeshRange -> {{0, 40}, {-0.5, 40.5}}];

We could do a ListContourPlot, but let's make an interpolation function

h[x_, y_] = ListInterpolation[data, {{0, 40}, {-0.5, 40.5}}][x, y]


InterpolatingFunction[{{0., 40.}, {-0.5, 40.5}}, <>][x, y]

Then we can make a contour plot...

ContourPlot[h[x, y], {x, 0, 40}, {y, 0, 40}, PlotPoints -> 50];

and you can also obtain the interpolated height at any point in the domain.
For example

h[20.2, 20.15]
5.919  (with the particular set of random data generated above.)

David Park
djmp at

From: mrksr. dmn. co. uk [mailto:daniel at]
To: mathgroup at

Hello, I am new to this newsgroup.
I will shortly have an array of 40 x 41 = 1640 height measurements on
some undulating land, taken at 1 metre intervals on a square grid. Each
measurement has an error of about 5%.
How do I display the data as smooth interpolated height contours ?
Daniel Marks

  • Prev by Date: Inflight magazine puzzle
  • Next by Date: Re: mathlink newbie q
  • Previous by thread: Re: Inflight magazine puzzle
  • Next by thread: Re: Optimization Problem - Need Stochastic Method