Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 13 down vote accepted

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

share|improve this answer
    
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
1  
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.