[Tex/LaTex] How to draw a 2D vector field in pgfplots

pgfplotstikz-pgf

I'm pretty new to LaTeX and I need to draw a 2D vector field (Like a graph with vector arrows all over it. I can't find it anywhere online. I'd like to use pgfplots if that's possible.

Best Answer

If you're not stuck to pgfplots, pst-plot has a \psVectorfield command which makes it very easy (adapted from an example in the pst-plot documentation):

\documentclass[x11names, border=5pt]{standalone}

\usepackage{pst-plot}
\usepackage{auto-pst-pdf}

\begin{document}
%
%%%%%%%%%%% v(x, y) = =x² + y² - 1
\psset{unit=4cm, arrowinset=0.12}
\begin{pspicture}(-1.2,-1.2)(1.1,1.1)
    \psaxes[ticksize=0 4pt,axesstyle=frame,tickstyle=inner,subticks=20,
    Ox=-1,Oy=-1](-1,-1)(1,1)
    \psset{arrows=->,algebraic}
    \psVectorfield[linecolor=DarkOliveGreen3](-0.9,-0.9)(0.9,0.9){ x²+y²-1 }
\end{pspicture}

\end{document} 

enter image description here