我创建了以下条形图。
\begin{figure}[ht!]
\caption{Accuracy comparison of A with other models}
\scriptsize
\begin{tikzpicture}
\begin{axis}
[symbolic y coords={A,B,C,D},
ytick=data,
xbar,
y=0.5cm,
enlarge y limits={abs=0.5cm},
xlabel={Accuracy(\%)}
]
\addplot[fill=blue] coordinates
{(4.90,A)
(5.05,B)
(7.99,C)
(24.67,D)
};
\end{axis}
\label{comparison}
\end{tikzpicture}
\vspace{-1.5em}
\end{figure}
但我还必须在栏目顶部显示实际数字。我该怎么做?
但我需要得到类似下面的东西来显示实际数字。
答案1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
symbolic y coords={A,B,C,D},
ytick=data,
xbar,
xmin=0,
y=0.5cm,
enlarge y limits={abs=0.5cm},
enlarge x limits={abs=3,upper},
xlabel={Accuracy(\%)},
nodes near coords={\pgfmathprintnumber{\pgfplotspointmeta}\%},
nodes near coords style={orange},
]
\addplot[fill=blue] coordinates {(4,A) (5,B) (7,C) (24,D)};
\end{axis}
\end{tikzpicture}
\end{document}