# pgfplots: problem with stacked histograms

I want to plot data for a node that has several inflows and one outflow, using stacked histograms. I want the plot to look like this:

First, I have tried stacked histograms (ybar stacked, see the code below), where I draw the negative series first and then add it to the first series. Unfortunately, it does work, even if it works with lines and area style:

Then I tried using separate axis environment for positive and negative values, as suggested in this answer. The problem is that the stacked histogram breaks down once I change ymin - is this a bug?

My question is: is there some way to make this work, other than the hack I used to create the first figure? (There, I am stacking the columns manually - OK for two inflows, but very impractical for five or more - though I guess it could be scripted..)

PS: I realized that the figure has to work also black-and-white, so I need to use patterns. This made my manual stacking impossible, since the patterns have transparent backgrounds - until I found this answer which showed how to combine patterns and fill, so I could get this:

Here is the full code for all the figures:

\documentclass{article}
\usepackage{tikz,pgfplots,pgfplotstable}
\usetikzlibrary{patterns}
\pagestyle{empty}

\begin{document}

t   in1 in2 out
1   5   2   7
2   3   0   6
3   1   2   5
4   0   4   4
5   1   6   5
6   4   4   6
7   6   2   7
}\flowData

\begin{tikzpicture}
\begin{axis}[small,title=This is what I want,ybar,bar shift=0pt,]
\end{axis}
\end{tikzpicture}
\
\begin{tikzpicture}
\begin{axis}[small,title=First attempt using ybar stacked,ybar stacked]
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[small,title=Check: using lines is OK,stack plots=y]
\end{axis}
\end{tikzpicture}
\
\begin{tikzpicture}
\begin{axis}[small,title=Check: using area style is OK,stack plots=y,area style]
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[small,title=Test: only inflows,ybar stacked]
\pgfplotsset{cycle list shift=1}
\end{axis}
\end{tikzpicture}
\
\begin{tikzpicture}
\begin{axis}[small,title={Test: only inflows with ymin=-8},ybar stacked,ymin=-8]
\pgfplotsset{cycle list shift=1}
\end{axis}
\end{tikzpicture}

\pgfplotsset{ % redefine the cycle list used for bar- and area plots
/pgfplots/bar cycle list/.style={/pgfplots/cycle list={%
{blue!80!black,fill=white,postaction={pattern=north east lines,pattern color=blue!75!white}},%
{green!75!black,fill=white,postaction={pattern=crosshatch dots,pattern color=green!90!white}},%
{red!80!black,fill=white,postaction={pattern=crosshatch,pattern color=red!67!white}}}
}
}
\begin{tikzpicture}
\begin{axis}[small,title={This is what I \emph{really} want},ybar,bar shift=0pt,]