# How to draw a 2D vector field in pgfplots?

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.

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} • Thank you for the answer. However, I still can't get it to work for me. This is the command I typed in: \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) \psVectorfield[linecolor=DarkOliveGreen3](-0.9,-0.9)(0.9,0.9){ x^2+y^2-1 } \end{pspicture} Feb 1, 2017 at 17:26
• To compile pstricks code with pdflatex, you have to launch the compiler with the --enable-write18 switch (MiKTeX) or -shell-escape (TeX Live, MacTeX). Feb 1, 2017 at 17:30
• Sorry I don't know how to type in latex form on this page so my comment looks like a mess Feb 1, 2017 at 17:32
• You forgot to add the command \psset{arrows=->,algebraic} after \psaxes. The normal mode in postscript for computations is reverse polish notation, not infix notation. Feb 1, 2017 at 17:43
• I've tried everything but it's just not working for me. I even copypasted everything you had into a new latex document and it didn't work. But luckily I found a solution. I'm now using the Desmos vector field generator and using my snipping tool, and inserting that as a picture. Feb 1, 2017 at 23:10