previous: graphing 2D data
next: plot parametric function

18a: Display array data using a color map

1. Create a 32×32 array Z
2. Define z(x,y) = exp(-((x/15)2 + (y/12)2))
        for x in [-5,26] and y in [-10,10]
3. Display as a ``density'' plot
4. Create and use color map for hue in [0,0.67]

Mathematica:

(1,2)
elev = Table[ Exp[-((x/15)^2+(y/12)^2)],
      {x,-5,26,21./31.},
      {y,-10,10,20./31.}]

(3)
ListDensityPlot[elev];

(4)
ListDensityPlot[elev,Mesh->False,
      ColorFunction->(Hue[0.67#]&)];

Matlab:

(1)
x = linspace(-5,26,32);
y = linspace(-10,10,32);

(2)
Z=zeros(32,32);
for j=1:32
  for k=1:32
    Z(k,j) = exp(-((x(j)/15)^2 + (y(k)/12)^2));
  end
end

(3)
imagesc(x,y,Z);

(4)
hsv = ones(256,3);   % hue/saturation/value
for j=1:256
  hsv(j,1) = 0.0027 * (j-1);
end
set(gcf,'Colormap',hsv2rgb(hsv));

Maple: IDL: