我想水平对齐这两个图:
\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 节中。