7

I am producing a stacked bar chart or two series with error bars that describe the uncertainty in their sum. I apply the error bars as properties of the second plot.

If I use \pgfplotset{compat=1.9}, then points where the second plot value is zero (no rectangle) don't get error bars, even through the error amount is non-zero!

Not surprisingly, the manual says that pgfplots 1.9 comes with "suppression of empty increments in stacked bar plots" that is enabled with compat=1.9 or higher.

Sure seems like a bug. Am I doing something wrong?

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

% Uncomment to make second error bar disappear
\pgfplotsset{compat=1.9}

\begin{filecontents*}{dataTable.txt}
xpos firsty secondy yerrdown yerrup
1           0         1                0.1               0.1
2           1         0               1.5               0.4
3           2         1               0.3               0.4
\end{filecontents*}

\begin{document}

\pgfplotstableread{dataTable.txt}\dataTable
\begin{tikzpicture}
\pgfplotsset{set layers}
\begin{axis}[
ybar stacked
    ]
% Layers needed to get error bars on top of lower blue rectangle
\addplot table[on layer=axis grid,x=xpos, y=firsty]{\dataTable};
\addplot plot[on layer=axis lines,error bars/.cd, y dir=both, y explicit] table[x=xpos, y=secondy, y error minus=yerrdown, y error plus=yerrup]{\dataTable};

\end{axis}

\end{tikzpicture}


\end{document}

With compat1.9: With compat=1.9 Without compat1.9: Without compat=1.9

1
  • 1
    I have fixed this bug in the developer version of pgfplots, will become available in the version after pgfplots 1.10 Mar 16, 2014 at 16:15

1 Answer 1

5

You can use compat/bar nodes=1.8 to make the error bar appear when using compat=1.9.

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\pgfplotsset{
    compat=1.9,
    compat/bar nodes=1.8
}


\begin{filecontents*}{dataTable.txt}
xpos firsty secondy yerrdown yerrup
1           0         1                0.1               0.1
2           1         0               1.5               0.4
3           2         1               0.3               0.4
\end{filecontents*}

\begin{document}

\pgfplotstableread{dataTable.txt}\dataTable
\begin{tikzpicture}
\pgfplotsset{set layers}
\begin{axis}[
ybar stacked
    ]
% Layers needed to get error bars on top of lower blue rectangle
\addplot table[on layer=axis grid,x=xpos, y=firsty]{\dataTable};
\addplot plot[on layer=axis lines,error bars/.cd, y dir=both, y explicit] table[x=xpos, y=secondy, y error minus=yerrdown, y error plus=yerrup]{\dataTable};

\end{axis}

\end{tikzpicture}


\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .