# Quiver scale in pgfplots (unit scaling)

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?).

-
Bad, bad boy (I tripped up that norm). My apologies for making you go through that...but thanks! –  TSGM Nov 8 '11 at 3:06
you're welcome. After all, I could produce nice pictures (which is always worth the effort ;-) ) –  Christian Feuersänger Nov 9 '11 at 18:26