# Stacked ybar with unordered coordinate input

I'm creating a stacked ybar plot from some data, which causes the input coordinates to be not sorted. This causes a gap between some of the bars. Is this a bug? Shouldn't the stacked ybar plot know all the heights? If not, is there a simple way to fix this? Surely i fix this in my program (i do some data processing beforehand), but i feel there should be an easy solution.

Here is a sample document:

\documentclass{scrartcl}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}
[
ybar stacked,
ymin = 0,
enlarge x limits
]
(1, 1)
(2, 2)
(3, 3)
};
(1, 1)
(3, 3) % 'wrong' order
(2, 2)
};
\end{axis}
\end{tikzpicture}

\end{document}


This produces:

What i want is the following, which is produced by changing the 'wrongly' ordered lines in the second \addplot command.

This is not a real answer, but a long comment ...

In the PGFPlots manual (v1.15) section 4.5.9 on page 94 at the end of the description of the key stack plots you can find the following text:

The current implementation for stack plots does not interpolate missing coordinates. That means stacking will fail if the plots have different grids.

Together with the slightly modified example you have given which you can find below, it should be pretty much self-explanatory how the current implementation is working. Thus I think you don't have another choice than sorting your entries first before stating the coordinates.

But you mentioned something about "your program" so I think you create your data externally. Then I would consider writing the data to an external file and use this data by \addplot table. (I don't present an example here because you can find plenty of them on this site.)

% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
% used to center the nodes near coords' in stacked plots
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
ymin=0,
enlarge x limits,
nodes near coords,
point meta=\coordindex,
]
(1, 1)
(5, 2) % 'wrong' order
(3, 3)
};
`