이것은 내 MWE입니다.
\begin{tikzpicture}
\pgfplotstableread{ % Read the data into a table macro
Label First Second Third
Yes 0.1 0.3 0.3
No 0.9 0.7 0.7
}\datatable
\begin{axis}[
xbar stacked, % Stacked horizontal bars
xmin=0, % Start x axis at 0
ytick=data, % Use as many tick labels as y coordinates
yticklabels from table={\datatable}{Label} % Get the labels from the Label column of the \datatable
]
\addplot [fill=yellow] table [x=First, y expr=\coordindex] {\datatable}; % Plot the "First" column against the data index
\addplot [fill=green!70!blue] table [x=Second, y expr=\coordindex] {\datatable};
\addplot [fill=red!80!yellow] table [x=Third, y expr=\coordindex] {\datatable};
\end{axis}
\end{tikzpicture}
이 스크립트는 y축이 열의 예/아니요 값에 해당하는 차트를 생성합니다.첫 번째,두번째, 그리고제삼. y축이 열에 해당하도록 스크립트를 어떻게 변경합니까(예:첫 번째,두번째, 그리고제삼)? 특정 열에 대한 예/아니요 분포를 수평으로 표현해야 합니다.
답변1
나는 해결책을 찾았습니다.테이블을 전치하다스크립트를 다음과 같이 수정합니다.
\begin{tikzpicture}
\pgfplotstableread{ % Read the data into a table macro
Label First Second Third
Yes 0.1 0.3 0.3
No 0.9 0.7 0.7
}\datatable
\pgfplotstabletranspose[string type, colnames from=Label, input colnames to=Label]\datatabletransposed{\datatable}
\begin{axis}[
xbar stacked, % Stacked horizontal bars
xmin=0, % Start x axis at 0
ytick=data, % Use as many tick labels as y coordinates
yticklabels from table={\datatabletransposed}{Label} % Get the labels from the Label column of the \datatable
]
\addplot [fill=green!70!blue] table [x=Yes, y expr=\coordindex] {\datatabletransposed};
\addplot [fill=red!70!blue] table [x=No, y expr=\coordindex] {\datatabletransposed};
\end{axis}
\end{tikzpicture}