1

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.

8
  • 1
    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, 2016 at 7:54
  • 1
    Thanks Jan...as per your suggestion I have added the missing data Dec 29, 2016 at 9:21
  • Are you sure data.csv is comma delimited? The link showed formatting. Dec 29, 2016 at 14:38
  • yes it is .... Please download data.csv from given link and open in notepad++. I have just checked it. Dec 29, 2016 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. Jan 3, 2017 at 4:10

1 Answer 1

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .