여러 개의 막대를 펼치는 YComb

여러 개의 막대를 펼치는 YComb

다음 그래프가 있습니다.

\usepackage{pgfplots}

\begin{tikzpicture}
\begin{axis}[y dir = reverse,
     width=12cm,
     height=10cm, 
     xtick={1,...,6}, 
     ytick={-1,...,-1000},
     ymax=-600,
     xlabel = Number of tasks trained,
     ylabel = Cost
     ]
\addplot+[ycomb, very thick] coordinates {(1, -612) (2, -612)   (3, -611) (4,-611) (5, -611)};
\addplot+[ycomb, very thick] coordinates {          (2, -611.5) (3, -611) (4,-611) (5, -610.5)};
\addplot+[ycomb, very thick] coordinates {                      (3, -612) (4,-611) (5, -610.9)};
\addplot+[ycomb, very thick] coordinates {                                (4,-613) (5, -613)};
\addplot+[ycomb, very thick] coordinates {                                         (5, -612.5)};
\end{axis}
\end{tikzpicture}

문제는 모든 빗의 막대기가 겹쳐져 있다는 것입니다. 막대그래프처럼 퍼뜨릴 수 있는 방법이 있나요?

답변1

반자동, xshift각각에 추가 \addplot:

여기에 이미지 설명을 입력하세요

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[y dir = reverse,
     width=12cm,
     height=10cm, 
     xtick={1,...,6}, 
     ytick={-1,...,-1000},
     ymax=-600,
     xlabel = Number of tasks trained,
     ylabel = Cost
     ]
\addplot+[ycomb, very thick,xshift=-4mm] coordinates {(1, -612) (2, -612)   (3, -611) (4,-611) (5, -611)};
\addplot+[ycomb, very thick,xshift=-2mm] coordinates {          (2, -611.5) (3, -611) (4,-611) (5, -610.5)};
\addplot+[ycomb, very thick] coordinates {                      (3, -612) (4,-611) (5, -610.9)};
\addplot+[ycomb, very thick,xshift=2mm] coordinates {                                (4,-613) (5, -613)};
\addplot+[ycomb, very thick,xshift=4mm] coordinates {                                         (5, -612.5)};
\end{axis}
\end{tikzpicture}
\end{document}

관련 정보