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 plot some data using loops, but i've some issues when I try to extract the column header and have it as a sub legend. Does anyone have any idea to fix it up ?

\documentclass{minimal}

\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usepackage{pgfplotstable}
\definecolor{skyblue1}{rgb}{0.447,0.624,0.812}


\pgfplotstableread{
time    y   c   q   r   pi  r_F efp z_E z_F
1   0.105597    0.000553    0.007493    0.002008    0.001352    41.251213   0.015177    0.015177    41.251213
2   0.003563    0.003143    -0.001881   0.000742    -0.000582   0.541130    -0.011564   -0.001644   0.545364
3   0.003204    0.004251    -0.000223   0.000048    -0.000367   -0.016199   0.000767    0.001246    -0.016337
4   0.003582    0.004518    0.000531    -0.000285   -0.000218   -0.115549   0.000642    0.000411    -0.115694
5   0.003762    0.004358    0.000743    -0.000414   -0.000126   -0.158629   0.000492    -0.000035   -0.158753
}\modelresponses
\pgfplotstablegetcolsof{\modelresponses}

\begin{document}
  \begin{tikzpicture}

    \begin{groupplot}[group style={group size=3 by 2,vertical sep= 1.5cm},width=0.45\textwidth,ybar]
     \pgfplotsinvokeforeach{1,2,3,4,5,6,7,8,9}{%
                \pgfplotstablegetcolumnnamebyindex{#1}\of{\modelresponses}\to{\mycolname};
                \nextgroupplot[title=\mycolname,grid=major];
             \addplot[very thick,smooth,skyblue1] table [ x index=0,  y index=#1] {\modelresponses};
    }
    \end{groupplot}
  \end{tikzpicture}
\end{document}
share|improve this question
    
Just to make your example compilable, replace the group title key with title=$\mycolname$. –  percusse Jun 7 '12 at 14:17
    
@percusse: I believe that's the answer to the question =) –  Jake Jun 7 '12 at 14:23
    
@percusse found the solution. It's now working, thanks a lot. –  gVermandel Jun 7 '12 at 14:44
add comment

1 Answer 1

up vote 3 down vote accepted

The underscores require the math mode. Hence a quick fix is to put the title variable between dollar signs i.e. replacing the respective line with

\nextgroupplot[title=$\mycolname$,grid=major];

However, just for the sake of curiosity it would be nice if someone can find a way to pass the title names including math characters like \pi,\psi without expanding (as I suspect it is the problem).

share|improve this answer
    
Christian Feuersänger showed a way how to do this in How can LaTeX code in a data file be read by pgfplotstable?: You define a macro \let\ESCAPE=\string at the start of the file, change the column name in the datafile to {\ESCAPE\pi}, and use title=\let\ESCAPE\relax$\mycolname$. –  Jake Jun 7 '12 at 15:39
    
@jake Aha nice. Thanks for the pointer. –  percusse Jun 7 '12 at 15:42
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.