0

I am so desperately trying to align an equation graph (which consists of a bunch of sine waves) with a ybar graphs places on its right that represents its Fourier transformation. I have used the subfloat environment in order to have two distinct figures which I could then reference and caption individually. The problem that soon arose is that I can't seem to figure out how to align these two graphs properly, and I believe that the problem comes from the fact that the ybar graph has a different structure and layout than the normal graph. I have tried hiding the tick marks of the bar graph but that didn't fix the problem. How can I solve this? Thanks in advance!

\begin{figure}[H]
\centering
\subfloat[][]{
        \begin{tikzpicture}
        \begin{axis}[
            ymajorgrids=true,
            grid style=dashed,tick pos=left,width=9cm,height=8cm]
            \addplot[domain=0:1, samples=200, red, very thin]{6*sin(4*pi*deg(x))};
            \addplot[domain=0:1, samples=200, cyan, very thin]{4*sin(8*pi*deg(x))};
            \addplot[domain=0:1, samples=200, orange, very thin]{3*sin(12*pi*deg(x))};
            \addplot[domain=0:1, samples=200, green, very thin]{2*sin(16*pi*deg(x))};
            \addplot[domain=0:1,samples=200,blue, ultra thick]{6*sin(4*pi*deg(x))+4*sin(8*pi*deg(x))+3*sin(12*pi*deg(x))+2*sin(16*pi*deg(x))};
        \end{axis}
        \end{tikzpicture}
        }
        \subfloat[][]{
        \begin{tikzpicture}
        \begin{axis}[ybar,xmin=0,xmax=1000,tick pos=left, width=9cm,height=8cm]
            \addplot
                coordinates{(200,6) (400,4) (600,3) (800,2)};
        \end{axis}
    \end{tikzpicture}
    }
\end{figure}

enter image description here

1

1 Answer 1

1

Here is a way, using the floatrow package:

\documentclass{article}
\usepackage[utf8]{inputenc} %
\usepackage{geometry}
\usepackage{caption, subcaption, floatrow, tikz, pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{figure}[!ht]
\ffigbox{%
 \floatsetup{style=plain, heightadjust=object, valign=t}
\begin{subfloatrow} 
\ffigbox[\FBwidth]{\caption{}\label{fig:1}}
{\begin{tikzpicture}
        \begin{axis}[
            ymajorgrids=true,
            grid style=dashed,tick pos=left,width=9cm,height=8cm]
            \addplot[domain=0:1, samples=200, red, very thin]{6*sin(4*pi*deg(x))};
            \addplot[domain=0:1, samples=200, cyan, very thin]{4*sin(8*pi*deg(x))};
            \addplot[domain=0:1, samples=200, orange, very thin]{3*sin(12*pi*deg(x))};
            \addplot[domain=0:1, samples=200, green, very thin]{2*sin(16*pi*deg(x))};
            \addplot[domain=0:1,samples=200,blue, ultra thick]{6*sin(4*pi*deg(x))+4*sin(8*pi*deg(x))+3*sin(12*pi*deg(x))+2*sin(16*pi*deg(x))};
        \end{axis}
        \end{tikzpicture}}
\ffigbox[\FBwidth]{\caption{}\label{fig:2}}
{\begin{tikzpicture}
        \begin{axis}[ybar,xmin=0,xmax=1000,tick pos=left, width=9cm,height=8cm]
            \addplot
                coordinates{(200,6) (400,4) (600,3) (800,2)};
        \end{axis}
    \end{tikzpicture}}
\end{subfloatrow}}
{\caption{Sine waves and their Fourier transforms}\label{fig}}
\end{figure}

\end{document} 

enter image description here

2
  • +1: Never heard of the floatrow package! I would have tried something with scale only axis as a first guess. May 25, 2021 at 16:15
  • 1
    @Dr.ManuelKuehner: It cooperates with caption, but has a drawback: one cannot load the float package (however, I believe it has similar functionalities).
    – Bernard
    May 25, 2021 at 16:30

You must log in to answer this question.

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