# Use BPchem Numbering As Labels in a PGFPlot

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},
]
(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.
\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?

-

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}
]
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