# Align plots within tikz pictures one above the other

I have an issue I trust you will solve.

I am plotting two graphs in order to represent Bode diagrams. For correspondance of abscissa they should be one above the other. I can align the figures but because the value on the y axis may differ, the plots themselves may not be aligned.

See for yourselves:

Can you help me ?

Plus, this is just in "standalone" document, so I used "varwidth" to have them on top of each other but how will I achieve the same result inside an "article" document ?

Created with this code :

\documentclass[varwidth]{standalone}
\usepackage{pgfplots}

\begin{document}

\def\T{10}
\def\K{1000}
\def\FloorW{floor(ln(1/\T)/ln(10))}
\def\CeilW{ceil(ln(1/\T)/ln(10))}

\begin{tikzpicture}
\begin{semilogxaxis}[height=5cm,width=10cm,
grid=both, tick align=outside, tickpos=left]

\def\GdbK{20*ln(\K)/ln(10)}

\end{semilogxaxis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{semilogxaxis}[height=5cm,width=10cm,
grid=both, tick align=outside, tickpos=left,
ytick=\empty,extra y ticks={0,-45,-90} ]

{(10^(\FloorW-2),0) (1/\T,0) (1/\T,-90) ((10^(\CeilW+2),-90)}[red];

\end{semilogxaxis}
\end{tikzpicture}
\end{document}


Just put both graphics in the same tikzpicture environment and move the second one down with yshift=-4.5cm

\documentclass[varwidth]{standalone}
\usepackage{pgfplots}

\begin{document}

\def\T{10}
\def\K{1000}
\def\FloorW{floor(ln(1/\T)/ln(10))}
\def\CeilW{ceil(ln(1/\T)/ln(10))}

\begin{tikzpicture}
\begin{semilogxaxis}[height=5cm,width=10cm,
grid=both, tick align=outside, tickpos=left]

\def\GdbK{20*ln(\K)/ln(10)}

\end{semilogxaxis}
%\end{tikzpicture}
%
%\begin{tikzpicture}
\begin{semilogxaxis}[yshift=-4.5cm,height=5cm,width=10cm,
grid=both, tick align=outside, tickpos=left,
ytick=\empty,extra y ticks={0,-45,-90} ]

{(10^(\FloorW-2),0) (1/\T,0) (1/\T,-90) ((10^(\CeilW+2),-90)}[red];

\end{semilogxaxis}
\end{tikzpicture}
\end{document}


• Thanks, that's exactly what I was looking for. Quick follow up question, how come -4.5cm is enough when the height of the first plot is set to 5cm ? – LMT-PhD Feb 17 at 13:22
• This is because on the y-axis, it displays the graduations between 20 and 60 and not those between 20 and 0. – AndréC Feb 17 at 14:46
• I don't know, I changed \K to 10, to change the values between -20 and 20 and it doesn't affect the display positions. – LMT-PhD Feb 17 at 14:49
• The part displayed is the useful part, if I may say so. Since there is no data between 0 and 20, by default the graph is reduced to useful dimensions – AndréC Feb 17 at 14:52

off-topic since your problem is solved by @AndréC's answer. i would write his mwe on the following way:

\documentclass[varwidth, margin=3mm]{standalone}
\usepackage{pgfplots}

\begin{document}

\def\T{10}
\def\K{1000}
\def\FloorW{floor(ln(1/\T)/ln(10))}
\def\CeilW{ceil(ln(1/\T)/ln(10))}

\begin{tikzpicture}
\pgfplotsset{height=5cm,width=10cm,
grid=both,
%tick align=outside,
tickpos=left,
no marks}
\begin{semilogxaxis}
\def\GdbK{20*ln(\K)/ln(10)}