Verwenden Sie die BPchem-Nummerierung als Beschriftung in einem PGFPlot

Verwenden Sie die BPchem-Nummerierung als Beschriftung in einem PGFPlot

Ich habe dieses Beispiel also direkt aus dem Handbuch genommen pgfplots, weil es sehr komplex aussieht. Die Grafik ist genau das, was ich haben möchte, außer dass ich anstelle der benutzerdefinierten Beschriftungen, die es bereitstellt, die zusammengesetzte Nummerierung von BPChemals Beschriftung einfügen möchte. Als Test habe ich diese also zuerst symbolic x coorddurch meine eigene Nummernreferenz ersetzt. Es ist unnötig zu sagen, dass es nicht funktioniert :(

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

Die Kompilierung von pdflatex wird nie abgeschlossen, aber die PDF-Datei enthält Folgendes …

pgfplots [ybar, enlargelimits=0.15, legend style=at=(0.5,-0.2), anchor=north,legend columns=-1, ylabel=#participants, symbolische x-Koordinaten=?? ,gut,neutral,nicht gut,schlecht, xtick=Daten, Knoten nahe Koordinaten, Knoten nahe Koordinaten align=vertikal, x-tick label style=rotate=45,anchor=east, ] Koordinaten (?? ,0) (gut,8) (neutral,2) (nicht gut,0) (schlecht,0); 1

Wenn ich pdflatex stoppe, erhalte ich die folgenden Fehler in meiner Konsole:

! 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)

Besteht die Möglichkeit, dieses Problem zu umgehen?

Antwort1

Ich würde vorschlagen, diesen symbolic x coordsAnsatz nicht zu verwenden, sondern stattdessen \coordindexals x-Koordinate zu verwenden und die x-Teilstrichbeschriftungen mithilfe von bereitzustellen 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}

verwandte Informationen