在 PGFPlot 中使用 BPchem 编号作为标签

在 PGFPlot 中使用 BPchem 编号作为标签

因此,我直接从手册中摘取了这个示例pgfplots,因为这看起来非常复杂。图表正是我想要的,除了它提供的自定义标签之外,我希望能够插入化合物编号作为BPChem标签,因此作为测试,我首先symbolic x coord用自己的数字参考替换了它。不用说,它不起作用 :(

\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 编译永远不会完成,但 pdf 文件包含这个......

pgfplots [ ybar,largelimits=0.15,图例样式=at=(0.5,-0.2),anchor=north,图例列=-1,ylabel=#participants,符号 x 坐标=??,好,中性,不好,差,xtick=data,节点靠近坐标,节点靠近坐标对齐=垂直,x 刻度标签样式=rotate=45,anchor=east,] 坐标 (??,0) (好,8) (中性,2) (不好,0) (差,0);1

如果我停止 pdflatex,我的控制台中会出现以下错误:

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

有没有可能解决这个问题?

答案1

我建议不要使用该symbolic x coords方法,而是使用\coordindex作为 x 坐标并使用提供 x 刻度标签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}

相关内容