Matlab - surf and contour3, clipping order?

那年仲夏 提交于 2019-12-02 01:29:25

After some digging in the doc, I have found the best solution.

The clipping order is specified at the axes level.

A complete MWE to have the contours always on top of the surface is below:

fig = figure;
ax = get(gca);
ax.SortMethod = 'childorder'; % this is the important line
surf(x,y,z);
[c,h] = contour3(x,y,z,'LevelList',[0 : 0.1 : 1],'Color','k');
clabel(c,h,[0 : 0.1 : 1]);

You can try working on the properties of the contour patches: increase the linewidth of the patch' edge: the default value is 0.5: a linewidth of 1 or 1.5 should be enough.

On the same way you can set the properties of the lavels generated by clabel: you can set the font size and font weight to make them more visible. Also you can set the number of label to be added by specifying the labelspacing property.

An interesting option could also be to manually set the labels: this can be done by specifying the manaul property in the clabel call.

In the following you find an example based on the peaks surface:

[x,y,z]=peaks
surf(x,y,z);
shading interp
hold on
[c,h] = contour3(x,y,z,[-10:1:10]);
set(h(:),'linewidth',1,'edgecolor','k')
clabel(c,h,[-10:1:10],'fontsize',9,'fontweight','bold','rotation',0,'labelspacing',99);
% clabel(c,h,'manual','fontsize',9,'fontweight','bold','rotation',0);

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!