
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}
結果: