Ich habe folgende Grafik:
\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}
Das Problem ist, dass sich die Stäbe aller Waben überlappen. Gibt es eine Möglichkeit, sie wie in einem Balkendiagramm zu verteilen?
Antwort1
Halbautomatisch, fügen Sie xshift
jedem ein hinzu \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}