对pgfplots
不是太了解,follow reference link,尝试给出一个解答:
\documentclass[11pt, border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
colormap/jet,% change colormap style here
scatter,
scatter src=x,
only marks,
clip mode=individual,
scatter/@pre marker code/.append code={
\pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}
\pgfmathsetmacro\negheight{-\pgfplotspointmeta}
\fill [draw=black] (axis direction cs:0,0.3) rectangle (axis direction cs:\negheight,-0.3);\pgfplotsset{mark=none}
},
width=12cm,
height=8cm,
grid=both,
ytick=data,
xmin=0,xmax=100,
xlabel={Percentage (\%)},
ylabel={Categories},
% symbolic y coords={A, B, C, D, E},
yticklabels={A, B, C, D, E},
ytick style={draw=none},
%nodes near coords,
enlarge y limits=.2,
xtick={0, 20, 40, 60, 80, 100},
xticklabel=\pgfmathprintnumber{\tick}\%,
]
\addplot coordinates {(23,1) (45,2) (56,3) (78,4) (89,5)};
\end{axis}
\end{tikzpicture}
\end{document}
问 如何使得横向柱状图的不同分类ABCDE用不同颜色显示