# tikz plots alignment

I'm trying to produce a figure using

\begin{figure}
\centering
\makebox[\columnwidth]{\input{try1.tikz}}
\makebox[\columnwidth]{\input{try2.tikz}}
\end{figure}


The files try1.tikz and try2.tikz are given below. The only difference between them is that in the former xmin=-2, in the latter xmin=-4.

I get

How do I align the panels vertically?

try1.tikz is:

\begin{tikzpicture}[font=\footnotesize\sffamily]

\begin{axis}[%
view={0}{90},
width=4cm,
height=4cm,
scale only axis,
xmin=-2, xmax=1,
ymin=0, ymax=1.7,
name=plot2,
unbounded coords=jump]
\end{axis}

\begin{axis}[
view={0}{90},
width=4cm,
height=4cm,
scale only axis,
xmin=-2, xmax=1,
ymin=0, ymax=1.7,
at=(plot2.left of south west), anchor=right of south east,
unbounded coords=jump]
\end{axis}

\begin{axis}[
view={0}{90},
width=4cm,
height=4cm,
scale only axis,
xmin=-2, xmax=1,
ymin=0, ymax=1.7,
at=(plot2.right of south east), anchor=left of south west,
legend style={nodes=right,font=\tiny},
legend pos= north west,
unbounded coords=jump]

\end{axis}
\end{tikzpicture}


and try2.tikz is:

\begin{tikzpicture}[font=\footnotesize\sffamily]

\begin{axis}[
view={0}{90},
width=4cm,
height=4cm,
scale only axis,
xmin=-4, xmax=1,
ymin=0, ymax=1.7,
name=plot2,
unbounded coords=jump]
\end{axis}

\begin{axis}[
view={0}{90},
width=4cm,
height=4cm,
scale only axis,
xmin=-4, xmax=1,
ymin=0, ymax=1.7,
at=(plot2.left of south west), anchor=right of south east,
unbounded coords=jump]
\end{axis}

\begin{axis}[
view={0}{90},
width=4cm,
height=4cm,
scale only axis,
xmin=-4, xmax=1,
ymin=0, ymax=1.7,
at=(plot2.right of south east), anchor=left of south west,
legend style={nodes=right,font=\tiny},
legend pos= north west,
unbounded coords=jump]
\end{axis}
\end{tikzpicture}


This brings immediate attention to the groupplots library of pgfplots.

Your plot can be realized through:

% \usepgfplotslibrary{groupplots}
\begin{tikzpicture}
\begin{groupplot}[group style={rows=2,columns=3},
view={0}{90},
width=4cm,height=4cm,
scale only axis,
xmin=-2, xmax=1,
bottom plots/.style={xmin=-4},
ymin=0, ymax=1.7,unbounded coords=jump]
\nextgroupplot
\nextgroupplot
\nextgroupplot
\nextgroupplot[bottom plots]
\nextgroupplot[bottom plots]
\nextgroupplot[bottom plots]
\end{groupplot}
\end{tikzpicture}


which will yield the following image:

The groupplot environment does the following:

1. Determines the number of plots by rows and columns in the style group style. (one can also use group size=<cols> by <rows>)
2. Grab each \nextgroupplot and places it in column-wise order
3. Each \nextgroupplot is equivalent to \begin{axis} ... \end{axis}
4. Every option specified in the groupplot (and not in the group style style) environment will be added to each \nextgroupplot macro, thereby each axis environment.

If you need to adjust the spacing between the plots you have the following styles (which should be placed inside the group style key:

• horizontal sep=<dim>
• vertical sep=<dim>

Thus you can do:

 group style={vertical sep=0cm}


to make them touch each other in the vertical direction. The pgfplots manual has a whole section of this which I highly suggest you read (it is placed under Related Libraries).

You can use the groupplots library:

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary[pgfplots.groupplots]

\begin{document}
\begin{figure}
\begin{tikzpicture}[font=\footnotesize\sffamily]
\begin{groupplot}[
group style={group size=3 by 2},
view={0}{90},
width=4cm,
height=4cm,
scale only axis,
xmin=-2, xmax=1,
ymin=0, ymax=1.7,
name=plot2,
unbounded coords=jump]
]
\nextgroupplot          \addplot [domain=-2:1, thick, cyan] {rnd};
\nextgroupplot          \addplot [domain=-2:1, thick, cyan] {rnd};
\nextgroupplot          \addplot [domain=-2:1, thick, cyan] {rnd};
\nextgroupplot[xmin=-4] \addplot [domain=-4:1, thick, cyan] {rnd};
\nextgroupplot[xmin=-4] \addplot [domain=-4:1, thick, cyan] {rnd};
\nextgroupplot[xmin=-4] \addplot [domain=-4:1, thick, cyan] {rnd};
\end{groupplot}
\end{tikzpicture}
\end{figure}
\end{document}


Which produces

Any option that is common for all plots can go as the optional arguments to the \begin{groupplot} command, and any that are specific to each plot can be passed to the \nextgroupplot command.

To make the difference between the top and the bottom plots, the best way would probably be by defining a style for all of them, as in zeroth's answer. So I modified my answer to show how options can be passed individually to each \nextgroupplot.