# How to maintain the ratio between two axis in pgfplots

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}
(0,0)
(1,1)
};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}
(0,0)
(1,1)
};
(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:

-
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

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}
(0,0)
(1,2)
};
\pgfplotsextra{
\global\edef\yunit{\pgfplotsunitylength}
}
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[y=\yunit]
(0,0)
(1,2)
};
(0,0)
(1,3)
};
\end{axis}
\end{tikzpicture}
\end{document}

}


-

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]
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[height=12.0cm,width=10cm,scale only axis]
\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]
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[y=4cm]

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