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}


%%%%%%%%%%% v(x, y) = =x² + y² - 1
\psset{unit=4cm, arrowinset=0.12}
    \psaxes[ticksize=0 4pt,axesstyle=frame,tickstyle=inner,subticks=20,
    \psVectorfield[linecolor=DarkOliveGreen3](-0.9,-0.9)(0.9,0.9){ x²+y²-1 }


enter image description here

  • 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} – ILoveJesus Feb 1 '17 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). – Bernard Feb 1 '17 at 17:30
  • Sorry I don't know how to type in latex form on this page so my comment looks like a mess – ILoveJesus Feb 1 '17 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. – Bernard Feb 1 '17 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. – ILoveJesus Feb 1 '17 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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