使用 BPchem 編號作為 PGFPlot 中的標籤

使用 BPchem 編號作為 PGFPlot 中的標籤

因此,我直接從 手冊中刪除了這個範例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,放大限制=0.15,圖例樣式=at=(0.5,-0.2),錨點=北,圖例列=-1,ylabel=#participants,符號x座標=?? ,好,中性,不好,差,xtick=資料,座標附近的節點,座標附近的節點align=垂直,x刻度標籤style=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}

相關內容