% Use color to display gradient and mesh (perspective view) to display % surface [x,y] = meshgrid([-2:0.2:2]); % specify x-y grid Z = x.*exp(-x.^2 - y.^2); % calculate function surf(x,y,Z,gradient(Z)) % plot surface and associate colors with gradient colorbar % plot colorbar for legend