Re: How can I plot a file of <x, y, z> points?
- To: mathgroup at smc.vnet.net
- Subject: [mg17377] Re: How can I plot a file of <x, y, z> points?
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Thu, 6 May 1999 02:44:03 -0400
- Organization: University of Western Australia
- References: <7gfsge$6fv@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
David Finton wrote: > I'm trying to use Mathematica to make a 3D plot of some data. > The data comes in a file which has three numbers on each line, > each line representing the x, y, z coordinates of a point. > > Unfortunately, the only Mathematica commands I've been able to find > want my data to be a *matrix of heights*. A coworker showed me > a very complex method of finding the smallest x value and > then adding the correct number of 0's to the left and right > in order to position each z_xy at the correct xy location in > a grid. But come on! There has to be an easier way. Can anyone > help this novice Mathematica user see the light? Suppose that the file mat.data contains the following data: 0 0 0. 0 1 0. 0 2 0. 0 3 0. 1 0 0. 1 1 0.841471 1 2 0.909297 1 3 0.14112 2 0 0. 2 1 0.909297 2 2 -0.756802 2 3 -0.279415 3 0 0. 3 1 0.14112 3 2 -0.279415 3 3 0.412118 Read in the data as triples: In[1]:= ReadList["mat.data", Table[Number, {3}]] Out[1]= {{0, 0, 0.}, {0, 1, 0.}, {0, 2, 0.}, {0, 3, 0.}, {1, 0, 0.}, {1, 1, 0.841471}, {1, 2, 0.909297}, {1, 3, 0.14112}, {2, 0, 0.}, {2, 1, 0.909297}, {2, 2, -0.756802}, {2, 3, -0.279415}, {3, 0, 0.}, {3, 1, 0.14112}, {3, 2, -0.279415}, {3, 3, 0.412118}} If appropriate, interpolate the data: In[2]:= f = Interpolation[%]; Read off the x-range and y-range from the interpolation function: In[3]:= {{xmin, xmax}, {ymin, ymax}} = First[f] Out[3]= {{0., 3.}, {0., 3.}} Plot the surface: In[4]:= Plot3D[f[x, y], {x, xmin, xmax}, {y, ymin, ymax}]; Cheers, Paul ____________________________________________________________________ Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia Nedlands WA 6907 mailto:paul at physics.uwa.edu.au AUSTRALIA http://www.physics.uwa.edu.au/~paul God IS a weakly left-handed dice player ____________________________________________________________________