
Latex가 메시지와 함께 아래 코드를 컴파일하지 못합니다.
Could not parse input 'industry' as a floating point number, sorry. The unreadable part was near 'ndustry'..
Pgfplots는 첫 번째 열 데이터가 문자열이라는 것을 인식하지 못하는 것 같습니다. 이것을 바로잡을 방법이 있나요?
\documentclass{minimal}
\usepackage{pgfplots,pgfplotstable}
\begin{document}
\pgfplotstableread{
category cond othr
industry 202 72.8
transport 0 352
households 248 45.8
services 96 55.8
rest 0 30.3
}\data
\begin{tikzpicture}
\begin{axis}[xbar stacked,yticklabels from table={\data}{category}]
\addplot table[x=cond,y=category]{\data};
\addplot table[x=othr,y=category]{\data};
\end{axis}
\end{tikzpicture}
\end{document}
답변1
ytick=data
플롯에 axis
및 y expr=\coordindex
플롯에 사용할 수 있습니다 .
\documentclass[margin=5pt]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.15}
\begin{document}
\pgfplotstableread{
category cond othr
industry 202 72.8
transport 0 352
households 248 45.8
services 96 55.8
rest 0 30.3
}\data
\begin{tikzpicture}
\begin{axis}[xbar stacked,yticklabels from table={\data}{category},
ytick=data
]
\addplot table[x=cond,y expr=\coordindex]{\data};
\addplot table[x=othr,y expr=\coordindex]{\data};
\end{axis}
\end{tikzpicture}
\end{document}
결과: