Main Content

Combine Contour Plot and Quiver Plot

Display contour lines and gradient vectors on the same plot.

Plot 10 contours of x e - x 2 - y 2 over a grid from -2 to 2 in thexandydirections.

[X,Y] = meshgrid(-2:0.2:2); Z = X .* exp(-X.^2 - Y.^2); contour(X,Y,Z,10)

Figure contains an axes object. The axes object contains an object of type contour.

Calculate the 2-D gradient ofZusing thegradientfunction. Thegradientfunction returnsUas the gradient in thex-direction andVas the gradient in they-direction. Display arrows indicating the gradient values using thequiverfunction.

[U,V] = gradient(Z,0.2,0.2); holdonquiver(X,Y,U,V) holdoff

Figure contains an axes object. The axes object contains 2 objects of type contour, quiver.

See Also

|