Possible Duplicate:
Use first row of a table as legend entry in pgfplot graph ?
I am creating a number of very similar plots using pgfplots. The raw data for these is provided in a single .csv file, so something like
x,a,b,c,d,e
0,0.04,0.03,0.04,0.03,0.04
1,0.06,0.05,0.06,0.05,0.06
2,0.06,0.07,0.06,0.07,0.06
3,0.09,0.08,0.09,0.08,0.09
4,0.13,0.12,0.13,0.12,0.13
5,0.13,0.12,0.13,0.12,0.13
(In the real case, there are a lot more rows and columns.) Each plot is separate (i.e. not on the same axes), but they are produced 'semi-automatically' using a suitable macro containing a plot environment of the form
\newcommand{\buildplot}[1]%
{%
\begin{tikzpicture}
\begin{axis}
[
axis x line = bottom,
axis y line = left,
]
\addplot [mark = none]
table [col sep = comma, y index = #1]
{example.csv};
\end{axis}
\end{tikzpicture}
}
The plots need to be differentiated, and the easiest way is to use the column header (in the example data a, b, etc.) as the title key. However, I cannot find a way to recover the header within the plotting environment to achieve this. As the information is already in the .csv, I would rather avoid retyping it in the document if at all possible.
\buildplotmacro, as there are various other settings which have to be adjusted on a plot-by-plot basis, plus some general set up to make things look good. – Joseph Wright Jan 04 '12 at 08:58datatoolpackage (Nicola Talbot) uses provides an API for creatingtabulars from CSV input. It seems to be capable of extracting the information in the first line/as well as ignoring it. – Jan 04 '12 at 09:12pgfplotshas a solution for Jospephs problem, it'd be nice to know how to deal with the ``input''. – Jan 04 '12 at 19:34\inputcommand, then you should add the [tag:input] tag again. – lockstep Jan 04 '12 at 19:37\input). – Joseph Wright Jan 04 '12 at 20:07pgfplots. If you want to pursue this, I suggest popping into the chat system. (Comments are not the best way to run a discussion.) – Joseph Wright Jan 04 '12 at 20:15pgfplotswould be desirable and would help similar questions in context with different packages. That's my point. No need to reply to this. I'll pose a question in a different thread. – Jan 04 '12 at 22:29