# PGFPLOTS: 3d Surface plots using data file

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,%
] %
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

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.

• Welcome to TeX.SE. I think, you have missed to insert the image of the result? Also, a lot of people prefer a complete MWE from \documentclass till \end{document}. Could you please add both in order helping us to help you. – Jan Dec 29 '16 at 7:54
• Thanks Jan...as per your suggestion I have added the missing data – Gaurav Kumar Jain Dec 29 '16 at 9:21
• Are you sure data.csv is comma delimited? The link showed formatting. – John Kormylo Dec 29 '16 at 14:38
• yes it is .... Please download data.csv from given link and open in notepad++. I have just checked it. – Gaurav Kumar Jain Dec 29 '16 at 15:51
• I think that you should add the variables that you want to be on the axes and if you want that the colorbar has to be defined according to another set of variables. You also have to explain according to what principle you used mesh/rows=5 which does not seem to be compatible with the data stored in data.csv. Finally, a picture of the desired output would be very appreciated. – Pietro D'Antuono Jan 3 '17 at 4:10

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}