次のグラフがあります:
\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}