Why do my CONTOUR lines disappear when I shade my plot using the SHADING function in MATLAB 7.1 (R14SP3)?

I want to label and apply shading to my CONTOUR plot. When I execute the following commands in MATLAB 7.1 (R14SP3), my labels remain, but my contour lines disappear.
[X,Y] = meshgrid(-2:.2:2,-2:.2:3);
Z = X.*exp(-X.^2-Y.^2);
pcolor(X,Y,Z);
caxis([-2 3]);
hold on
[C,h] = contour(X,Y,Z,'k');
clabel(C,h,'FontSize',8,'color','k');
shading interp

 Accepted Answer

The SHADING function controls the color shading of surface and patch graphics objects. The contour lines generated by the CONTOUR function are patch objects. Therefore if the SHADING command is executed after the CONTOUR command, the color of contour lines, which are patch objects gets controlled by the SHADING function.
To workaround this issue, execute the SHADING command, before the CONTOUR command as explained below:
[X,Y] = meshgrid(-2:.2:2,-2:.2:3);
Z = X.*exp(-X.^2-Y.^2);
pcolor(X,Y,Z);
caxis([-2 3]);
shading interp
hold on
[C,h] = contour(X,Y,Z,'k');
clabel(C,h,'FontSize',8,'color','k');

More Answers (0)

Products

Release

R14SP1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!