[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: contour plot of irregularly spaced data
From: |
Ted Harding |
Subject: |
RE: contour plot of irregularly spaced data |
Date: |
Thu, 11 Jun 1998 21:53:29 +0100 (BST) |
On 11-Jun-98 Don Fisher wrote:
> How does one form a regular two dimensional grid from
> irregularly spaced data points? The Matlab book says "If X
> or Y is irregularly spaced, contour calculates contours
> using a regularly spaced contour grid, then transforms the
> data to X or Y", but I do not know how to accomplish this.
>
> I would like to convert/interpolate the irregularly spaced
> data samples to a grid and then contour that data. Any code
> fragments or pointers would be appreciated.
Octave uses gnuplot for plotting contours, and gnuplot has an option which will
do this. In Octave the gnuplot command would be
"gset dgrid3d {<row_size>} {,{<col_size>} {,<norm>}}"
(in gnuplot, see: help -> set -> dgrid3d, where you will get an explanation of
how it is calculated).
Maybe a superfluous comment, but ...
Don't get carried away by the apparently glamorous performance of a program
which claims to produce contours of a function, given values at a finite set of
points (irregularly or regularly spaced).
Look at it this way: if you had a parametric expression for the function, such
that you could calculate the exact value of the function at any point given its
exact values at a certain set of points, then you could calculate the values at
a sufficiently dense regular grid of points and use a standard contour program
with arbitrary precision (gnuplot can do the contours from the grid values, for
instance).
But: the contouring program does not know the expression for any function, and
therefore uses one [of a set of] rule-of-thumb procedure[s] to generate a
smooth interpolation which agrees with the given points without undertaking to
really agree at any other point. Therefore this amounts to assuming a functional
form for the result, which may or may not be realistic, effectively stating
that the value of the function at points on any contour line is equal to the
contour value for that line. The appearance of the result therefore tends to
depend strongly, for irregularly spaced data, on the actual positions of the
data points. You can test this by taking a known (preferably non-quadratic!)
function z = f(x,y) and
1. Take the values (xi, yi, zi) at a dense regular grid and contour these
(this is your reference or "control" contour plot)
2. Take the values for non-dense irregularly-spaced data, and contour these
3. Take the values for a quite differently positioned data, and contour these.
For many functions, I would be surprised if there was anything like close
agreement between any two of the resulting contour plots.
As pointed out above, gnuplot tells you how it's done (distance-weighted mean
of the given points, and this is the only option). I don't know how Matlab does
it, nor whether you have a choice of how it does it, nor whether it tells you
how it does it.
That being said, I am at present writing a contouring routine for octave which
offers capabilities not readily available from the existing gnuplot resource.
I'll announce it when ready.
Good-looking contour plots make contouring look a lot easier and less
problematic than it really is ...
Best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Date: 11-Jun-98 Time: 21:53:29
--------------------------------------------------------------------