Next: 2.2 Three-dimensional plots
Up: 2.1.3 Other 2-D plots
Previous: 2.1.3.6 Function plots
  Contents
Contour plots are perhaps the easiest way to visualize two-dimensional
data. When the function we wish to plot depends on two independent
variables, like
, we need a third dimension in which to show the
function values--simple 2-D plots don't work.
Consider the function of two Gaussians defined in the
-
plane,
This
function defines an exponential ``hill'' centered at
and
an exponential ``valley'' centered at
. It's not too hard
to visualize what an ``elevation map'' of this function would look like.
Sketch your guess and then try the following.
% Plotting 2D data with contour
close all; clear all;
points = linspace(-2,2,40); % 40 equally spaced points between
[X Y] = meshgrid(points,points); % Create two arrays, x & y
Z = 1./exp((X-.5).^2+Y.^2)-1./exp((X+.5).^2+Y.^2);
contour(X,Y,Z,30) % The fourth argument says "draw 30 contours"
The command meshgrid is new. It fills the two arrays
and
with the
and
coordinates, respectively, for each point in the plot
(that is, each is a
array of 1600 numbers).
Also new is the ./ operator. It means to individually take
the inverse of each element of an array (i.e., don't take the inverse of
the array as a whole as if it is a matrix).
Next: 2.2 Three-dimensional plots
Up: 2.1.3 Other 2-D plots
Previous: 2.1.3.6 Function plots
  Contents
Gus Hart
2005-01-28