3
|
37517 Views
|
|
5 Total Likes
View groups...
Share

# Plot a simple x vs. y plot from a table

Posted 11 years ago
 I have a table that I imported from a csv file with 15 columns of hippocampal subregion volumes and some memory tests. For some reason, mathematica does not make it easy to make a simple x vs. y plot. Any Ideas how I could simply refer to two colums that I want plotted against each other?Extra:I would really like to use headers in the csv, but I had to take them out because mathematica cannot handle them without what seems like a lot of extra work. Any advice?I should probably just go back to r....Thank you all in advance for any help!
Sort By:
Posted 11 years ago
 Here is a simple example. Given table of 3 rows and 4 columns, suppose you want to plot the second column against the 4th column. Method 1tbl = { {1, 2, 3, 4},        {2, 5, 7, 8},        {9, 10, 11, 12}};x = tbl[[All, 2]];y = tbl[[All, 4]];data = Transpose[{x, y}]Now your data is{{2, 4}, {5, 8}, {10, 12}}Now you can plot it asListLinePlot[data, Mesh -> All, AxesOrigin -> {0, 0}]Method 2You can select the columns and plot directlytbl = {{1, 2, 3, 4}, {2, 5, 7, 8}, {9, 10, 11, 12}};data = tbl[[ All, {2, 4} ]] ListLinePlot[data, Mesh -> All, AxesOrigin -> {0, 0}]bypassing headersNow if your table had header in it, you do not need to remove these. Simply start from the second row, instead of the first row, like this:tbl = {{"h1", "h2", "h3", "h4"}, {1, 2, 3, 4},{2, 5, 7, 8},{9, 10, 11, 12}};data = tbl[[ 2 ;;, {2, 4} ]] ListLinePlot[data, Mesh -> All, AxesOrigin -> {0, 0}]
Community posts can be styled and formatted using the Markdown syntax.