Message Boards Message Boards

0
|
9407 Views
|
6 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Plotting points from a 3d table

Posted 12 years ago
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
6 Replies
Posted 3 years ago

Yes! Thank you for your speedy reply Rohit.

POSTED BY: Clara Woodie
Posted 3 years ago

Hi Clara,

Do you mean something like this?

ClearAll@f
f[x_, y_] := Sin[x]*Cos[y]
Plot3D[f[x, y], {x, 0, 2 Pi}, {y, 0, 2 Pi}]

enter image description here

POSTED BY: Rohit Namjoshi
Posted 3 years ago

Hi Simone,

I recognize this was 8 whole years ago, but did you ever get a sufficient answer? I too am now struggling to plot output from a function of two variables. Thank you in advance!

POSTED BY: Clara Woodie
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
Posted 12 years 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
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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract