
내 플롯에 막대 레이블로 포함할 테이블에 일부 메타데이터가 있습니다. 나는 이 라벨이 타이밍(예: 15.8초)임을 지정하고 싶습니다. 라벨에 '초' 텍스트를 추가하는 방법을 모르겠습니다.
MWE는 다음과 같습니다.
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\pgfplotstableread{
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11
1 94 0 5 6 6 15.8 2.0 37.5 42.3 42.3
2 93 0 5 7 7 16.1 2.1 30.7 43.1 42.5
3 97 0 11 13 13 18.6 1.9 39.0 51.6 51.9
4 87 34 93 93 93 34.6 34.6 93.8 93.3 92.4
}\inittable
\begin{tikzpicture}
\begin{axis}[
ybar, bar width=10pt,
width=6in, height=2.5in,
ymin=-5, ymax=120, ytick={0,50,100},
xmin=0, xmax=5, xtick={1,2,3,4},
point meta=explicit,
nodes near coords, every node near coord/.append style={
anchor= west, rotate=90, font=\footnotesize},
tick label style={font=\footnotesize},
]
\addplot table[x=c1,y=c2,meta=c7] {\inittable};
\addplot table[x=c1,y=c3,meta=c8] {\inittable};
\addplot table[x=c1,y=c4,meta=c9] {\inittable};
\addplot table[x=c1,y=c5,meta=c10] {\inittable};
\addplot table[x=c1,y=c6,meta=c11] {\inittable};
\end{axis}
\end{tikzpicture}
\end{document}
답변1
기본값은 다음과 node near coords
같습니다 \pgfmathprintnumber\pgfplotspointmeta
. 단순히 포인트 메타 값을 숫자로 인쇄합니다. 하지만 Ti 내에서는 그렇게 됩니다.케이Z 노드에 텍스트를 추가하기만 하면 노드에도 들어갈 수 있습니다. 그러므로 당신이 하고 싶은 일은 nodes near coords={\pgfmathprintnumber{\pgfplotspointmeta}~secs}
. 그러나 이렇게 하면 "초" 중 일부가 위쪽 축 경계 위로 확장되는 것을 볼 수 있으므로 enlarge y limits={upper, abs value=20}
. 이 두 가지 변경 사항은 다음과 같은 결과를 제공합니다.
그러나 개인적으로 나는 두 번째 기호를 다음과 같이 siunitx
사용 하고 싶습니다 .s
nodes near coords={%
${\pgfmathprintnumber\pgfplotspointmeta} \, \si{\second}$%
}
코드를 약간 단순화한 xtick distance=1
및 에 주목하세요 . 또한 .NET의 향후 버전에서도 출력이 동일하게 유지되는지 확인하는 데 ytick distance=50
사용합니다 .\pgfplotsset{compat=1.16}
pfgplots
\documentclass[border=5pt]{standalone}
\usepackage{siunitx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\pgfplotstableread{
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11
1 94 0 5 6 6 15.8 2.0 37.5 42.3 42.3
2 93 0 5 7 7 16.1 2.1 30.7 43.1 42.5
3 97 0 11 13 13 18.6 1.9 39.0 51.6 51.9
4 87 34 93 93 93 34.6 34.6 93.8 93.3 92.4
}\inittable
\begin{tikzpicture}
\begin{axis}[
ybar, bar width=10pt,
width=6in, height=2.5in,
ymin=-5, ymax=120, ytick distance=50,
xmin=0, xmax=5, xtick distance=1,
point meta=explicit,
enlarge y limits={upper, abs value=5},
nodes near coords={$\pgfmathprintnumber{\pgfplotspointmeta} \, \si{\second}$},
every node near coord/.append style={
anchor=west, rotate=90, font=\footnotesize,
},
tick label style={font=\footnotesize},
]
\addplot table[x=c1,y=c2,meta=c7] {\inittable};
\addplot table[x=c1,y=c3,meta=c8] {\inittable};
\addplot table[x=c1,y=c4,meta=c9] {\inittable};
\addplot table[x=c1,y=c5,meta=c10] {\inittable};
\addplot table[x=c1,y=c6,meta=c11] {\inittable};
\end{axis}
\end{tikzpicture}
\end{document}