![pgfplots、ybar 堆叠、节点附近的坐标使用文本而不是值](https://linux22.com/image/450110/pgfplots%E3%80%81ybar%20%E5%A0%86%E5%8F%A0%E3%80%81%E8%8A%82%E7%82%B9%E9%99%84%E8%BF%91%E7%9A%84%E5%9D%90%E6%A0%87%E4%BD%BF%E7%94%A8%E6%96%87%E6%9C%AC%E8%80%8C%E4%B8%8D%E6%98%AF%E5%80%BC.png)
答案1
您可以设置point meta={TeX code symbolic={\def\pgfplotspointmeta{something}}}
,并为每个图添加它们。我只做了前五个图作为示例。但我认为这不是这个条形图的好方法,因为您有太多条形堆叠在一起,这会使标签难以辨认。我认为您需要将它们拆分成单独的图表。
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=30cm,compat=1.9}
\newcommand\mtlarge{\fontsize{15pt}{18pt}\selectfont}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
ymin=0,
ymax=100,
bar width=35pt,
nodes near coords,
legend style={at={(0.5,-0.06)},
anchor=north,legend columns=10,font=\mtlarge},
ylabel={percentage},
y label style={font=\mtlarge},
y tick label style={font=\mtlarge},
symbolic x coords={person, man, bird, sit, snake, woman, house, dog, human, table, head, fish, boat, hat, cat},
xtick=data,
x tick label style={rotate=45,anchor=east,font=\mtlarge},
node near coords style={black},
]
\addplot+[ybar,point meta={TeX code symbolic={\def\pgfplotspointmeta{head}}}] plot coordinates {(person,21.6) (man,19.5) (bird,19.6) (sit,19.2) (snake,33.8) (woman,19.4) (house,0.4) (dog,17.3) (human,22.0) (table,3.9) (head,24.5) (fish,21.7) (boat,11.6) (hat,9.1) (cat,15.6)};
\addplot+[ybar,point meta={TeX code symbolic={\def\pgfplotspointmeta{body}}}] plot coordinates {(person,14.5) (man,13.9) (bird,14.7) (sit,15.8) (snake,33.1) (woman,12.7) (house,1.5) (dog,15.7) (human,16.7) (table,4.6) (head,9.6) (fish,22.8) (boat,28.1) (hat,11.8) (cat,13.7)};
\addplot+[ybar,point meta={TeX code symbolic={\def\pgfplotspointmeta{leg}}}] plot coordinates {(person,17.2) (man,15.8) (bird,3.1) (sit,17.2) (snake,0.3) (woman,12.1) (house,0.7) (dog,17.7) (human,14.2) (table,24.7) (head,4.8) (fish,0.6) (boat,0.8) (hat,7.7) (cat,12.3)};
\addplot+[ybar,point meta={TeX code symbolic={\def\pgfplotspointmeta{arm}}}] plot coordinates {(person,15.4) (man,13.2) (bird,0.6) (sit,8.9) (snake,0.2) (woman,12.6) (house,0.0) (dog,0.9) (human,10.9) (table,2.9) (head,5.9) (fish,0.4) (boat,4.1) (hat,6.2) (cat,1.4)};
\addplot+[ybar,point meta={TeX code symbolic={\def\pgfplotspointmeta{tail}}}] plot coordinates {(person,0.1) (man,0.0) (bird,13.2) (sit,1.9) (snake,23.5) (woman,0.1) (house,0.0) (dog,8.8) (human,0.1) (table,0.0) (head,1.5) (fish,23.4) (boat,0.0) (hat,0.8) (cat,12.4)};
\addplot+[ybar] plot coordinates {(person,1.8) (man,2.0) (bird,7.5) (sit,3.5) (snake,4.3) (woman,2.5) (house,0.0) (dog,9.2) (human,1.5) (table,0.0) (head,12.2) (fish,0.0) (boat,1.7) (hat,2.9) (cat,4.1)};
\addplot+[ybar] plot coordinates {(person,0.1) (man,0.0) (bird,21.0) (sit,0.7) (snake,0.0) (woman,0.0) (house,0.7) (dog,0.0) (human,0.0) (table,0.0) (head,1.3) (fish,3.4) (boat,0.0) (hat,1.2) (cat,0.0)};
\addplot+[ybar] plot coordinates {(person,1.7) (man,2.9) (bird,1.6) (sit,1.9) (snake,1.8) (woman,5.7) (house,0.0) (dog,4.6) (human,0.4) (table,0.4) (head,7.3) (fish,3.6) (boat,0.8) (hat,11.0) (cat,6.7)};
\addplot+[ybar] plot coordinates {(person,4.8) (man,3.5) (bird,1.8) (sit,3.7) (snake,0.2) (woman,4.5) (house,0.0) (dog,1.4) (human,3.2) (table,0.6) (head,1.0) (fish,0.0) (boat,0.0) (hat,1.9) (cat,0.4)};
\addplot+[ybar] plot coordinates {(person,1.9) (man,3.1) (bird,1.9) (sit,2.0) (snake,0.0) (woman,3.8) (house,0.4) (dog,0.9) (human,1.2) (table,3.1) (head,2.5) (fish,0.2) (boat,3.3) (hat,1.2) (cat,2.8)};
\addplot+[ybar] plot coordinates {(person,1.9) (man,3.2) (bird,2.0) (sit,1.1) (snake,0.0) (woman,3.5) (house,0.4) (dog,0.5) (human,1.2) (table,3.1) (head,2.5) (fish,0.0) (boat,4.1) (hat,1.2) (cat,3.4)};
\addplot+[ybar] plot coordinates {(person,0.1) (man,0.2) (bird,0.4) (sit,0.1) (snake,0.0) (woman,0.0) (house,3.7) (dog,0.0) (human,0.0) (table,4.4) (head,0.6) (fish,0.0) (boat,9.9) (hat,0.8) (cat,0.2)};
\addplot+[ybar] plot coordinates {(person,1.7) (man,1.7) (bird,0.3) (sit,3.0) (snake,0.3) (woman,1.3) (house,1.1) (dog,5.1) (human,2.0) (table,0.4) (head,0.8) (fish,0.9) (boat,4.1) (hat,1.0) (cat,4.4)};
\addplot+[ybar] plot coordinates {(person,3.4) (man,4.0) (bird,0.1) (sit,2.1) (snake,0.0) (woman,3.6) (house,0.0) (dog,0.4) (human,6.6) (table,0.2) (head,1.3) (fish,0.0) (boat,0.0) (hat,1.2) (cat,0.0)};
\addplot+[ybar] plot coordinates {(person,0.3) (man,0.3) (bird,0.2) (sit,0.2) (snake,0.3) (woman,0.4) (house,2.6) (dog,0.4) (human,0.0) (table,11.2) (head,2.3) (fish,1.9) (boat,4.1) (hat,4.1) (cat,0.7)};
\addplot+[ybar] plot coordinates {(person,3.1) (man,2.5) (bird,0.2) (sit,2.2) (snake,0.0) (woman,4.0) (house,0.0) (dog,0.7) (human,4.6) (table,0.4) (head,2.9) (fish,0.0) (boat,0.0) (hat,2.1) (cat,0.7)};
\addplot+[ybar] plot coordinates {(person,2.9) (man,2.9) (bird,0.5) (sit,2.0) (snake,1.0) (woman,2.9) (house,0.4) (dog,0.9) (human,1.1) (table,0.4) (head,0.6) (fish,0.9) (boat,1.7) (hat,0.8) (cat,0.9)};
\addplot+[ybar] plot coordinates {(person,0.0) (man,0.1) (bird,0.0) (sit,0.0) (snake,0.0) (woman,0.1) (house,0.0) (dog,0.0) (human,0.0) (table,0.4) (head,0.6) (fish,0.0) (boat,0.8) (hat,0.0) (cat,0.0)};
\addplot+[ybar] plot coordinates {(person,2.2) (man,3.4) (bird,0.9) (sit,3.2) (snake,0.0) (woman,1.5) (house,0.4) (dog,0.7) (human,2.0) (table,0.4) (head,0.4) (fish,0.2) (boat,0.0) (hat,0.4) (cat,0.5)};
\addplot+[ybar] plot coordinates {(person,0.1) (man,0.2) (bird,0.0) (sit,1.1) (snake,0.0) (woman,0.5) (house,0.0) (dog,7.3) (human,0.0) (table,0.0) (head,9.0) (fish,0.0) (boat,0.0) (hat,2.1) (cat,13.7)};
\addplot+[ybar] plot coordinates {(person,0.0) (man,0.0) (bird,0.4) (sit,0.1) (snake,0.0) (woman,0.0) (house,56.5) (dog,0.0) (human,0.0) (table,0.6) (head,0.0) (fish,0.0) (boat,10.7) (hat,0.4) (cat,0.0)};
\addplot+[ybar] plot coordinates {(person,0.1) (man,0.0) (bird,0.0) (sit,1.1) (snake,0.2) (woman,0.2) (house,5.9) (dog,4.7) (human,0.0) (table,0.2) (head,0.2) (fish,0.2) (boat,12.4) (hat,0.8) (cat,3.9)};
\addplot+[ybar] plot coordinates {(person,1.2) (man,2.4) (bird,0.3) (sit,0.6) (snake,0.3) (woman,1.5) (house,0.0) (dog,0.4) (human,0.8) (table,0.6) (head,2.1) (fish,0.0) (boat,0.0) (hat,26.5) (cat,0.5)};
\addplot+[ybar] plot coordinates {(person,1.5) (man,2.0) (bird,1.0) (sit,3.1) (snake,0.2) (woman,1.8) (house,0.0) (dog,1.9) (human,0.9) (table,0.2) (head,0.8) (fish,0.0) (boat,0.8) (hat,1.2) (cat,1.2)};
\addplot+[ybar] plot coordinates {(person,0.0) (man,0.0) (bird,7.6) (sit,0.2) (snake,0.0) (woman,0.0) (house,0.0) (dog,0.0) (human,0.0) (table,0.0) (head,3.3) (fish,0.0) (boat,0.0) (hat,1.2) (cat,0.0)};
\addplot+[ybar] plot coordinates {(person,0.9) (man,1.3) (bird,0.4) (sit,1.6) (snake,0.2) (woman,2.5) (house,0.0) (dog,0.2) (human,4.7) (table,0.4) (head,1.1) (fish,0.4) (boat,0.8) (hat,0.4) (cat,0.2)};
\addplot+[ybar] plot coordinates {(person,0.0) (man,0.0) (bird,0.0) (sit,0.0) (snake,0.0) (woman,0.0) (house,0.0) (dog,0.0) (human,0.0) (table,0.0) (head,0.2) (fish,19.6) (boat,0.0) (hat,0.4) (cat,0.0)};
\addplot+[ybar] plot coordinates {(person,1.0) (man,1.3) (bird,0.5) (sit,1.8) (snake,0.3) (woman,2.3) (house,0.4) (dog,0.1) (human,5.0) (table,1.0) (head,1.0) (fish,0.0) (boat,0.0) (hat,0.8) (cat,0.2)};
\addplot+[ybar] plot coordinates {(person,0.1) (man,0.0) (bird,0.1) (sit,0.2) (snake,0.0) (woman,0.0) (house,24.0) (dog,0.2) (human,0.0) (table,0.6) (head,0.0) (fish,0.0) (boat,0.0) (hat,0.0) (cat,0.0)};
\addplot+[ybar] plot coordinates {(person,0.4) (man,0.5) (bird,0.0) (sit,1.8) (snake,0.0) (woman,0.4) (house,1.1) (dog,0.0) (human,1.1) (table,35.1) (head,0.0) (fish,0.0) (boat,0.0) (hat,0.4) (cat,0.0)};
\legend{head, body, leg, arm, tail, neck, wing, face, feet, left, right, base, back, hand, top, shoulder, torso, handle, foot, ear, roof, front, hat, chest, beak, upper, fin, lower, wall, table}
\end{axis}
\end{tikzpicture}
\end{document}