pgfplot ybar バーオフセットを削除

pgfplot ybar バーオフセットを削除

私はpgfplotを持っています

  \begin{tikzpicture}[baseline]
\begin{axis}[
  ymajorgrids,      
  legend style={at={(0.5,1.05)}, anchor=south,legend columns=3},
  ybar,
  bar width=0.5cm,
  ylabel=Ratio vs. original,
  xtick={1, 2, 3, 4},
  ymin=0,
  width=\textwidth,
  height=7cm
  ]
  \addplot+ [DarkRed] (1, 0.9166278045494584);
  \addplot+ [BlueViolet] (2, 0.9745841753458725);
  \addplot+ [CadetBlue] (3, 0.7903000155448467);
  \addplot+ [Blue] (4,0.9375097155293016);      
\end{axis}
\end{tikzpicture}    

この出力が得られる ここに画像の説明を入力してください

x 軸のティックからバーのオフセットを削除するにはどうすればよいですか?

答え1

あなたが探しているのは次のものだと思います:

ここに画像の説明を入力してください

以下の MWE では、コード フラグメントと比較した変更は次のようにマークされます% <---

\documentclass[a4paper,12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz,xcolor}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}[baseline]
\begin{axis}[
  ymajorgrids=true,
  %legend style={at={(0.5,1.05)}, anchor=south,legend columns=3}, % it is not used
  ybar=2mm,                     % <----
  bar width=8mm,                % <----
  bar shift=0mm,                % <---- remove offset
  ylabel={Ratio vs. original},
  enlarge x limits=0.2,
  width=0.5\textwidth,          % <----
  height=7cm
  ]
\addplot + [red]      coordinates {(1, 0.9166278045494584)};
\addplot + [green]    coordinates {(2, 0.9745841753458725)};
\addplot+ [magenta]   coordinates {(3, 0.7903000155448467)};
\addplot+ [yellow]    coordinates {(4,0.9375097155293016)};
\end{axis}
\end{tikzpicture}
\end{document}

関連情報