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, 확대 제한=0.15, 범례 스타일=at=(0.5,-0.2), 앵커=북쪽, 범례 열=-1, ylabel=#participants, 기호 x 좌표=?? ,좋음,중립,좋지 않음,나쁨, xtick=데이터, 좌표 근처 노드, 좌표 근처 노드 정렬=수직, x 눈금 라벨 스타일=회전=45,앵커=동쪽, ] 좌표(?? ,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이 접근 방식을 사용하지 말고 대신 를 \coordindexx 좌표로 사용하고 를 사용하여 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}

관련 정보