How to make the unit length of $x$ axis and that of $y$ axis the same?

When I use Tikz to draw the graphs of $y=x+\frac{1}{x}$ and $y=5(x-\frac{4}{3})$, but I found the unit length of $x$ axis and that of $y$ axis are different, if I want to let them be the same, what should I do?

• Welcome to TeX.SE! Are you looking for unit vector ratio=1 1 1? – user121799 Nov 9 '18 at 21:46
• Unrelated note: TikZ and pgfplots are two separate packages. The latter uses the former, but one can make plots in TikZ without using pgfplots. That unit vector ratio worked means that you use pgfplots I guess, so it's better to say that. (By the the way, axis equal is a shorthand for unit vector ratio=1 1 1.) – Torbjørn T. Nov 9 '18 at 23:24
• @TorbjørnT. wow great advice! – manooooh Nov 9 '18 at 23:26
• @TorbjørnT. The pgfplots manual says on p. 299: "The configuration axis equal image=true is actually just a style which sets unit vector ratio=1 1 1,unit rescale keep size=false." so that I think that there is a slight difference (which however does not matter here). And yes, I guessed from the context that pgfplots was used since TikZ alone does not rescale units. – user121799 Nov 9 '18 at 23:55
• @marmot Oops, you're right. I must have misread, thanks for the correction. – Torbjørn T. Nov 10 '18 at 0:01

You can enforce equal units by saying unit vector ratio=1 1 1, axis equal image or axis equal. The differences are subtle.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{pdflscape}
\begin{document}
\begin{landscape}
\begin{tikzpicture}[
declare function={
f(\x) = \x+1/\x;
g(\x) = 5*(\x-4/3);}]
\begin{axis}[unit vector ratio=1 1 1,
axis x line=middle, axis y line=middle,
ymin=-5, ymax=5,ylabel=$y$,
xmin=0,xmax=5.5,xlabel=$x$,
domain=0.1:5,samples=101,
legend pos=south east]
\addlegendentry{$f(x)$}
\addlegendentry{$g(x)$}
\end{axis}
\node[anchor=north] at (current axis.south) {\texttt{unit vector ratio=1 1 1}};
\end{tikzpicture}
~
\begin{tikzpicture}[
declare function={
f(\x) = \x+1/\x;
g(\x) = 5*(\x-4/3);}]
\begin{axis}[axis equal image,
axis x line=middle, axis y line=middle,
ymin=-5, ymax=5,ylabel=$y$,
xmin=0,xmax=5.5,xlabel=$x$,
domain=0.1:5,samples=101,
legend pos=south east]
\addlegendentry{$f(x)$}
\addlegendentry{$g(x)$}
\end{axis}
\node[anchor=north] at (current axis.south) {\texttt{axis equal image}};
\end{tikzpicture}
~
\begin{tikzpicture}[
declare function={
f(\x) = \x+1/\x;
g(\x) = 5*(\x-4/3);}]
\begin{axis}[axis equal,
axis x line=middle, axis y line=middle,
ymin=-5, ymax=5,ylabel=$y$,
xmin=0,xmax=5.5,xlabel=$x$,
domain=0.1:5,samples=101,
legend pos=south east]
\addlegendentry{$f(x)$}
\addlegendentry{$g(x)$}