0

I am trying to align the axis of 3 plots that are organized as the following: two on the first row and one on the second row. I would like the axis of the third plot to be aligned with the axis of the plots of the first row. What is the best practice to do so?

enter image description here

\begin{figure}
\centering
\begin{tikzpicture}


\begin{groupplot}[group style={group size= 2 by 1, horizontal sep=0.12\textwidth, vertical     sep=0.0\textwidth,}]
    
    \nextgroupplot[
    scale only axis=true,
    xlabel = {$x$},
    ylabel = {$y$},
    width=0.38\columnwidth,
    height=0.253125\columnwidth,]
    \addplot {rnd};
                
    \nextgroupplot[
    scale only axis=true,
    xlabel = {$x$},
    ylabel = {$y$},
    width=0.38\columnwidth,
    height=0.253125\columnwidth,]
    \addplot {rnd};
    \end{groupplot}
\end{tikzpicture}

\vspace{0.5cm}

\centering
\begin{tikzpicture}
\begin{axis}[
    scale only axis=true,
    xlabel = {$x$},
    ylabel = {$y$},
    width=0.80\columnwidth,
    height=0.253125\columnwidth,]
    \addplot {rnd};
\end{axis}
\end{tikzpicture} 
1
  • What exactly do you want aligned? As you write it now, it is confusing/contradictory. Dec 23, 2022 at 18:08

1 Answer 1

2

I guess you want the left/right edges of the bottom axis to align with the outer edges of the two axes on the top?

First of all, that obviously means the bottom axis has to be as wide as the two top axes combined plus the space between them. You're using scale only axis everywhere, and you've specified all lengths explicitly for the first two, so it's a simple calculation. You can even have pgf do the calculation for you, with width=2*0.38\columnwidth+0.12\textwidth.

In addition, you have to make sure the horizontal alignment is correct. If the ticklabels/ylabels have different widths in the first and third axis, you might get wrong alignment if they're in separate tikzpictures. What I would do is place everything in the same tikzpicture, and place the third axis relative the first. There are several ways to do that, below I took what might be the laziest option, and added a negative yshift to the big axis.

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{figure}

\centering
\begin{tikzpicture}


\begin{groupplot}[
   group style={
      group size= 2 by 1,
      horizontal sep=0.12\textwidth,
      vertical sep=0.0\textwidth,
      group name=toprow
      }]
    
    \nextgroupplot[
    scale only axis=true,
    xlabel = {$x$},
    ylabel = {$y$},
    width=0.38\columnwidth,
    height=0.253125\columnwidth,]
    \addplot {rnd};
                
    \nextgroupplot[
    scale only axis=true,
    xlabel = {$x$},
    ylabel = {$y$},
    width=0.38\columnwidth,
    height=0.253125\columnwidth,]
    \addplot {rnd};
    \end{groupplot}
% put all plots in same tikzpicture
\begin{axis}[
    yshift=-0.35\columnwidth, % <-- added
    scale only axis=true,
    xlabel = {$x$},
    ylabel = {$y$},
    width=0.76\columnwidth+0.12\textwidth,  % modified 
    height=0.253125\columnwidth
    ]
    \addplot {rnd};
\end{axis}
\end{tikzpicture} 
\end{figure}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .