Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've read both this Plot alignment using groupplot in pgfplots and this Using pgfplots, add vertical/horizontal spacing between plots? and neither helped me. I'm trying to align horizontally plots in my pgfplot. Here's the code:

\documentclass{article} 
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{patterns}
\newcommand{\benchmark}{\textsf}
\usepgfplotslibrary{groupplots}
\usepackage{tikz}
\begin{document}

\pgfplotstableread{
1   north   south
a   0.001280    16.766500
b   34.134100   54.436300
c   33.406100   54.002900
d   16.179600   47.049400
e   35.584100   49.673600
f   60.769900   33.283100
g   34.033700   53.008600
h   34.572000   50.658500
i   30.651700   56.141900
j   26.295600   26.996700
t   40.039200   35.579900
}\africa

\pgfplotstableread{
2   north    south
a   55.417400   44.540100
b   36.533900   55.810100
c   22.362600   76.587400
d   92.259800   5.152260
e   50.970100   48.105000
f   51.881900   38.708600
g   89.573900   9.147390
h       32.110000   54.245900
i   40.787100   52.661700
j   17.979700   70.260900
x   27.225800   51.346500
}\europe

\pgfplotstableread{
3   north   south
a   61.048100   38.920000
b   41.228300   33.868400
c   25.102600   67.448500
d   52.942500   46.574600
e   59.920200   40.050800
f   49.975200   41.445900
g   58.469200   41.373000
h   26.563400   48.328000
i   23.641900   54.914700
j   58.528300   41.439700
y   36.577600   42.945300
}\australia

\pgfplotstableread{
4   north   south
a   16.671400   66.676200
b   15.373900   69.806300
c   26.460400   60.564900
d   20.170900   75.096100
e   44.496400   54.911900
f   40.571300   48.995000
g   28.882700   43.026900
h   39.763300   32.143500
i   33.911500   58.649300
j   22.915300   68.710700
z   26.765400   62.534000
}\latin

\begin{figure}
\begin{minipage}{.45\columnwidth}
\centering
\begin{tikzpicture}[scale = .5, transform shape]    
\begin{groupplot}[
  group style={
   rows=2,
   columns=2,
   horizontal sep=0pt,
   vertical sep=60pt,
   yticklabels at=edge left
 },
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,t},
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
  ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
 ]
  \nextgroupplot[title=1,ytick pos=both,xtick pos=left,cycle list={    { fill=olive},                {fill=lightgray,pattern=north east lines} }
]
  \addplot table [x index=0, y index =1] {\africa};
  \addplot table [x index=0, y index =2] {\africa};
\end{groupplot}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.45\columnwidth}
\centering
\begin{tikzpicture}[scale = .5, transform shape]
\begin{groupplot}[
  group style={
   rows=2,
   columns=2,
   horizontal sep=0pt,
   vertical sep=60pt,
   yticklabels at=edge left
 },
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,x},
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
  ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
 ]
\nextgroupplot[title=2,ytick pos=both,xtick pos=left,cycle list={    { fill=olive},        {fill=lightgray,pattern=north east lines}}]
  \addplot table [x index=0, y index =1] {\europe};
  \addplot table [x index=0, y index =2] {\europe};
 \end{groupplot}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.45\columnwidth}
\centering
\begin{tikzpicture}[scale = .5, transform shape]
\begin{groupplot}[
  group style={
   rows=2,
   columns=2,
   horizontal sep=0pt,
   vertical sep=60pt,
   yticklabels at=edge left
 },
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,y},
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
  ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
 ]
\nextgroupplot[title=3,ytick pos=both,xtick pos=left,cycle list={    { fill=olive},        {fill=lightgray,pattern=north east lines}}]
  \addplot table [x index=0, y index =1] {\australia};
  \addplot table [x index=0, y index =2] {\australia};
 \end{groupplot}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.45\columnwidth}
\centering
\begin{tikzpicture}[scale = .5, transform shape]
\begin{groupplot}[
  group style={
   rows=2,
   columns=2,
   horizontal sep=0pt,
   vertical sep=60pt,
   yticklabels at=edge left
 },
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,z},
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
     ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
 ]
\nextgroupplot[title=4,ytick pos=both,xtick pos=left,cycle list={    { fill=olive},    {fill=lightgray,pattern=north east lines}}]
  \addplot table [x index=0, y index =1] {\latin};
  \addplot table [x index=0, y index =2] {\latin};

\end{groupplot}
\end{tikzpicture}
\end{minipage}
\end{figure}
\end{document}

it produces the following plot: enter image description here

I want to align plot 4. However, I'm not even sure which one (plot 2 or plot 4) is not correctly aligned.

I've also tried avoiding groupplots:

\documentclass{article} 
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{patterns}
\newcommand{\benchmark}{\textsf}
\usepgfplotslibrary{groupplots}
\usepackage{tikz}

\begin{document}

\pgfplotstableread{
1   north   south
a   0.001280    16.766500
b   34.134100   54.436300
c   33.406100   54.002900
d   16.179600   47.049400
e   35.584100   49.673600
f   60.769900   33.283100
g   34.033700   53.008600
h   34.572000   50.658500
i   30.651700   56.141900
j   26.295600   26.996700
t   40.039200   35.579900
}\africa

\pgfplotstableread{
2   north    south
a   55.417400   44.540100
b   36.533900   55.810100
c   22.362600   76.587400
d   92.259800   5.152260
e   50.970100   48.105000
f   51.881900   38.708600
g   89.573900   9.147390
h   32.110000   54.245900
i   40.787100   52.661700
j   17.979700   70.260900
x   27.225800   51.346500
}\europe

\pgfplotstableread{
3   north   south
a   61.048100   38.920000
b   41.228300   33.868400
c   25.102600   67.448500
d   52.942500   46.574600
e   59.920200   40.050800
f   49.975200   41.445900
g   58.469200   41.373000
h   26.563400   48.328000
i   23.641900   54.914700
j   58.528300   41.439700
y   36.577600   42.945300
}\australia

\pgfplotstableread{
4   north   south
a   16.671400   66.676200
b   15.373900   69.806300
c   26.460400   60.564900
d   20.170900   75.096100
e   44.496400   54.911900
f   40.571300   48.995000
g   28.882700   43.026900
h   39.763300   32.143500
i   33.911500   58.649300
j   22.915300   68.710700
z   26.765400   62.534000
}\latin


\begin{figure}
\begin{minipage}{.45\columnwidth}
\centering
\begin{tikzpicture}[scale = .5, transform shape]
\begin{axis}[
scale only axis,
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,t},
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
  ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
  cycle list = {
   { fill = gray },
   { fill = darkgray,pattern=north east lines },
 }, title={1},
 ]

  \addplot table [x index=0, y index =1] {\africa};
  \addplot table [, x index=0, y index =2] {\africa};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.45\columnwidth}
\centering
\begin{tikzpicture}[scale = .5, transform shape]
\begin{axis}[
scale only axis,
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,x},
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
  ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
  cycle list = {
   { fill = gray },
   { fill = darkgray,pattern=north east lines },
 }, title={2},
 ]

  \addplot table [x index=0, y index =1,fill=olive] {\europe};
  \addplot table [, x index=0, y index =2,fill=lightgray] {\europe};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.45\columnwidth}
\centering
\begin{tikzpicture}[scale = .5, transform shape]
\begin{axis}[
scale only axis,
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,y},
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
  ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
  cycle list = {
   { fill = gray },
   { fill = darkgray,pattern=north east lines },
 }, title={3},
 ]

  \addplot table [x index=0, y index =1,fill=olive] {\australia};
  \addplot table [, x index=0, y index =2,fill=lightgray] {\australia};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.45\columnwidth}
\centering
\begin{tikzpicture}[scale = .5, transform shape]
\begin{axis}[
scale only axis,
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,z},
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
  ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
  cycle list = {
   { fill = gray },
   { fill = darkgray,pattern=north east lines },
 }, title={4},
 ]

  \addplot table [x index=0, y index =1,fill=olive] {\latin};
  \addplot table [, x index=0, y index =2,fill=lightgray] {\latin};
\end{axis}
\end{tikzpicture}
\end{minipage}
\end{figure}
\end{document}

It results in a similar plot: enter image description here

How can I resolve it? Preferably for the groupplots solution, since I have tons of them and don't want to change it.

share|improve this question
add comment

3 Answers

up vote 6 down vote accepted

I think you're using groupplots not exactly as intended. Using the groupplot options you specified, and changing the code a little:

enter image description here

The point is, you have just one groupplot environment, and within that you start a new axis with \nextgroupplot.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{patterns}
\newcommand{\benchmark}{\textsf}
\usepgfplotslibrary{groupplots}
\usepackage{tikz}
\begin{document}

\pgfplotstableread{
1   north   south
a   0.001280    16.766500
b   34.134100   54.436300
c   33.406100   54.002900
d   16.179600   47.049400
e   35.584100   49.673600
f   60.769900   33.283100
g   34.033700   53.008600
h   34.572000   50.658500
i   30.651700   56.141900
j   26.295600   26.996700
t   40.039200   35.579900
}\africa

\pgfplotstableread{
2   north    south
a   55.417400   44.540100
b   36.533900   55.810100
c   22.362600   76.587400
d   92.259800   5.152260
e   50.970100   48.105000
f   51.881900   38.708600
g   89.573900   9.147390
h       32.110000   54.245900
i   40.787100   52.661700
j   17.979700   70.260900
x   27.225800   51.346500
}\europe

\pgfplotstableread{
3   north   south
a   61.048100   38.920000
b   41.228300   33.868400
c   25.102600   67.448500
d   52.942500   46.574600
e   59.920200   40.050800
f   49.975200   41.445900
g   58.469200   41.373000
h   26.563400   48.328000
i   23.641900   54.914700
j   58.528300   41.439700
y   36.577600   42.945300
}\australia

\pgfplotstableread{
4   north   south
a   16.671400   66.676200
b   15.373900   69.806300
c   26.460400   60.564900
d   20.170900   75.096100
e   44.496400   54.911900
f   40.571300   48.995000
g   28.882700   43.026900
h   39.763300   32.143500
i   33.911500   58.649300
j   22.915300   68.710700
z   26.765400   62.534000
}\latin

\begin{figure}
\begin{minipage}{.95\columnwidth}
\centering
\begin{tikzpicture}[scale = .5, transform shape]    
\begin{groupplot}[
  group style={
   rows=2,
   columns=2,
   horizontal sep=0pt,
   vertical sep=60pt,
   yticklabels at=edge left
 },
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
  ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
 ]
  \nextgroupplot[title=1,ytick pos=both,xtick pos=left,cycle list={    { fill=olive},                {fill=lightgray,pattern=north east lines} }
 ,symbolic x coords={a,b,c,d,e,f,g,h,i,j,t}]
  \addplot table [x index=0, y index =1] {\africa};
  \addplot table [x index=0, y index =2] {\africa};

\nextgroupplot[title=2,ytick pos=both,xtick pos=left,cycle list={    { fill=olive},        {fill=lightgray,pattern=north east lines}},
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,x}]
  \addplot table [x index=0, y index =1] {\europe};
  \addplot table [x index=0, y index =2] {\europe};

\nextgroupplot[title=3,ytick pos=both,xtick pos=left,cycle list={    { fill=olive},        {fill=lightgray,pattern=north east lines}},
symbolic x coords={a,b,c,d,e,f,g,h,i,j,y}]
  \addplot table [x index=0, y index =1] {\australia};
  \addplot table [x index=0, y index =2] {\australia};

\nextgroupplot[title=4,ytick pos=both,xtick pos=left,cycle list={    { fill=olive},    {fill=lightgray,pattern=north east lines}},
symbolic x coords={a,b,c,d,e,f,g,h,i,j,z}]
  \addplot table [x index=0, y index =1] {\latin};
  \addplot table [x index=0, y index =2] {\latin};

\end{groupplot}
\end{tikzpicture}
\end{minipage}
\end{figure}
\end{document}
share|improve this answer
    
Thanks for the hint! I'm a newbie in pgfplots, still don't know all the tricks. I'll update my code according to your suggestions. –  bekon Aug 14 '13 at 19:23
add comment

Adding \centering after \begin{figure} solves that for me.


And for your tons of plots:

Adding

\makeatletter
\g@addto@macro\@floatboxreset\centering
\makeatother

to your preamble will do that automatically for all floats (figures, tables). You will never forget it any more and don't have to type it every time. For some environments (subfigures of subcaption and therefore minipages, too, I guess) that does not word. Don't know why. But it solves your case completely.

share|improve this answer
    
Thanks a lot! You can't even imagine how much you saved me! –  bekon Aug 14 '13 at 19:21
add comment

Or you could just stick the plots in a tabular.

\documentclass{article} 
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{patterns}
\newcommand{\benchmark}{\textsf}
\usepgfplotslibrary{groupplots}
\usepackage{tikz}
\begin{document}

\pgfplotstableread{
1   north   south
a   0.001280    16.766500
b   34.134100   54.436300
c   33.406100   54.002900
d   16.179600   47.049400
e   35.584100   49.673600
f   60.769900   33.283100
g   34.033700   53.008600
h   34.572000   50.658500
i   30.651700   56.141900
j   26.295600   26.996700
t   40.039200   35.579900
}\africa

\pgfplotstableread{
2   north    south
a   55.417400   44.540100
b   36.533900   55.810100
c   22.362600   76.587400
d   92.259800   5.152260
e   50.970100   48.105000
f   51.881900   38.708600
g   89.573900   9.147390
h       32.110000   54.245900
i   40.787100   52.661700
j   17.979700   70.260900
x   27.225800   51.346500
}\europe

\pgfplotstableread{
3   north   south
a   61.048100   38.920000
b   41.228300   33.868400
c   25.102600   67.448500
d   52.942500   46.574600
e   59.920200   40.050800
f   49.975200   41.445900
g   58.469200   41.373000
h   26.563400   48.328000
i   23.641900   54.914700
j   58.528300   41.439700
y   36.577600   42.945300
}\australia

\pgfplotstableread{
4   north   south
a   16.671400   66.676200
b   15.373900   69.806300
c   26.460400   60.564900
d   20.170900   75.096100
e   44.496400   54.911900
f   40.571300   48.995000
g   28.882700   43.026900
h   39.763300   32.143500
i   33.911500   58.649300
j   22.915300   68.710700
z   26.765400   62.534000
}\latin


\begin{tabular}{cc}
\begin{tikzpicture}[scale = .5, transform shape]    
\begin{groupplot}[
  group style={
   rows=2,
   columns=2,
   horizontal sep=0pt,
   vertical sep=60pt,
   yticklabels at=edge left
 },
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,t},
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
  ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
 ]
  \nextgroupplot[title=1,ytick pos=both,xtick pos=left,cycle list={    { fill=olive},                {fill=lightgray,pattern=north east lines} }
]
  \addplot table [x index=0, y index =1] {\africa};
  \addplot table [x index=0, y index =2] {\africa};
\end{groupplot}
\end{tikzpicture}
&
\begin{tikzpicture}[scale = .5, transform shape]
\begin{groupplot}[
  group style={
   rows=2,
   columns=2,
   horizontal sep=0pt,
   vertical sep=60pt,
   yticklabels at=edge left
 },
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,x},
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
  ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
 ]
\nextgroupplot[title=2,ytick pos=both,xtick pos=left,cycle list={    { fill=olive},        {fill=lightgray,pattern=north east lines}}]
  \addplot table [x index=0, y index =1] {\europe};
  \addplot table [x index=0, y index =2] {\europe};
 \end{groupplot}
\end{tikzpicture}
\\
\begin{tikzpicture}[scale = .5, transform shape]
\begin{groupplot}[
  group style={
   rows=2,
   columns=2,
   horizontal sep=0pt,
   vertical sep=60pt,
   yticklabels at=edge left
 },
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,y},
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
  ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
 ]
\nextgroupplot[title=3,ytick pos=both,xtick pos=left,cycle list={    { fill=olive},        {fill=lightgray,pattern=north east lines}}]
  \addplot table [x index=0, y index =1] {\australia};
  \addplot table [x index=0, y index =2] {\australia};
 \end{groupplot}
\end{tikzpicture}
&
\begin{tikzpicture}[scale = .5, transform shape]
\begin{groupplot}[
  group style={
   rows=2,
   columns=2,
   horizontal sep=0pt,
   vertical sep=60pt,
   yticklabels at=edge left
 },
 symbolic x coords={a,b,c,d,e,f,g,h,i,j,z},
 xtick=data,
 xticklabel = {\benchmark{\tick}},
 xtick align=outside,
 ytick align=inside,
 x tick label style={rotate=45,anchor=east,font=\Large},
 y tick label style={font=\Large},
 title style={font=\Large},
     ybar stacked,
    ymin=0, ymax=100,
  yticklabel={ $\pgfmathprintnumber{\tick}\,\%$ },
 ]
\nextgroupplot[title=4,ytick pos=both,xtick pos=left,cycle list={    { fill=olive},    {fill=lightgray,pattern=north east lines}}]
  \addplot table [x index=0, y index =1] {\latin};
  \addplot table [x index=0, y index =2] {\latin};

\end{groupplot}
\end{tikzpicture}
\end{tabular}
\end{document}

enter image description here

share|improve this answer
1  
If you could provide more detail, in the form of an example that uses the OP's data, that would be great. –  Werner Aug 14 '13 at 20:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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