pgfplots won't plot from CSV

I have a file called 'dat.csv' that contains data in the following format:

x,y,z
-2.4,-2.4,0.00208966369454526
-2.3,-2.4,0.00245568047497186
-2.2,-2.4,0.00284901821144199
-2.1,-2.4,0.00326424484110634
-2,-2.4,0.00369478959101684
-1.9,-2.4,0.00413324571684902
-1.8,-2.4,0.00457174861531703
-1.7,-2.4,0.00500239752919971
-1.6,-2.4,0.00541768332000374
-1.5,-2.4,0.005810883691126
-1.4,-2.4,0.00617639102950998
-1.3,-2.4,0.00650994613105532
-1.2,-2.4,0.0068087622314587
-1.1,-2.4,0.00707153627611177
-1,-2.4,0.00729835639420583
-0.9,-2.4,0.00749052445419115
-0.8,-2.4,0.00765031919830823
-0.7,-2.4,0.00778072823782364
-0.6,-2.4,0.0078851762449041
-0.5,-2.4,0.00796727266169779
-0.4,-2.4,0.00803059618622074
-0.3,-2.4,0.00807852634842078
-0.2,-2.4,0.00811412573961708
-0.0999999999999996,-2.4,0.00814007074426613
4.44089209850063e-16,-2.4,0.00815862445567777
...


I'd like to plot the function that generated this data using pgfplots. So far I have:

\documentclass{scrartcl}

\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}
table{dat.csv};
\end{axis}
\end{tikzpicture}
\end{document}


This however, doesn't work as I get:

! Package pgfplots Error: Sorry, the requested column number '1' in table 'dat.
csv' does not exist!? Please verify you used the correct index 0 <= i < N..


for column numbers 1 and 2 as well as errors of the type:

! Package PGF Math Error: Could not parse input '-2.4,-2.4,0.00208966369454526' as a floating point number, sorry. The unreadable part was near ',-2.4,0.00208966369454526'..


Any help would be appreciated!

• You have to use \addplot3[surf] table [col sep=comma] {dat.csv}; to tell PGFPlots to expect commas as column separators (default is white space).
– Jake
Mar 17 '15 at 11:21

You have to use \addplot3[surf] table [col sep=comma] {dat.csv}; to tell PGFPlots to expect commas as column separators. By default, PGFPlots assumes that the columns are separated by white space.
• I had col sep=comma, but that didn't work. However, my file was named .txt instead of .csv. After I changed that to .csv, that worked. Dec 20 '19 at 13:54