4

Is there a way to have two or more plots next to each other in a single row? I would like to use pgfplots to have some simple functions be plotted. Best thing would be to have a little arrow in between the plots as they shall represent changes in a sequence of functions. So basically I would like to have the following code be presented in one row.

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[margin=1.2in]{geometry}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xmin = 0, xmax = 1,
        xlabel = $x$,
        ylabel = $h_0$
    ]
    \addplot[mark = none, thick]{1};
    \end{axis}
\end{tikzpicture}

\[\rightarrow\]

\begin{tikzpicture}     
    \begin{axis}[
        xmin = 0, xmax = 1,
        xlabel = $x$,
        ylabel = $h_1$
    ]
    \addplot+[mark = none, thick, const plot, jump mark left]
        coordinates{
            (0,2) (0.5,-2) (1,-2)
        };
    \end{axis}
\end{tikzpicture}
\end{document}
1
  • Can you add your complete code (with the \documentclass and the packages that you use?
    – Sebastiano
    May 29, 2018 at 21:08

1 Answer 1

5

test, if this gives satisfactory result:

edit: to be top of diagrams in line you should ensure, that yticklabel is at both or none diagram at their tops. for example adding

        ymin = 0, ymax = 1.1,

to the first diagrams gives:

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16, width=0.4\linewidth}

\begin{document}
\begin{tikzpicture}[baseline=(current bounding box.center)] % new, added option
    \begin{axis}[
        xmin = 0, xmax = 1,
        xlabel = $x$,
        ylabel = $h_0$
    ]
    \addplot[mark = none, thick]{1};
    \end{axis}
\end{tikzpicture}
\quad          % new
$\rightarrow$  % changed
\quad          % new
\begin{tikzpicture}[baseline=(current bounding box.center)] % new, added option
    \begin{axis}[
        xmin = 0, xmax = 1,
        xlabel = $x$,
        ylabel = $h_1$
    ]
    \addplot+[mark = none, thick, const plot, jump mark left]
        coordinates{
            (0,2) (0.5,-2) (1,-2)
        };
    \end{axis}
\end{tikzpicture}
\end{document}
2
  • Almost, I think the right plot is shifted upwards a bit. EDIT: it's not, the labeling of the y-axis on the left graph makes it shift down a bit.
    – Strupp1
    May 29, 2018 at 21:16
  • yes, it is. this you can correct by defining ymax to plots or on other way which will move yticklabel on the first plot below top diagram border.
    – Zarko
    May 29, 2018 at 21:20

You must log in to answer this question.

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