So richten Sie zwei Diagramme horizontal aus

So richten Sie zwei Diagramme horizontal aus

Ich möchte diese beiden Diagramme horizontal ausrichten:

 \begin{tikzpicture}
        \begin{axis}[
            xmin=1995,
            xmax=2010,
            ymode=log,
            xtick={1975,1980,...,2015},
            x tick label style={/pgf/number format/1000 sep=},
            xlabel={Year},
            ylabel={Cost of gene synthesis $(\$/base$)},
        ]
            \addplot coordinates {(1998,30) (2001,15) (2002,10) (2003,5) (2006,0) (2007,0.7)};
        \end{axis}
    \end{tikzpicture}

Und

\begin{tikzpicture}
        \begin{axis}[
            xmin=1975,
            xmax=2010,
            ymode=log,
            xtick={1975,1980,...,2015},
            x tick label style={/pgf/number format/1000 sep=},
            xlabel={Year},
            ylabel={Length in base pairs},
        ]
            \addplot coordinates {(1978,207) (1990,2100) (1995,2700) (2003,7500) (2005,14600) (2006,32000) (2009,583000)};
        \end{axis}
    \end{tikzpicture}

Ich habe versucht, es zu verwenden \subfigure, aber ohne Erfolg.

Antwort1

So würde ich es machen, mit demsubcaptionPaket nach Wunsch

Bildschirmfoto

Ich habe mir erlaubt, deinen ylabelText in die Bildunterschrift zu verschieben. Das habe ich width=\textwidthauch eingestellt.

Vielleicht möchten Sie es erkunden, scale only axises ist recht nützlich – ich habe es als Kommentar in der Präambel gelassen, damit Sie damit spielen können.

% arara: pdflatex
% !arara: indent: {overwrite: true}
\documentclass{article}

\usepackage{pgfplots}
\usepackage{subcaption}

%\pgfplotsset{every axis/.append style={
%                    scale only axis,       % otherwise width won't be as intended: http://tex.stackexchange.com/questions/36297/pgfplots-how-can-i-scale-to-text-width
%                    }}

\begin{document}

\begin{figure}[!ht]
    \begin{subfigure}[t]{.5\textwidth}
        \begin{tikzpicture}
            \begin{axis}[
                    xmin=1995,
                    xmax=2010,
                    ymode=log,
                    xtick={1975,1980,...,2015},
                    x tick label style={/pgf/number format/1000 sep=},
                    xlabel={Year},
                    width=\textwidth,
                ]
                \addplot coordinates {(1998,30) (2001,15) (2002,10) (2003,5) (2006,0) (2007,0.7)};
            \end{axis}
        \end{tikzpicture}
        \caption{Cost of gene synthesis ($\$/base$)},
    \end{subfigure}%
    \begin{subfigure}[t]{.5\textwidth}
        \begin{tikzpicture}
            \begin{axis}[
                    xmin=1975,
                    xmax=2010,
                    ymode=log,
                    xtick={1975,1985,...,2015},
                    x tick label style={/pgf/number format/1000 sep=},
                    xlabel={Year},
                    width=\textwidth,
                ]
                \addplot coordinates {(1978,207) (1990,2100) (1995,2700) (2003,7500) (2005,14600) (2006,32000) (2009,583000)};
            \end{axis}
        \end{tikzpicture}
        \caption{Length in base pairs}
    \end{subfigure}%
\end{figure}
\end{document}

Antwort2

Normalerweise platziere ich sie einfach zusammen in einer centerUmgebung:

\begin{center}
 \begin{tikzpicture} \begin{axis} ... \end{axis} \end{tikzpicture}
 \hfil
 \begin{tikzpicture} \begin{axis} ... \end{axis} \end{tikzpicture}
\end{center}

Es gibt auch \usepgfplots{groupplots}die zugehörige matrixartige Anordnung, die in Abschnitt 5.5 des pgfplotsHandbuchs dokumentiert ist.

verwandte Informationen