YComb espalhando vários palitos

YComb espalhando vários palitos

Tenho o seguinte gráfico:

\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}

O problema é que os palitos de todos os pentes ficam sobrepostos. Existe uma maneira de distribuí-los como em um gráfico de barras?

Responder1

Semiautomático, adicione um xshifta cada \addplot:

insira a descrição da imagem aqui

\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}

informação relacionada