I once already asked a very similar question; How can I add space between two separate plots, using pgfplots?. But this is some what different.
I have the following code;
\documentclass{standalone}
\usepackage{graphics}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.6}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
width=3cm,
height=3cm,
scale only axis,
every x tick label/.append style={font=\scriptsize\color{gray!80!black}},
xmin=0, xmax=20000,
xlabel={$t$},
xmajorgrids,
xminorgrids,
every y tick label/.append style={font=\scriptsize\color{gray!80!black}},
ymin=0.0004, ymax=0.0012,
ylabel={$\phi_{\mathrm{i}}(t)$},
ymajorgrids,
yminorgrids,
name=plot1]
\end{axis}
\begin{axis}[%
width=3cm,
height=3cm,
scale only axis,
every x tick label/.append style={font=\scriptsize\color{gray!80!black}},
xmin=0, xmax=20000,
xlabel={$t$},
xmajorgrids,
xminorgrids,
every y tick label/.append style={font=\scriptsize\color{gray!80!black}},
ymin=0.2, ymax=1.2,
ylabel={$h(t)$},
ymajorgrids,
yminorgrids,
name=plot2,
at=(plot1.right of north east), anchor=left of north west]
\end{axis}
\begin{axis}[%
width=3cm,
height=3cm,
scale only axis,
every x tick label/.append style={font=\scriptsize\color{gray!80!black}},
xmin=0, xmax=20000,
xlabel={$t$},
xmajorgrids,
xminorgrids,
every y tick label/.append style={font=\scriptsize\color{gray!80!black}},
ymin=0.0004, ymax=0.0012,
ylabel={$\phi_{\mathrm{o}}(t)$},
ymajorgrids,
yminorgrids,
name=plot4,
at=(plot1.below south west), anchor=above north west]
\end{axis}
\begin{axis}[%
width=3cm,
height=3cm,
scale only axis,
every x tick label/.append style={font=\scriptsize\color{gray!80!black}},
xmin=0, xmax=20000,
xlabel={$t$},
xmajorgrids,
xminorgrids,
every y tick label/.append style={font=\scriptsize\color{gray!80!black}},
ymin=2000, ymax=12000,
ylabel={$p_{\mathrm{i}}(t)$},
ymajorgrids,
yminorgrids,
name=plot5,
at=(plot4.right of north east), anchor=left of north west]
\end{axis}
\end{tikzpicture}
\end{document}
This creates the following plot:
I think there is to few vertical/horizontal spacing between the plots. I want to increase this. Currently I use x- yshift, this gives the following result:
\documentclass{standalone}
\usepackage{graphics}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.6}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
width=3cm,
height=3cm,
scale only axis,
every x tick label/.append style={font=\scriptsize\color{gray!80!black}},
xmin=0, xmax=20000,
xlabel={$t$},
xmajorgrids,
xminorgrids,
every y tick label/.append style={font=\scriptsize\color{gray!80!black}},
ymin=0.0004, ymax=0.0012,
ylabel={$\phi_{\mathrm{i}}(t)$},
ymajorgrids,
yminorgrids,
name=plot1]
\end{axis}
\begin{axis}[%
xshift=1cm,
width=3cm,
height=3cm,
scale only axis,
every x tick label/.append style={font=\scriptsize\color{gray!80!black}},
xmin=0, xmax=20000,
xlabel={$t$},
xmajorgrids,
xminorgrids,
every y tick label/.append style={font=\scriptsize\color{gray!80!black}},
ymin=0.2, ymax=1.2,
ylabel={$h(t)$},
ymajorgrids,
yminorgrids,
name=plot2,
at=(plot1.right of north east), anchor=left of north west]
\end{axis}
\begin{axis}[%
yshift=-1cm,
width=3cm,
height=3cm,
scale only axis,
every x tick label/.append style={font=\scriptsize\color{gray!80!black}},
xmin=0, xmax=20000,
xlabel={$t$},
xmajorgrids,
xminorgrids,
every y tick label/.append style={font=\scriptsize\color{gray!80!black}},
ymin=0.0004, ymax=0.0012,
ylabel={$\phi_{\mathrm{o}}(t)$},
ymajorgrids,
yminorgrids,
name=plot4,
at=(plot1.below south west), anchor=above north west]
\end{axis}
\begin{axis}[%
xshift=1cm,
width=3cm,
height=3cm,
scale only axis,
every x tick label/.append style={font=\scriptsize\color{gray!80!black}},
xmin=0, xmax=20000,
xlabel={$t$},
xmajorgrids,
xminorgrids,
every y tick label/.append style={font=\scriptsize\color{gray!80!black}},
ymin=2000, ymax=12000,
ylabel={$p_{\mathrm{i}}(t)$},
ymajorgrids,
yminorgrids,
name=plot5,
at=(plot4.right of north east), anchor=left of north west]
\end{axis}
\end{tikzpicture}
\end{document}
I want to know if there is a more consistent manner to do this.
Best Answer
You might want to have a look to the
groupplots
library (see the documentation 5.5 Grouping plots).It allows you to deploy graphs in a grid by selecting the
group size
(e.g.group size= 2 by 2
for your case) or directly the number ofrows
andcolumns
. Then you can customize the horizontal and vertical distance among the graphs by means of the keyshorizontal sep
andvertical sep
.In your case, a possible solution is:
The result: