[Tex/LaTex] Create a 3D figure (surf) from .csv file

pgfplots

I have a .csv file with 3 columns: time, f and psd. I would like to create a 3D surf plot using this data. Just like the following image generated in Matlab. enter image description here.

Here is the link to the data I am trying to use: datastft.csv.

The code that I am using is the following:

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}
\pgfplotsset{compat=1.9}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot3 [surf] table[x=time, y=f, z=psd, col sep=comma] {datastft.csv};

\end{axis}
\end{tikzpicture}
\end{document}

Using this code I am getting this image with lines:

enter image description here

Any help would be greatly appreciated.

Best Answer

pgfplots does not know, how the data are organized. There are thirteen scan lines. Either separate the blocks with empty lines in the .csv file or count them and specify them: mesh=rows=13.

Package pgfplots provides many different shaders and patch types (see library patchplots.

Some examples:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
\begin{axis}[x dir=reverse]
\addplot3 [surf, mesh/rows=13, shader=interp]
  table[x=f, y=time, z=psd, col sep=comma] {datastft.csv};

\end{axis}
\end{tikzpicture}
\end{document}

Result interp

With shader=faceted interp:

Result faceted interp

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{patchplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[x dir=reverse]
\addplot3 [surf, mesh/rows=13, shader=interp, patch type=bilinear]
  table[x=f, y=time, z=psd, col sep=comma] {datastft.csv};

\end{axis}
\end{tikzpicture}
\end{document}

Result interp/patch type=bilinear