I have a .dat file (which is actually a csv), whose columns are like

x1 y1 z1 w1
x2 y2 z2 w2
x3 y3 z3 w3
.  .  .  .
.  .  .  .

I want to separately obtain contour plots of z(x,y) and w(x,y) from the set of data.

I have imported the file with

mydata = Import["filename.dat","CSV"];

Now I can form the vectors containing x, y, z values with

x = mydata[[All, 1]];
y = mydata[[All, 2]];
z = mydata[[All, 3]];

How to do the contour plot? The ContourPlot function works with a function, not points.

I don't necessarily need to interpolate between the points to make it a smooth function. If there is some way to plot densities at discrete points, that will also do. However, if there is a way to do this with interpolation, or if there is some inbuilt routine to achieve this, I am also interested to know about that.

The function ListContourPlot requires a n x 3 matrix, but my data is n x 4. How can I select a column specifically?

  • 3
    $\begingroup$ ListContourPlot? See if ListContourPlot[ mydata[[All, ;;3]] ] and ListContourPlot[ mydata[[All, {1, 2, 4}]] ] do what you want. $\endgroup$
    – MarcoB
    Jan 1, 2021 at 15:55
  • $\begingroup$ Yes the second form wouldn’t work, because you are selecting the first four columns to pass to ListCountourPlot. Did you try the {1, 2, 4} syntax I showed you in my previous comment for your second case? $\endgroup$
    – MarcoB
    Jan 1, 2021 at 16:06
  • $\begingroup$ @MarcoB yes, the {1,2,4} syntax works. Please write it as an answer and I will accept it $\endgroup$ Jan 1, 2021 at 16:11
  • $\begingroup$ Glad it worked. I’ve done that. $\endgroup$
    – MarcoB
    Jan 1, 2021 at 16:33

1 Answer 1


ListContourPlot will do what you need. In particular:

ListContourPlot[ mydata[[All, ;;3]] ]
ListContourPlot[ mydata[[All, {1, 2, 4}]] ]

should do what you want.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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