Re: How do I plot contours from measurements taken on a rectangular 2D lattice ?
- To: mathgroup at smc.vnet.net
- Subject: [mg50385] Re: [mg50371] How do I plot contours from measurements taken on a rectangular 2D lattice ?
- From: "David Park" <djmp at earthlink.net>
- Date: Wed, 1 Sep 2004 01:49:24 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Daniel,
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,
1}];
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
instead.
h[x_, y_] = ListInterpolation[data, {{0, 40}, {-0.5, 40.5}}][x, y]
giving
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 earthlink.net
http://home.earthlink.net/~djmp/
From: mrksr. dmn. co. uk [mailto:daniel at marksr.demon.co.uk]
To: mathgroup at smc.vnet.net
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