pgfplots,table-plot:无法将输入解析为浮点数

pgfplots,table-plot:无法将输入解析为浮点数

我明白了Could not parse input 'A' as a floating point number

我需要在这里更改什么?

\documentclass[border=5pt, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,
]
\addplot[] table[y index=1] {
name data     color    
A       22        gray     
C       5          blue     
D       5         orange     
};
\end{axis}
\end{tikzpicture}
\end{document}

答案1

两个选项:

\documentclass[border=5pt, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,
]
\addplot[] table[y index=1,x expr=\coordindex] {
name data     color    
A       22        gray     
C       5          blue     
D       5         orange     
};
\end{axis}
\end{tikzpicture}
\end{document}

或者

\documentclass[border=5pt, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,symbolic x coords={A,B,C,D},xtick=data]
\addplot[] table[y index=1] {
name data     color    
A       22        gray     
C       5          blue     
D       5         orange     
};
\end{axis}
\end{tikzpicture}
\end{document}

相关内容