TiKZ の棒グラフにおけるエラーバーの位置

TiKZ の棒グラフにおけるエラーバーの位置

助けてください! 各バーの上にあるエラー バーの位置を正しく取得できないようです。また、何らかの理由で凡例の位置もずれているようです。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}


\colorlet{negro}{black}
\colorlet{gris}{black!70}
\colorlet{rojo}{red!70!black}
\colorlet{rojol}{red}

\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis}[xscale = 1.45,
 scaled ticks=false, tick label style={/pgf/number format/fixed},
 xbar, 
 xmin = 1, xmax = 7,
 ymin = -0.1, ymax = 0.25,
 ytick = {-0.10, -0.05, 0.00, 0.05, 0.10, 0.15, 0.20, 0.25},
 ylabel = Efecto en Pr(Voto),
 xticklabels = {Género, Ruralidad, Pareja, Riqueza, Id. Part., Ideología},
 ybar interval=0.5,
 bar width=3pt,
 grid = major,
 legend style={cells={anchor=center, fill}, nodes={inner sep=1,below=-1.1ex}},area legend
 ]
  \draw [orange, very thick] (axis cs:0,0) -- (axis cs:7,0);
  \addplot[color = negro, fill = negro, 
  error bars/.cd,
  y dir=both,
  y explicit,
  error bar style={line width=1.5pt, gris},
  error mark options = {
  rotate = 90, 
  line width=1.5pt, 
  mark size = 3pt, 
  gris}
  ]
    coordinates{(1,-0.011097) +- (0,0.0380683)
                (2,0.0393206) +- (0,0.050079)
                (3,-0.019293) +- (0,0.0389844)
                (4,0.0078975) +- (0,0.0097073)
                (5,0.0234860) +- (0,0.0481639)
                (6,0.0336061) +- (0,0.0462397)
                (7,0)};
  \addplot [color = rojo, fill = rojo,
   error bars/.cd,
  y dir=both,
  y explicit,
  error bar style={line width=1.5pt, rojol},
  error mark options = {
  rotate = 90, 
  line width=1.5pt, 
  mark size = 3pt, 
  rojol}
  ]
    coordinates{(1,-0.025222) +- (0,0.055507)
                (2,0.1337832) +- (0,0.0720284)
                (3,0.0517127) +- (0,0.0574637)
                (4,0.0053732) +- (0,0.0129013)
                (5,0.0741801) +- (0,0.0731692)
                (6,0.0181164) +- (0,0.0709312)
                (7,0)};
 \addlegendentry{2008}
 \addlegendentry{2012}
 \end{axis}
\end{tikzpicture}
\end{center}

\end{document}

答え1

最適な方法はまだ見つかっていませんが、この例ではうまく機能しています。改善点のリストは次のとおりです。

  1. xscale = 1.45に変更しましたwidth=12cm, height=6cm
  2. xshift(2回)の選択肢の中から推測した寸法で追加しましたerror bar style
  3. パッケージをコメント アウトし、発音区別文字を TeX 文字列にデコードしました (2 回)。これで、たとえば など、inputencすべての主要な形式でファイルを実行できるようになりました。latexlualatex sample.tex

私の努力の結果と PDF ファイルのプレビューを同封します。

%! {pdf|lua|xe|}latex sample.tex
\documentclass{standalone}
%\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\colorlet{negro}{black}
\colorlet{gris}{black!70}
\colorlet{rojo}{red!70!black}
\colorlet{rojol}{red}

\begin{document}
\begin{tikzpicture}
\begin{axis}[%xscale = 1.45,
width=12cm, height=6cm,
 scaled ticks=false, tick label style={/pgf/number format/fixed},
 xbar, 
 xmin = 1, xmax = 7,
 ymin = -0.1, ymax = 0.25,
 ytick = {-0.10, -0.05, 0.00, 0.05, 0.10, 0.15, 0.20, 0.25},
 ylabel = Efecto en Pr(Voto),
 xticklabels = {G\'enero, Ruralidad, Pareja, Riqueza, Id. Part., Ideolog\'ia},
 ybar interval=0.5,
 bar width=3pt,
 grid = major,
 legend style={cells={anchor=center, fill}, nodes={inner sep=1, below=-1.1ex}}, area legend
 ]
  \draw [orange, very thick] (axis cs:0,0) -- (axis cs:7,0);
  \addplot[color = negro, fill = negro, 
  error bars/.cd,
  y dir=both,
  y explicit,
  error bar style={line width=1.5pt, gris, xshift=4.5mm},
  error mark options = {
  rotate = 90, 
  line width=1.5pt, 
  mark size = 3pt, 
  gris,
  }
  ]
    coordinates{(1,-0.011097) +- (0,0.0380683)
                (2,0.0393206) +- (0,0.050079)
                (3,-0.019293) +- (0,0.0389844)
                (4,0.0078975) +- (0,0.0097073)
                (5,0.0234860) +- (0,0.0481639)
                (6,0.0336061) +- (0,0.0462397)
                (7,0)};
  \addplot [color = rojo, fill = rojo,
   error bars/.cd,
  y dir=both,
  y explicit,
  error bar style={line width=1.5pt, rojol, xshift=13mm},
  error mark options = {
  rotate = 90, 
  line width=1.5pt, 
  mark size = 3pt, 
  rojol}
  ]
    coordinates{(1,-0.025222) +- (0,0.055507)
                (2,0.1337832) +- (0,0.0720284)
                (3,0.0517127) +- (0,0.0574637)
                (4,0.0053732) +- (0,0.0129013)
                (5,0.0741801) +- (0,0.0731692)
                (6,0.0181164) +- (0,0.0709312)
                (7,0)};
 \addlegendentry{2008}
 \addlegendentry{2012}
 \end{axis}
\end{tikzpicture}
\end{document}

ムウェ

関連情報