如何水平对齐两个图

如何水平对齐两个图

我想水平对齐这两个图:

 \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}

\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}

我尝试使用\subfigure,但没有成功。

答案1

以下是我使用的方法subcaption按您所需包装

截屏

我擅自将您的ylabel文字移到了标题中。我width=\textwidth也设置了。

您可能想探索一下scale only axis它是否非常有用 - 我已将它留在序言中作为评论供您参考。

% 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}

答案2

我通常只是将它们放在一个center环境中:

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

还有\usepgfplots{groupplots}其相关的矩阵状排列,记录在pgfplots手册的第 5.5 节中。

相关内容