Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a comma-separated list of data points. They should be plotted as a scatter plot, and should be labeled using data from the .csv file. Having specified the first column of my file as string type, I still keep running into errors saying Could not parse input [...] as a floating point number, sorry.

Given a CSV file of the following format, how can I read Name and Z as labels?

Name,X,Y,Z
ODIN,250,45,2001

Here is my MWE:

\documentclass{article}

\usepackage{tikz,pgfplots,pgfplotstable}
    \pgfplotsset{compat=1.5.1}

\begin{document}

\pgfplotstabletypeset[columns/Name/.style={string type}]{table.csv};

\begin{tikzpicture}
    \begin{axis}[
    visualization depends on=\thisrow{Name} \as \labela,
    visualization depends on=\thisrow{Z} \as \labelb,
    every node near coord/.append style={font={\tiny}},
    nodes near coords=\labela/\labelb,
    nodes near coords align={horizontal},]

    \addplot[only marks] table [x=X,y=Y,col sep=comma] {table.csv};

    \end{axis}
\end{tikzpicture}

\end{document}

Note that if the data in column Name is just floats it should work fine.

share|improve this question

1 Answer 1

up vote 12 down vote accepted

You need to add value prefix if you don't want the contents to be parsed as numbers.

\documentclass{article}
\usepackage{pgfplots,pgfplotstable,filecontents}
\begin{filecontents*}{table.csv}
Name,X,Y,Z
ODIN,250,45,2001
NIDO,280,70,2002
DINO,270,60,2003
\end{filecontents*}
\begin{document}

\pgfkeys{/pgf/number format/set thousands separator={}}
\pgfplotstabletypeset[columns/Name/.style={string type},col sep=comma]{table.csv}


\begin{tikzpicture}
    \begin{axis}[
    visualization depends on={value \thisrow{Name} \as \labela}, % note the value prefix
    visualization depends on={\thisrow{Z} \as \labelb},
    every node near coord/.append style={font={\tiny}},
    nodes near coords={\labela/\pgfmathprintnumber\labelb},
    nodes near coords align={horizontal}
        ]

    \addplot[scatter,only marks] table [x=X,y=Y,col sep=comma] {table.csv};

    \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
That's great to know, thanks. Can you tell me how you found that out? –  Ingo Jun 18 '12 at 13:48
1  
@Ingo I've struggled with this before. It's also in the manual (at the top of page 284 ver. 1.5.1) Much easier when you know what to look for :) –  percusse Jun 18 '12 at 14:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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