I got a problem with my pgfcodes. I get this error:

! Package pgfplots Error: Sorry, pgfplots expects stacked plots to have exactly the same number of coordinates. Unfortunately, I encountered at plot with DIFF ERENT NUMBERS OF COORDINATES. Please verify that 1. no point has been dropped b y coordinate filters (for example log(0) or so) and 2. all plots have the same number of coordinates..

I can't find out what I'm doing wrong. The code is generated from matlab2tikz and it is a stacked barplot.



scale only axis,
xmin=0, xmax=7,
xticklabels={Volsted,Sønderholm,Lundby Bakker,Hals Nørreskov,Vester Aslund,Branths},
x tick label style={
ymin=0, ymax=12,
ylabel={Antal data},
title={Antal data},
axis lines*=left,
legend style={align=left},
ybar stacked,
bar width=0.342857142857143cm,
area legend]
\addplot[fill=green,draw=black] plot coordinates{ (1,8) (2,5) (3,7) (4,2) (5,0) (6,7) };


\addplot [
forget plot
\addplot[fill=blue,draw=black] plot coordinates{ (1,3) (2,3) (3,3) (4,0) (5,3) (6,3) };



My document is in danish writing and I am a danish myself, so don't bother if you can't understand :)


You can not use only two points (in your case (0,0) (7,0)) since you are using six bars. For example, I'm using here

\addplot[fill=green,draw=black] plot coordinates{ (1,8) (2,5) (3,7) (4,2) (5,3) (6,7) };
\addlegendentry{Green color};

%forget plot
coordinates{ (1,2) (2,2)  (3,5) (4,1) (5,3) (6,4) };
\addlegendentry{Red color};

\addplot[fill=cyan,draw=black] plot coordinates{ (1,3) (2,3) (3,3) (4,0) (5,3) (6,3) };
\addlegendentry{Cyan color};

and the result is

enter image description here

  • So instead of (0,0) (7,0) I can add these?: (1,2) (2,2) (3,5) (4,1) (5,3) (6,4) ?
    – aloevgaard
    Oct 28 '13 at 14:26
  • The first coordinate refers to the number of bar, that is, (1,2) means that the first bar has height two. And so on. Those values for second coordinate was just to exemplify.
    – Sigur
    Oct 28 '13 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.