3

I have a CSV data file like the following

X Y Z T
0 0 0 12420
0 0 1 2154
0 0 2 54565
0 0 3 54640
   .
   .
0 0 10 53565
0 1 0 12420
   .
   .
0 1 10 53565
   .
   .
0 10 10 53565
1  0  0 2454535
   .
   .
10 10 10 6985

which represents a discrete three-dimensional field (for instance, T(x,y,z), where x, y and z are discrete values). I would like to plot a slice of this field (for instance, T(x,y) for z=10, assuming the original file has this information - i.e., interpolation is not necessary), using the pgfplots package. For this, I would normally break the CSV file to only have the results for z=10, but I've been wondering if it is possible to do this directly from the original file (with the 3D field), also using pgfplots?

I am aware of the skip coords between index command, but so far I have not been able to use it for the purpose I want.

  • 1
    Here you can see how to do the analogous, in 2 dimensions, of what you want to do in 3 dimensions. That answer makes use of \addplot3 with the restrict x to domain option (or y or z). So you could give x and y meshes and z values and then consider only data with z in a given range. There's not a \addplot4 to which you can give x, y and z meshes and v values and then restrict to a certain range of v. – Enrico Maria De Angelis Jul 25 '16 at 15:13
  • You could add the structure of the data file, just as in the answer I linked. In your case it should be a 4 column table, isn't it? – Enrico Maria De Angelis Jul 25 '16 at 16:00
  • 1
    @EnricoMariaDeAngelis Yes, it is a 4 column table, kind of like the one in the link you posted, but with an extra column (that would correspond to the values of T, in my example). The CSV files I'm working on are very large and that's the reason why I didn't posted them here, but I could create an example to ilustrate what I mean, if it's not clear yet. – Guilherme Fraga Jul 26 '16 at 17:38
  • @EnricoMariaDeAngelis Regarding your other comment, as you've said, the restric x (or y or z) to domain doesn't seem to work in my case. Basically, what I'd like to do is create an 3D plot based on a 4 column file where data from one of the columns is not ploted, but used to indicate from which rows of the other columns the data should be extracted an plotted. Alternatively, I could use a 3 column file and 3D plot only selected rows (using the row indices, for example), but I don't know how to do that either. – Guilherme Fraga Jul 26 '16 at 17:44
  • I think I found a (more) related answer here, where there's the case of a 4-column table from which rows to plot are selected based on the number in one of the columns. – Enrico Maria De Angelis Jul 27 '16 at 7:00
1

Actually my answer is just the same answer @percusse gave to another question.

That answer is about filtering the table to ignore rows with a certain value in one column (in your case z filter/.code={proper stuff here}).

Digression

I think that the tags of that answer (pgfplots and pgfpolotstable) make difficult for you (and other interested people) to find it. Because of this I added the tag 4d to both that and this answer, for the following reason

  • 3d usually make people think about functions of two variables, where a 3D plot is needed for the function to be represented "geometrically" (I mean surface plots), and a 2D plot is enough when the value of the functions are represented by color (I mean contours).
  • In your case you have a function of 3 variables and, in turn, you will need a 4D plot (it'd be a hyper-surface plot, ahahah, but as I wrote in a comment there's no \addplot4 which you can add the restrict z to domain option to), and a 3D contour plot would be enough (balls on a 3D grid with colors depending on the value of the funciton?).

If you will ever post another answer concerning 4d data, you better use that tag. Maybe it can be useful for someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.