
다음 라텍스 코드를 따라야 합니다.
\usepackage{tikz}
\usepackage{pgfopts}
\usepackage{pgfplotstable}
\begin{document}
\begin{tikzpicture}[scale=1]
\begin{axis}[minor tick num=1,
scale only axis,
height=5cm,
width=\textwidth*0.8,
xlabel=\textnumero contestants,
ylabel style={overlay},
yticklabel style={overlay},
xticklabel style={overlay},
ylabel=,
ybar,
ymin=0,
legend style={at={(0, 1)},anchor=west},
legend entries={\textnumero matches, \textnumero rounds}]
\addplot [draw opacity=0,fill=yellow!50] table [x index=0, y index=1] {charts/merge_no_matches_rounds.csv};
\addplot [draw opacity=0,fill=green] table [x index=0, y index=2] {charts/merge_no_matches_rounds.csv};
\end{axis}
\end{tikzpicture}
\end{document}
결과는 다음과 같습니다.
데이터 파일은 다음과 같습니다.
2 1 1
4 4 3
6 9 6
8 11 6
10 17 9
12 21 9
14 23 9
. . .
92 181 18
94 185 18
96 189 18
98 191 18
100 193 18
노란색 영역은 괜찮아 보이지만 녹색 영역에는 이상한 오프셋이 있습니다. 이 문제를 어떻게 해결할 수 있나요?
답변1
여기서는 히스토그램을 사용하면 안 됩니다. 노란색 데이터 중 하나의 값이 해당 녹색 값보다 낮아지면 플롯 아이디어가 더 이상 실용적이지 않습니다. 혼합이 아닌 실제 바 또는 실제 스태킹을 사용해야 합니다. (실제로는 단순한 곡선이 가장 좋습니다)
그래도 나는 당신에게 해결책을 제공합니다:
% arara: pdflatex
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepgfplotslibrary{fillbetween}
\usepackage{textcomp}
\usepackage{filecontents}
\begin{filecontents*}{charts/merge_no_matches_rounds.csv}
2 1 1
4 4 3
6 9 6
8 11 6
10 17 9
12 21 9
14 23 9
92 181 18
94 185 18
96 189 18
98 191 18
100 193 18
\end{filecontents*}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[%
,minor tick num=1
,scale only axis
,height=5cm
,width=\textwidth*0.8
,xlabel=\textnumero{} contestants
,yticklabel style={overlay}
,xticklabel style={overlay}
,ymin=0
,legend cell align=left
,legend style={at={(0, 1)},anchor=west}]
\addplot [draw opacity=0,name path=f,area legend,fill=yellow!50] table [x index=0, y index=1] {charts/merge_no_matches_rounds.csv};
\addplot [draw opacity=0,name path=g,area legend,fill=green] table [x index=0, y index=2] {charts/merge_no_matches_rounds.csv};
\path[name path=axis] (axis cs:0,0.2) -- (axis cs:100,0.2);
\addplot [draw opacity=0,color=yellow!50,fill=yellow!50]
fill between[of=f and axis];
\addlegendentry{\textnumero{} matches}
\addplot [draw opacity=0,color=green,fill=green]
fill between[of=g and axis];
\addlegendentry{\textnumero{} rounds}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}