[Tex/LaTex] PGFPLOTS: 3d Surface plots using data file

pgfplots

I want to create 3D surface plot using pgfplots in LaTeX. I got the data stored in .csv file, it is available at this link data.csv

\documentclass{article}

\usepackage{pgfplots}   

\begin{document}


\begin{figure}
\hspace{-1cm}
        \begin{tikzpicture} %
        \begin{axis}[smooth,
        legend pos = north east,
        mark repeat=10,%
        ] %
        \addplot3 [surf,z buffer=sort, mesh/rows=5, shader=interp]
        table[y={batch}, x={index} , z={val_loss}, col sep=comma] {data.csv};
        \end{axis} %
        \end{tikzpicture}
\end{figure}
\end{document}

I got following output

enter image description here

This is not proper, also in data file number of observations for batch=1,2,4,6,8 is not same. Is that the reason for this messed up plot?
How can I generate the correct surface plot using this type of data.

Best Answer

Your data doesn't have to correct format for plotting a surface (the scans in x direction have different length). Use scatter instead.

\documentclass{article}

\usepackage{pgfplots}   

\begin{document}

\begin{tikzpicture}
  \begin{axis}
    \addplot3+[only marks,scatter] table[y={batch}, x={index} , z={val_loss}, col sep=comma] {data.csv};
  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here