Difference between revisions of "MATLAB:Contour Plots"

From PrattWiki
Jump to navigation Jump to search
 
 
(One intermediate revision by the same user not shown)
Line 12: Line 12:
 
surfc(x, y, z)
 
surfc(x, y, z)
 
shading interp
 
shading interp
colormap gray
+
colormap copper
  
 
%% Contour plot
 
%% Contour plot
 
figure(2)
 
figure(2)
 
[C, H] = contour(x, y, z);
 
[C, H] = contour(x, y, z);
colormap gray
+
colormap copper
 
clabel(C, H)
 
clabel(C, H)
  
Line 23: Line 23:
 
figure(3)
 
figure(3)
 
[C, H] = contour(x, y, z, 5);
 
[C, H] = contour(x, y, z, 5);
colormap gray
+
colormap copper
 
clabel(C, H)
 
clabel(C, H)
  
Line 29: Line 29:
 
figure(4)
 
figure(4)
 
[C, H] = contour(x, y, z, [-.75:.25:.75]);
 
[C, H] = contour(x, y, z, [-.75:.25:.75]);
colormap gray
+
colormap copper
 
clabel(C, H)
 
clabel(C, H)
 
</source>
 
</source>
Line 42: Line 42:
 
surfc(x, y, z)
 
surfc(x, y, z)
 
shading interp
 
shading interp
colormap gray
+
colormap copper
  
 
%% Contour plot
 
%% Contour plot
 
figure(2)
 
figure(2)
 
[C, H] = contour(x, y, z);
 
[C, H] = contour(x, y, z);
colormap gray
+
colormap copper
 
clabel(C, H)
 
clabel(C, H)
  
Line 53: Line 53:
 
figure(3)
 
figure(3)
 
[C, H] = contour(x, y, z, 5);
 
[C, H] = contour(x, y, z, 5);
colormap gray
+
colormap copper
 
clabel(C, H)
 
clabel(C, H)
  
 
%% Contour plot specifying contour locations
 
%% Contour plot specifying contour locations
 
figure(4)
 
figure(4)
[C, H] = contour(x, y, z, [-.75:.25:.75]);
+
[C, H] = contour(x, y, z, [-1.75:.25:1.75]);
colormap gray
+
colormap copper
 
clabel(C, H)
 
clabel(C, H)
 
</source>
 
</source>

Latest revision as of 19:19, 30 September 2014

MATLAB is capable of making contour plots and also of labeling the contours using specified values. The following are some examples. Be sure to look up MATLAB:Plotting Surfaces first to understand how MATLAB makes surfaces.

Example 1: Pinched

[r, theta] = meshgrid(linspace(0,1,20), linspace(0, 2*pi, 50));
x = r.*cos(theta);
y = r.*sin(theta);
z = cos(theta).*r;

%% Surface with contours
figure(1)
surfc(x, y, z)
shading interp
colormap copper

%% Contour plot
figure(2)
[C, H] = contour(x, y, z);
colormap copper
clabel(C, H)

%% Contour plot specifying 5 contours
figure(3)
[C, H] = contour(x, y, z, 5);
colormap copper
clabel(C, H)

%% Contour plot specifying contour locations
figure(4)
[C, H] = contour(x, y, z, [-.75:.25:.75]);
colormap copper
clabel(C, H)

Example 2: Egg Crate

[x, y] = meshgrid(linspace(0, 3, 64), linspace(0, 1, 41));
z = -(1-cos(4*pi*y)).^(1/4).*(1-cos(2*pi*x)).^(1/4);

%% Surface plot with contours
figure(1)
surfc(x, y, z)
shading interp
colormap copper

%% Contour plot
figure(2)
[C, H] = contour(x, y, z);
colormap copper
clabel(C, H)

%% Contour plot specifying 5 contours
figure(3)
[C, H] = contour(x, y, z, 5);
colormap copper
clabel(C, H)

%% Contour plot specifying contour locations
figure(4)
[C, H] = contour(x, y, z, [-1.75:.25:1.75]);
colormap copper
clabel(C, H)