# Using pgfplots, is there a way to get the same data range for two plots in different figures without entering the bounds manually?

Example:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{figure}
\begin{tikzpicture}
\begin{axis}
0 0
1 0
};
\end{axis}
\end{tikzpicture}
\caption{Figure 1}
\end{figure}

\begin{figure}
\begin{tikzpicture}
\begin{axis}
0 1
1 1
};
\end{axis}
\end{tikzpicture}
\caption{Figure 2}
\end{figure}

\end{document}


Here, the first plot ends up with the y range [-1, 1] while the second plot ends up with the y range [-0.8, 1.2]. I want both plots to have the same range that automatically covers both lines.

How can I do this without entering ymin/ymax manually?

-
You could set a style, something like \pgfplotsset{mystyle/.style={ymin=-2,ymax=2}} and then use \begin{axis}[mystyle] but perhaps this is too manual? –  cmhughes Oct 29 '12 at 21:27
Your title refers to scale, but the question seems to be about the domain. Please change one of them so we know which one you are referring to. –  Peter Grill Oct 29 '12 at 21:30
@PeterGrill I changed the title of the question. Seems like the pgfplots manual calls it the "data range", so that's what I changed it to. Thanks. –  Vegard Oct 29 '12 at 21:33
@cmhughes Yes, I was looking for a solution where the range is still calculated automatically based on the data (as it is usually done if you don't specify anything). –  Vegard Oct 29 '12 at 21:35

My solution that seems to work so far is to input both data sets to both plots, but only draw one of them in each plot using the options [draw=none, forget plot] like this:

\documentclass{article}
\usepackage{fullpage}
\usepackage{subcaption}
\usepackage{pgfplots}
\begin{document}

0 0
1 0
}\tableA

0 1
1 1
}\tableB

\begin{figure}
\begin{subfigure}{0.5\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot [draw=none, forget plot] table {\tableB};
\end{axis}
\end{tikzpicture}
\caption{Foo}
\end{subfigure}
\begin{subfigure}{0.5\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot [draw=none, forget plot] table {\tableA};