2
votes

I have a CSV file with 5 columns and about 2*104 rows that I need to visualise.

I've imported the file like so:

data = Import["res.csv", "CSV"];`

Now, I'm going to want to generate a lot of visuals from this - all 5 dimensions on a single plot as well as various cross sections.

My questions:

If I want to select, say columns 1, 4 and 5 from my data and feed them to ListPlot3D how would I do that?

And, values in columns can be grouped. So if I wanted to ListPlot3D colums 1, 2, 4 and 5, but I want to group columns 1 and 2 on the same axis, how would I tell Mathematica to do that?

Thanks.

2
On second thoughts, assuming that column 1 and 2 are x-axis values, column 4 the y-axis value, and column 5 the z-axis value (which is usually the dependent value) does that mean that two differing sets of x-values give rise to the same set of dependent z-values? - Sjoerd C. de Vries
@Sjoerd, columns 4 and 5 are independent of each other, but both of them are dependant on columns 1, 2 and 3. The first 3 colums are something like: for every col1 value there are 10 col2 values. and for every col2 value there are 100 col3 values. - Griffin
Since ListPlot3D requires {x,y,z} triples, you have to describe which columns map to x, y, and z respectively, for each of the two data sets. So may I assume col 4 maps to z for the first set, and col 5 to z for the second set? And the, which columns map to x and y? - Sjoerd C. de Vries
I just need the syntax for grouping columns, I will figure out what combinations I need. For now lets just say columns 1 and 2 map to X, column 3 is Y and columns 4 and 5 will be Z on individual plots. - Griffin
Changed the 2nd part of my code accordingly. - Sjoerd C. de Vries

2 Answers

3
votes

I hate to disagree with a fellow poster especially after it has been accepted, but the Transpose is unnecessary. Almost everything you're asking for can be done within the context of Part:

ListPlot3D[ data[[All, {1, 4, 5}]] ]

Since matrices are stored row-wise within Mathematica, [[All, {1, 4, 5}]] can be read [[rows, columns]]. More specifically, All indicates here that you want all rows, but you can specify specific rows as well. Another construct that may be of interest is Span which is used to specify groups of indices, and if your CSV file contains a header row, you can strip it from your data using

ListPlot3D[ data[[ 2 ;; , {1, 4, 5}]] ]

As to your second requirement, to use both columns 1 and 2 as the x coordinate, then it is simply

ListPlot3D[ {data[[All, {2, 4, 5}]], data[[All, {1, 4, 5}]]} ]

and you change All to 2;; if you wish to strip off the header row.

2
votes

If I understand you correctly that would be

ListPlot3D[Transpose[{data[[All, 1]], data[[All, 4]], data[[All, 5]]}]]

and for the multiple sets:

ListPlot3D[
 {
  Transpose[{data[[All, 1]], data[[All, 3]], data[[All, 4]]}],
  Transpose[{data[[All, 2]], data[[All, 3]], data[[All, 5]]}]
  }
 ]