4

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.

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{fourier}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{tikz,pgfplots}

\begin{document}
\begin{tikzpicture}

\begin{axis}[%
view={0}{90},
width=6cm,
height=4cm,
scale only axis,
xmin=0, xmax=7,
xtick={1,2,3,4,5,6},
xticklabels={Volsted,Sønderholm,Lundby Bakker,Hals Nørreskov,Vester Aslund,Branths},
x tick label style={
    rotate=60,anchor=east},
ymin=0, ymax=12,
ylabel={Antal data},
ymajorgrids,
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) };

\addlegendentry{Boringer};

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

\addlegendentry{Vandværk};

\end{axis}
\end{tikzpicture}%
\end{document}

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

7

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};

\addplot[fill=red,solid,
%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.