How can I draw a vector field of a function with tikz?

For example f(x,y) = 4x2 + y2 - 5

What I want to plot


1 Answer 1


Using pgfplots you can draw a vector field with the option quiver. This option creates a 3d vector field, but you can choose to view it 'from above' adding the view={0}{90} to the axis options.

Something like this:

\usepackage {pgfplots}

  view     = {0}{90}, % for a view 'from above'
  domain   = -3:3,
  y domain = -3:3,
  xtick    = {-3,...,3},
  ytick    = {-3,...,3},
\addplot3[blue, quiver={u=8*x, v=2*y, scale arrows=0.05}, samples=16, -latex] (x,y,0);
\addplot3[red, thick, domain=0:360, samples=41] ({0.5*sqrt(5)*cos(x)},{sqrt(5)*sin(x)},0);

enter image description here

  • Thank you so much!
    – Huhu
    Aug 11, 2021 at 6:30
  • @Juan Castano: I think the red one is the ellipse 4x^2 + y^2 =5 where the speed (velocity) of solutions of the ODE y' = 4x^2 + y^2 - 5 is vanishing. It seems to contradict with your figure. Am I wrong something?
    – Black Mild
    Nov 15, 2021 at 5:12
  • 1
    @BlackMild, Well, the original post asked for the representation of a vector field but gave the equation of a scalar field. What I did was to assume (I don't know if correctly) that what was needed was to represent the gradient. And the ellipse, in that case, would be a level set. It looks quite similar to the original drawing, but it may be wrong. Nov 15, 2021 at 6:04
  • @JuanCastaño Yeap! I think there is some incorrect information from OP
    – Black Mild
    Nov 15, 2021 at 9:53

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.