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'm trying to include and fetch text from a pgf plot table without succeeding.

When using just numbers, everything goes smoothly:

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{tikz}

\pgfplotstableread[col sep=comma]{
1
}\mydata

\begin{document}
\begin{tikzpicture}
\pgfplotstablegetelem{0}{0}\of\mydata
\node[draw=black] at (0,0) {\pgfplotsretval};
\end{tikzpicture}

\end{document}

However, when exchanging the number for a letter or a text string, like so

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{tikz}

\pgfplotstableread[col sep=comma]{
a
}\mydata

\begin{document}
\begin{tikzpicture}
\pgfplotstablegetelem{0}{0}\of\mydata
\node[draw=black] at (0,0) {\pgfplotsretval};
\end{tikzpicture}

\end{document}

I get the following error message:

! Package pgfplots Error: Sorry, could not retrieve column '0' from table '<inl
ine_table>'. Please check spelling (or introduce name aliases)..

See the pgfplots package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.12 \pgfplotstablegetelem{0}{0}\of\mydata

How can I include and fetch text from my pgf plot table? I've tried things like enclosing the text in " or ' to no avail.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

If \pgfplotstableread encounters a non-numeric character in the first line of the table, it assumes that this line contains the column names. In this case, it thinks that your table contains just one column, called a, without any data, which is why trying to retrieve the first element of column 0 doesn't work: There's no column called 0, and there's no first element. You can tell PGFPlots that everything should be treated as data by setting header=false in the \pgfplotstableread options:

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{tikz}

\pgfplotstableread[col sep=comma, header=false]{
a
}\mydata

\begin{document}
\begin{tikzpicture}
\pgfplotstablegetelem{0}{0}\of\mydata
\node[draw=black] at (0,0) {\pgfplotsretval};
\end{tikzpicture}

\end{document}
share|improve this answer
    
Excellent! My real problem was trying to fetch data from a larger file, where the first row first contained some text strings and then a bunch of numbers. I guess this means that numbers aren't allowed as column names. –  Speldosa Jan 11 '13 at 10:54
    
@Speldosa: Glad it helps! Numbers are allowed as column names: In that case, you have to set header=has colnames. –  Jake Jan 11 '13 at 11:07
add comment

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.