I was trying to stack a groupplot, or was it grouping a stacked plot? However I was trying to get something like:
With Excel it didn't seem to be a problem but when I tried adapting it with pgfplots I got something like:
Why is there a seperation after the first three stacked parts?
And how can I label the bars separately but also label thee of them to one site?
Is the groupplot command even the right one to approach to this "problem"?
MWE:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{every axis legend/.append style={at={(0.5,1.025)}, anchor=south,semithick,legend columns=3},width=0.9\textwidth,compat=1.4}
\definecolor{RYB1}{RGB}{102, 194, 165}
\definecolor{RYB2}{RGB}{252, 141, 98}
\definecolor{RYB3}{RGB}{141, 160, 203}
\definecolor{RYB4}{RGB}{231, 138, 195}
\definecolor{RYB5}{RGB}{166, 216, 84}
\definecolor{RYB6}{RGB}{255, 217, 47}
\definecolor{RYB7}{RGB}{229, 196, 148}
\definecolor{RYB8}{RGB}{179,179,179}
\pgfplotscreateplotcyclelist{colorbrewer-RYB}{
{RYB1!50!black,fill=RYB1},
{RYB2!50!black,fill=RYB2},
{RYB3!50!black,fill=RYB3},
{RYB4!50!black,fill=RYB4},
{RYB5!50!black,fill=RYB5},
{RYB6!50!black,fill=RYB6},
{RYB7!50!black,fill=RYB7},
{RYB8!50!black,fill=RYB8},
}
\pgfplotstableread{
Criterion Komp Komp+PV Sorp
abc 7000 7000 12000
def 7500 7500 7500
ghi 7500 7500 7500
jkl 1500 1500 2250
mno 2000 2000 2000
pqrs 0 0 8000
tuv 0 0 11600
wxyz 0 5000 0
}\Rapperswil
\pgfplotstableread{
Criterion Komp Komp+PV Sorp
abc 7000 7000 12900
def 7500 7500 7500
ghi 8000 8000 8000
jkl 1500 1500 2250
mno 2000 2000 2000
pqrs 0 0 8000
tuv 0 0 15440
wxyz 0 6300 0
}\Palermo
\pgfplotstableread{
Criterion Komp Komp+PV Sorp
abc 7000 7000 19000
def 7500 7500 7500
ghi 9000 9000 9000
jkl 1500 1500 2250
mno 2000 2000 2000
pqrs 0 0 8000
tuv 0 0 23000
wxyz 0 8400 0
}\Jeddah
\pgfplotsset{
select row/.style={
x filter/.code={\ifnum\coordindex=#1\else\def\pgfmathresult{}\fi}
}
}
\begin{document}
\begin{figure}[hbt!]
\centering
\begin{tikzpicture}
\begin{groupplot}
[
group style=
{
columns=3,
xlabels at=edge bottom,
ylabels at=edge left,
horizontal sep=0.05\textwidth, group name=plots
},
ybar=0pt,
ybar stacked,
/pgf/bar shift=0pt,scale only axis,
width=0.74\textwidth/3,
height=0.5\textwidth,
ylabel=y-axis, ylabel style={text height=0.02\textwidth,inner ysep=0pt},
enlarge x limits=0.15,
ymin=0,
ymax=80000,
xtick=\empty,
tickpos=left,
scaled y ticks=base 10:-3,
cycle list name=colorbrewer-RYB,
legend columns=-1,
legend style={draw=none, /tikz/every even column/.append style={column sep=5pt}},
legend columns=4,
legend image code/.code={%
\draw[#1] (0cm,-0.1cm) rectangle (0.3cm,0.1cm);
}
]
\nextgroupplot[xlabel=Rapperswil, legend to name=grouplegend,]
\pgfplotsinvokeforeach {0,...,7}{
\addplot table [ x expr=\coordindex, select row=#1, y=Komp] {\Rapperswil};
\addlegendentry {\pgfplotstablegetelem{#1}{Criterion}\of\Rapperswil \pgfplotsretval}
\addplot table [x expr=\coordindex, select row=#1, y=Komp+PV] {\Rapperswil};
\addplot table [x expr=\coordindex, select row=#1, y=Sorp] {\Rapperswil};
}
\nextgroupplot[xlabel=Palermo]
\pgfplotsinvokeforeach {0,...,7}{
\addplot table [ x expr=\coordindex, select row=#1, y=Komp] {\Palermo};
\addplot table [x expr=\coordindex, select row=#1, y=Komp+PV] {\Palermo};
\addplot table [x expr=\coordindex, select row=#1, y=Sorp] {\Palermo};
}
\nextgroupplot[xlabel=Jeddah]
\pgfplotsinvokeforeach {0,...,7}{
\addplot table [x expr=\coordindex, select row=#1, y=Sorp] {\Jeddah};
\addplot table [x expr=\coordindex, select row=#1, y=Komp+PV] {\Jeddah};
\addplot table [x expr=\coordindex, select row=#1, y=Sorp] {\Jeddah};
}
\end{groupplot}
\node at (plots c2r1.south) [inner sep=0pt,anchor=north, yshift=-5ex] {\ref{grouplegend}};
\end{tikzpicture}
\end{figure}
\end{document}
@ zeroth: yes, that's what I had in mind.
I also fitted my example, getting to:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{every axis legend/.append style={at={(0.5,-0.20)},anchor=north,legend columns=-1},width=0.9\textwidth,compat=1.4}
\pgfplotstableread{
Criterion a b c d e f g h
Komp1 7000 7500 7500 1500 2000 0 0 0
Komp+PV1 7000 7500 7500 1500 2000 0 0 5000
Sorp1 12000 7500 7500 2250 2000 8000 11600 0
Komp2 7000 7500 8000 1500 2000 0 0 0
Komp+PV2 7000 7500 8000 1500 2000 0 0 6300
Sorp2 12900 7500 8000 2250 2000 8000 15440 0
Komp3 7000 7500 9000 1500 2000 0 0 0
Komp+PV3 7000 7500 9000 1500 2000 0 0 8400
Sorp3 19000 7500 9000 2250 2000 8000 23000 0
}\datatableA
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}
\begin{axis} [name=plot1,
ybar stacked,
width=10cm,
height=6.2cm,
xtick=data,
xlabel=plot1,]
\addplot table [x expr=\coordindex, y=a] {\datatableA};
\addplot table [x expr=\coordindex, y=b] {\datatableA};
\addplot table [x expr=\coordindex, y=c] {\datatableA};
\addplot table [x expr=\coordindex, y=d] {\datatableA};
\addplot table [x expr=\coordindex, y=e] {\datatableA};
\addplot table [x expr=\coordindex, y=f] {\datatableA};
\addplot table [x expr=\coordindex, y=g] {\datatableA};
\addplot table [x expr=\coordindex, y=h] {\datatableA};
\legend{a,b,c,d,e,f,g,h}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
(sorry for the load of useless commands in the first one)
Now my problem is still the same. Who can I group the first three bars, the second three and the last three ones with one label each?

groupplotsto reproduce it, neither does the packagegermaninterfere with your problem. Also narrow it down to 1 table, you dont need 3. Sorry if it sounds harsh. But this will help you in the long run. Also try to transpose your data. That should make it easier to parse instead ofselect row. – zeroth Dec 15 '11 at 14:12deleteoption under the question. – percusse Dec 15 '11 at 15:03groupplotcommand. Sorry but there are commands I didn't even know they where existing. – Lorzen Dec 15 '11 at 17:00