# Pgfplots: Stacked Bar Plot distorted if second plot is added

I am trying to create a stacked bar plot in oder to compare two sets of data. If I add only one plot (in this example just uncomment the other plot) everything looks perfect, but if i try to activate both at the same time, curious things happen. Can sombody please help? Please excuse the poor layout in the example, in reality I read from a data file with more entries and the plot looks nicer. Working example:

\documentclass[a4paper,12pt,oneside]{report}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[xbar stacked,
symbolic y coords={DP,DPn},
bar width=7pt,
y=0.8cm]

\end{axis}
\end{tikzpicture}

\end{document}


Picture of the whole plot (the working example only includes the first entry but shows the same issue).

• Did my answer answer your question? If yes, please consider upvoting (by clicking on the arrows next to the score) it and/or marking it as the accepted answer (by clicking on the checkmark ✓). If not, please edit your question again and state what you are missing. – Stefan Pinnow Apr 24 '18 at 4:33

You simply use it wrong. Each \addplot command should contain only one coordinate per ytick and they get stacked by multiple of such \addplot commands. So a simple rearrangement of your coordinates to different \addplot commands solves your problem.

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xbar stacked,
symbolic y coords={DP,DPn},
ytick=data,
]