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.

So, I yanked this example right from the manual on pgfplots, because this looks highly complex. The graph is exactly what I want to have, except instead of the custom labels it provided, I want to be able to insert the compound numbering from BPChem as the labels instead, so as a test I replaced that first symbolic x coord with my own number reference. Needless to say it does not work :(

\documentclass[12pt, letterpaper]{article}
\usepackage{pgfplots}
\usepackage{bpchem}
\begin{document}

\CNlabelsubnoref{cmp1}{a}
\begin{tikzpicture}
    \begin{axis}[
        ybar,
        enlargelimits=0.15,
        legend style={at={(0.5,-0.2)},
        anchor=north,legend columns=-1},
        ylabel={\#participants},
        symbolic x coords={\CNrefsub{cmp1}{a},good,neutral,%
        not good,poor},
        xtick=data,
        nodes near coords,
        nodes near coords align={vertical},
        x tick label style={rotate=45,anchor=east},
        ]
        \addplot coordinates {(\CNrefsub{cmp1}{a},0) (good,8)
        (neutral,2) (not good,0) (poor,0)};
    \end{axis}
\end{tikzpicture}

\end{document}

pdflatex compilation never finishes, but the pdf file contains this...

pgfplots [ ybar, enlargelimits=0.15, legend style=at=(0.5,-0.2), anchor=north,legend columns=-1, ylabel=#participants, symbolic x coords=?? ,good,neutral,not good,poor, xtick=data, nodes near coords, nodes near coords align=vertical, x tick label style=rotate=45,anchor=east, ] coordinates (?? ,0) (good,8) (neutral,2) (not good,0) (poor,0); 1

If I stop pdflatex, I get the following errors in my console:

! Missing \endcsname inserted.
<to be read again>
\protect
l.20 ]
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
Missing character: There is no a in font nullfont!
! Extra \endcsname.
\pgfplotsarray@glob@TMP ...ts@loc@TMPa \endcsname
Process exited with error(s)

Any chance this is something that can be worked around?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I would suggest not using the symbolic x coords approach, but instead using the \coordindex as the x coordinate and providing the x tick labels using xticklabels={\CNrefsub{cmp1}{a}, good, neutral, not good, bad}.

\documentclass[12pt, letterpaper]{article}
\usepackage{pgfplots}
\usepackage{bpchem}
\begin{document}

\CNlabelsubnoref{cmp1}{a}
\begin{tikzpicture}
    \begin{axis}[
        ybar,
        enlargelimits=0.15,
        legend style={at={(0.5,-0.2)},
        anchor=north,legend columns=-1},
        ylabel={\#participants},
        xtick=data,
        nodes near coords,
        nodes near coords align={vertical},
        x tick label style={rotate=45,anchor=east},
        xticklabels={\CNrefsub{cmp1}{a}, good, neutral, not good, bad}
        ]
        \addplot table [
            x expr=\coordindex, % Use the row number as x coordinate
            header=false    % Do not assume the first row to contain column names
        ] {
        cmp     0
        good    8
        neutral 2
        notgood 0
        bad     0
        };
    \end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
Works perfect, thank you! I really was so overwhelmed by the documentation for pgfplots (it's huge!), that I had no clue where to look to solve this. –  J M Aug 17 '12 at 13:54
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.