이것은 현재 다음 히스토그램을 생성해야 하는 코드입니다.
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
ymin=0,
xlabel={Classes},
ylabel={Frequency},
width=10cm,
height=6cm,
xtick=data,
xticklabels={A, B, C, D}, % Add more labels as needed
enlarge x limits=0.15,
nodes near coords, % Add labels above each bar
nodes near coords align={vertical},
nodes near coords style={font=\tiny},
]
]
\addplot[fill=blue!30] coordinates {(1, 15) (2, 12) (3, 8) (4, 10) };
\addplot[fill=green!30] coordinates {(1, 14) (2, 11) (3, 13) (4, 9) };
\end{axis}
\end{tikzpicture}
\end{document}
답변1
좋습니다. 여기에 한 가지 방법이 있습니다. 열쇠:
point meta=explicit symbolic
각각에 추가\addplot
- 각 좌표 뒤에 원하는 값/텍스트를 추가하십시오.
[ ]
pgfplots 매뉴얼, Ch. 4, p. 자세한 내용은 114, 버전 1.18.1을 참조하세요.
%\documentclass{article}
\documentclass[10pt,border=3mm,tikz]{standalone} % nicer for development
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
ymin=0,
xlabel={Classes},
ylabel={Frequency},
width=10cm,
height=6cm,
xtick=data,
xticklabels={A, B, C, D}, % Add more labels as needed
enlarge x limits=0.15,
nodes near coords, % Add labels above each bar
nodes near coords align={vertical},
nodes near coords style={font=\tiny},
]
]
\addplot[fill=blue!30,
point meta=explicit symbolic
] coordinates {
(1, 15) [1]
(2, 12) [2]
(3, 8) [4]
(4, 10) [3]
};
\addplot[fill=green!30,
point meta=explicit symbolic
] coordinates {
(1, 14) [1]
(2, 11) [3]
(3, 13) [2]
(4, 9) [4]
};
\end{axis}
\end{tikzpicture}
\end{document}