image thumbnail

MATLAB Plot Gallery - Quiver Plot 2D

by

 

24 Feb 2012 (Updated )

Create a 2D quiver plot

Quiver_Plot_2D

This is an example of how to create a 2D quiver plot in MATLAB®.

Read about the quiver function in the MATLAB documentation.

For more examples, go to MATLAB Plot Gallery

% Create a grid of x and y points
[x, y] = meshgrid(-2:.2:2);

% Create the function z(x,y) and its gradient
z = x.*exp(-x.^2 - y.^2);
[dx, dy] = gradient(z, .2, .2);

% Create a contour plot of x, y, and z using the contour function
figure
contour(x,y,z)
hold on

% Create a quiver plot of x, y, and the gradients using the quiver function
q = quiver(x, y, dx, dy);

% Set the axis limits
xlim([-2 2])
ylim([-2 2])

% Add title and axis labels
title('x*exp(-x^2-y^2)')
xlabel('x')
ylabel('x')

Contact us