 |
|
List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] Re: listplot3d
| [MUG] Re: listplot3d |
|
Author: Carl DeVore
Posted: 11/01/2001 00:31:31 GMT
|
>> From: Carl DeVore
| >>>From: "Ismail Boztosun"
|
| I need to obtain a 3D plot by using a data file. I could not find any
| other way that to use " listplot3d " but it seems that this accepts only
| heights arrays, namely a rectangular array containing the heights of the
| surface. In this way I cannot obtain the right scales on the x a y axis
| because the x and y data are not considered!
|
| Is there any way to plot a real three-dimensional set of data written as
| a set of {x,y,z} points?
I avoided answering this question earlier because I was hoping that
someone could give a better answer than me. Yesterday's answers all
suggested either using pointplot3d or surfdata (or not using Maple at
all). I don't think that either pointplot3d or surfdata are quite
satisfactory. The problem with pointplot3d is that you need a tremendous
number of points to get a reasonable looking surface. The problem with
surfdata is that the data needs to sorted on both the x and y coordinates
and subdivided into a triply nested list (a "listlistlist" as it were,
rather than the "listlist" form that data is currently in). Surfdata was
intended to be used when there are a fixed number n of x-values and a
fixed number m of y-values and a total of n*m points. These values define
the gridlines. But it is not absolutely necessary that the x and y values
are fixed as long as they are sorted. Example:
> f:= (x,y) -> sin(x*y);
> plot3d(f, 0..5, 0..5, style= patchnogrid);
As you can see (if you enter this code), this is a moderately complex
surface. By default, the plot3d command evaluates the function at 25x25
= 625 points: 25 x values by 25 y values. I will randomly sample the
surface at 4 times this number of points and construct a close
approximation to the original plot.
> k:= 50:
> M:= matrix(k^2,3):
> for n to k^2 do
> x:= evalf(5*rand()/10^12);
> y:= evalf(5*rand()/10^12);
> M[n,1]:= x; M[n,2]:= y;
> M[n,3]:= f(x,y);
> end:
> M:= convert(M,listlist):
Now M is in exactly the listlist form that it would be in had you read it
from a file with the readdata command.
Let's look at a pointplot:
> pointplot3d(M);
The picture is so sparse that it is barely visible. If we increase the
size of the points (or use a different style, like circle), the plot is
much too blurry.
Sort M by the y-coordinates:
> M:= sort(M, (p1,p2) -> evalb(p1[2]<p2[2])):
Now I will assume that we have n*m points for some reasonably close values
of n and m. In my example, n = m = k = 50.
> n:= k; m:= k;
Now we divide the list into chunks of length n and sort each chunk on the
x-coordinate. Then plot the whole.
> plots[surfdata]
> ([seq(sort(M[j*n+1..j*(n+1)], (p1,p2) -> evalb(p1[1]<p2[1]))
> ,j= 0..m-1
> )]
> ,style=patchnogrid
> );
I think that that's a pretty good approximation to the original surface.
If you put the grid lines in, they will still be a mess, which is why I
specified "patchnogrid".
A more sophisticated approach would be to define a mesh of x and y values
and replace each x and y value with the closest mesh point. Of course
this is unnecessary if your original data are already on a mesh. In this
case, the grid lines will look fine. But the above code is still
necessary in order to put the data into the format required by the
surfdata command.
If the x and y values are moved to mesh values, would it then be possible
to somehow interpolate the z-values? I know nothing about interpolating
multidimensional functions.
Carl Devore
University of Delaware
|
[View Complete Thread]
Previous by date: [MUG] Re: Double Integral problem with discontinuity, Maple Group
Next by date: [MUG] Re: Double Integral problem with discontinuity, Tanaka
Previous thread: [MUG] color eps, Maths
Next thread: [MUG] Re: Double Integral problem with discontinuity, Maple Group
|
|
|