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.

I have two axis environments both containing different plots. I do however want to maintain comparability between both, i.e. I want both plots to consume the same space on the paper for a coordinate step on the y-axis. Setting both plots to the same height doesn't do the trick, as both have different ymax values, thus the ratios of both plots would be different.

In this example

\documentclass[border=3mm]{standalone}

\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
        \begin{axis}
                \addplot coordinates {
                (0,0)
                (1,1)
                };
        \end{axis}
\end{tikzpicture}

\begin{tikzpicture} 
        \begin{axis}
                \addplot coordinates {
                (0,0)
                (1,1)
                };
                \addplot coordinates {
                (0,0)
                (1,2)
                };
        \end{axis}
\end{tikzpicture}
\end{document}

}

... I would want the second axis box to be automatically double as high as the first one, such that the two identical plots also are identically scaled across the two axis environments. The actual outcome does however look like this:

enter image description here

share|improve this question
    
It is always best to compose a MWE that illustrates the problem including the \documentclass so that those trying to help don't have to recreate it. –  Peter Grill Oct 9 '11 at 14:24
    
    
@PeterGrill I also came across that question, I don't think it helps here –  barbaz Oct 9 '11 at 14:35
    
@barbaz If Peter's answer is what you want can you upvote it and accept it please. –  Yiannis Lazarides Oct 9 '11 at 14:57
add comment

2 Answers

up vote 7 down vote accepted

You can save the y unit vector length of the first plot into a macro by using

\pgfplotsextra{
    \global\edef\yunit{\pgfplotsunitylength}
}

which can then be used to set the y unit vector in the second plot by setting y=\yunit. This will only work correctly if you use disabledatascaling, though, otherwise the unit vector will not be reported correctly.

\documentclass{article}

\usepackage{pgfplots}
\begin{document}

\pgfplotsset{
    scale only axis, % To make sure the plot *areas* are the same width
    width=5cm,
    enlarge y limits={abs=0.2}, % To make sure the axes are extended by the same absolute amount
    disabledatascaling
}

\begin{tikzpicture}
        \begin{axis}
                \addplot coordinates {
                (0,0)
                (1,2)
                };
        \pgfplotsextra{
            \global\edef\yunit{\pgfplotsunitylength}
        }
        \end{axis}
\end{tikzpicture}
\begin{tikzpicture} 
        \begin{axis}[y=\yunit]
                \addplot coordinates {
                (0,0)
                (1,2)
                };
                \addplot coordinates {
                (0,0)
                (1,3)
                };
        \end{axis}
\end{tikzpicture}
\end{document}

}

share|improve this answer
add comment

Not quite automatic, but you could specify the height, or specify the y-unit vector length.

Perhaps you use can do some automation to determine the scale factor via the values of ymin ymax. These are accessible via \pgfkeysvalueof{/pgfplots/xmin}, but as per How to access \xmin, \xmax, \ymin, \ymax from within PGFplots axis environment you can only access them if they have been set explicitly in the axis options.

\documentclass[border=3mm]{standalone}

\usepackage{pgfplots}
\begin{document}

\pgfplotsset{yticklabel style={text width=3em,align=right}}
\begin{tikzpicture}
        \begin{axis}[height=6.0cm,width=10cm,scale only axis]
                \addplot coordinates {(0,0) (1,1)};
        \end{axis}
\end{tikzpicture}

\begin{tikzpicture}
        \begin{axis}[height=12.0cm,width=10cm,scale only axis]
                \addplot coordinates {(0,0) (1,1)};
                \addplot coordinates {(0,0) (1,2)};
        \end{axis}
\end{tikzpicture}
\end{document}

Also not automatic, but you could specify the length of the unit vectors by [y={<dimension>}].

\documentclass[border=3mm]{standalone}

\usepackage{pgfplots}
\begin{document}

\pgfplotsset{yticklabel style={text width=3em,align=right}}
\begin{tikzpicture}
        \begin{axis}[y=4cm]
                \addplot coordinates {(0,0) (1,1)};
        \end{axis}
\end{tikzpicture}

\begin{tikzpicture}
        \begin{axis}[y=4cm]
                \addplot coordinates {(0,0) (1,1)};
                \addplot coordinates {(0,0) (1,2)};
        \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Yes, thats what I'm doing at the moment. And thats what I want a replacement for :o) –  barbaz Oct 9 '11 at 14:52
    
See updated re possible automation, but that require explicitly specifying the ymin, yamx values, or alternatively specifying the unit vector length. –  Peter Grill Oct 9 '11 at 15:09
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.