# How to make a contour plot from a .dat file

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?

• ListContourPlot? See if ListContourPlot[ mydata[[All, ;;3]] ] and ListContourPlot[ mydata[[All, {1, 2, 4}]] ] do what you want. Jan 1, 2021 at 15:55
• 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? Jan 1, 2021 at 16:06
• @MarcoB yes, the {1,2,4} syntax works. Please write it as an answer and I will accept it Jan 1, 2021 at 16:11
• Glad it worked. I’ve done that. Jan 1, 2021 at 16:33

ListContourPlot will do what you need. In particular:
ListContourPlot[ mydata[[All, ;;3]] ]