Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Example:

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

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

\begin{figure}
\begin{tikzpicture}
\begin{axis}
\addplot table {
    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?

share|improve this question
    
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
add comment

1 Answer 1

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}

\pgfplotstableread{
    0 0
    1 0
}\tableA

\pgfplotstableread{
    0 1
    1 1
}\tableB

\begin{figure}
\begin{subfigure}{0.5\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot table {\tableA};
\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};
\addplot table {\tableB};
\end{axis}
\end{tikzpicture}
\caption{Bar}
\end{subfigure}
\caption{Foobar}
\end{figure}

\end{document}

I also changed the example slightly to put the graphs side-by-side, since that's what I wanted this for in the first place (for easier comparisons of two non-overlaid graphs).

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.