# [Tex/LaTex] Quiver scale in pgfplots (unit scaling)

pgfplotstikz-pgf

Quiver plots can be made within pgfplots. Here is a minimal example which is a vector field of [1, x-y]:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[domain=-3:3, view={0}{90}]
\addplot3[blue, quiver={u={1}, v={(x-y)}, scale arrows=0.15}, -stealth,samples=20] {0};
\end{axis}
\end{tikzpicture}

\end{document}


This produces the below picture.

The question is, how do I scale the arrows to be of unit size? Dividing by the norm of arrows, abs(x-y), isn't a great solution, because around zero pgfplots will spit out an error.

You already have the right approach: dividing by the arrow length is the solution. In your case, the error norm is sqrt(1+(x-y)^2) (do not forget the x component!):

\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\def\length{sqrt(1+(x-y)^2)}
\begin{tikzpicture}
\begin{axis}[domain=-3:3, view={0}{90}]
\addplot3[blue, quiver={u={1/(\length)}, v={(x-y)/(\length)}, scale arrows=0.15}, -stealth,samples=20] {0};
\end{axis}
\end{tikzpicture}

\end{document}


You may want to adjust scale arrows (perhaps using value 1 again?).