Group Abstract Group Abstract

Message Boards Message Boards

plotting points from a 3d table

GROUPS:
Hi, I have a set of data in the table format
{{1,2,3,4},{10,2,5,6,5},{20,1,3,4,7},{30,3,1,6,9}}
where the first line is the x axis, but the y column is the first number of the following lines
TableForm[{{1, 2, 3, 4}, {10, 2, 5, 6, 5}, {20, 1, 3, 4, 7}, {30, 3, 1, 6, 9}}]
So x={1,2,3,4}, y={10,20,30} and f(x,y) are the remaining data.

How can I plot these data in a 3D like form?
Thanks
Simone
POSTED BY: S Mazzu
Answer
7 months ago
To begin, be careful when using TableForm. TableForm should be used for viewing data in an easy to read format, but shouldn't be used as a wrapper when storing data.

Part of the issue with the data is that it should form a complete square or rectangle of numbers. Otherwise, it is hard to interpret what the data means. In the definition below, I've added 0 to the first element of the data:
myData = {{0, 1, 2, 3, 4}, {10, 2, 5, 6, 5}, {20, 1, 3, 4, 7}, {30, 3, 1, 6, 9}};
You can vizualize what this table of numbers looks like with TableForm or with ArrayPlot.
TableForm[myData]
ArrayPlot[myData]



Now, if you would like to make this rectangular matrix of numbers into a 3D surface, you can use the ListPlot3D function:
ListPlot3D[myData]

POSTED BY: Sean Clarke
Answer
7 months ago
Thanks, but this is not the answer I I wanted, probably as I did not explain it well. I am aware of the use of TableForm, and I don't want to add an extra in the first row. In your second graph you see that the data coordinates are 1 to 5 for x and 1 to 5 for y. For me I wanted x={1,2,3,4} and y={10,20,30}.
So the points in the 3D graph should be like in the following graph done with Origin Pro


Thanks
Simone
POSTED BY: S Mazzu
Answer
7 months ago
Please see: http://reference.wolfram.com/mathematica/ref/ListPointPlot3D.html

So we have to provide a list of {x,y,z} values. There are many ways of doing this. People familiar with imperative programming will would likely use a double for loop or Do loop to make this list of values. Here is how you would use Table. 
xvals = {1, 2, 3, 4}; yvals = {10, 20, 30};
data = Transpose@{{2, 5, 6, 5}, {1, 3, 4, 7}, {3, 1, 6, 9}}

formattedData = Flatten[#, 1] &@ Table[{xvals[[x]], yvals[[y]], data[[x, y]]}, {x, 1, 4}, {y, 1, 3}]
This formatted data can be given to ListPointPlot3D
ListPointPlot3D[formattedData, Filling -> Bottom, PlotStyle -> Directive[PointSize[Large], Red]]
POSTED BY: Sean Clarke
Answer
7 months ago