Why do my CONTOUR lines disappear when I shade my plot using the SHADING function in MATLAB 7.1 (R14SP3)?
19 views (last 30 days)
Show older comments
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
MathWorks Support Team
on 27 Jun 2009
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');
0 Comments
More Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!