# PgfPlots column name with multiple words

I have a simple data file consisting of two columns (x and y coordinates). I would like the first row of the file to be the names for the columns. I would like the user to have the option to specify the column names however he/she sees fit, including multiple words for one column. An example:

Number of points    Values
10    100
20    400
30    1200
40    2345
etc...


I can get this to work (as expected) when using single words for column names but as soon as I introduce multiple words I can not get latex to compile. I've tried the following in my latex:

\addplot table [only marks, x={Number of Points}, y={Time}] {...}
\addplot table [only marks, x=${Number of Points}$, y=${Time}$] {...}
\addplot table [only marks, x="Number of Points", y=Time] {...}


I've tried other variations as well and no luck. I keep getting the error:

"Sorry, could not retrieve 'Number of Points' from table..."

Any thoughts would be GREATLY appreciated.

-
Ideally we'd like to see something like a minimal working example (MWE) that starts with \documentclass and ends with \end{document}. You can include a dataset in your MWE using filecontents if needed. It makes things portable, and helps us to ultimately help you. –  Werner Mar 28 '14 at 19:31

You can wrap the offending column name in braces:

    {Number of points} Values


Here's a complete MWE:

% arara: pdflatex
\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[only marks] table[x=Number of points,y=Values] {%
{Number of points} Values
10 100
20 400
30 1200
40 2345
};
\end{axis}
\end{tikzpicture}
\end{document}

-
Definitely more convenient than my solution! –  sudosensei Mar 28 '14 at 20:10
@sudosensei I like your solution as it shows another approach :) +1 –  cmhughes Mar 28 '14 at 20:11
Thanks a ton to both of you. –  MCP Mar 28 '14 at 20:47

The problem is that you use spaces to separate both the words in the column name and the columns themselves. If you use something other than space to delimit the columns, it works fine, without even having to wrap the column name in delimiters.

In this example, I used a comma and I let pgfplots know that the column separator is a comma using col sep=comma:

# Solution:

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[only marks] table[col sep=comma,x=Number of points,y=Values] {%
Number of points, Values
10, 100
20, 400
30, 1200
40, 2345
};
\end{axis}
\end{tikzpicture}
\end{document}


-