www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/SimpleContourPlotsExample.m

    %% Types of Contour Plots
% The |contour| and |contourf| functions display 2-D contour plots. The
% |contour3| function displays a 3-D contour plot. These functions can be called with
% three separate matrix inputs, |X|, |Y|, and |Z|, or they can be called with a
% single input |Z|. The data in |Z| is interpreted as heights with respect to a plane.  
%
% If you do not specify the number of contour lines to display, then these
% functions automatically determine the number based on the minimum and
% maximum data values in |Z|. To explicitly set the number of contour lines
% displayed, specify an integer value after matrix |Z|.
%
%% 2-D Contour Plot
% Create a 2-D contour plot with 20 contours.

% Copyright 2015 The MathWorks, Inc.

[X,Y,Z] = peaks; 
figure
contour(X,Y,Z,20)
title('2-D Contour Plot with 20 Contours')
%% Filled 2-D Contour Plot
% Create a filled 2-D contour plot with 20 contours.
[X,Y,Z] = peaks;
figure
contourf(X,Y,Z,20)
title('2-D Filled Contour Plot with 20 Contours')
%% 3-D Contour Plot
% Create a 3-D contour plot with 20 contours.
[X,Y,Z] = peaks;
figure
contour3(X,Y,Z,20)
title('3-D Contour Plot with 20 Contours')