3

I am having issues trying to build a very simple scatter plot. The csv is organized as follows:

0.09298303885566861,1976.677756339018,1.360252917788105
0.05630059591218889,3608.903320218602,-12.0558030777737
0.1027903546069633,1976.677756339018,0.8145755693068558
0.08901905835364105,2282.470869446955,-1.414111279194796
0.07962106630870476,2551.88001037322,0.002312934257887339

I need to plot marks on the locations specified by the first two columns and color them according to the third. Without receiving any error, the data are plotted at the right positions but colored according to second column.

There must be a really simple mistake. The code is:

\documentclass[border=9,tikz]{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[scale=0.75]
  \begin{axis}[]
    \addplot[scatter, only marks] table [x index=0, y index=1, meta index=2, col sep=comma] {files/data.csv};
  \end{axis}
\end{tikzpicture}

\end{document}
3

You need to set scatter src, not the meta index.

output of code

\documentclass[border=9,tikz]{standalone}
\usepackage{pgfplots,filecontents}
\begin{filecontents*}{data.dat}
0.09298303885566861,1976.677756339018,1.360252917788105
0.05630059591218889,3608.903320218602,-12.0558030777737
0.1027903546069633,1976.677756339018,0.8145755693068558
0.08901905835364105,2282.470869446955,-1.414111279194796
0.07962106630870476,2551.88001037322,0.002312934257887339
\end{filecontents*}
\begin{document}

\begin{tikzpicture}[scale=0.75]
  \begin{axis}[colorbar]
    \addplot[scatter, only marks] table [x index=0, y index=1, scatter src=\thisrowno{2}, col sep=comma] {data.dat};
  \end{axis}
\end{tikzpicture}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.