18

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.

Quiver

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.

1 Answer 1

21

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

enter image description here

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .