Reputation: 3832
I am using the contourf function to create a contour plot:
I would like to get grid lines to appear on top of the plane that shows the contours.
I came across one solution, but it only works in 2D (that is when you view the contour plot in 2D) which involved the following two commands:
grid on
set(gca,'layer','top');
However, the grid lines do not appear when viewing the axes in 3D. Is there any way to do this simply?
Upvotes: 4
Views: 8932
Reputation: 26069
You can accomplish that using line
object manipulation that re-writes the grid lines, or a small FEX tool called gridxy .
For example, lets recreate a figure that has the same properties:
figure
set(gcf,'Renderer','OpenGL')
%# plot surface and contour
Z = peaks;
surf(Z), hold on
[~,h] = contourf(Z); %# get handle to contourgroup object
%# change the ZData property of the inner patches
hh = get(h,'Children'); %# get handles to patch objects
for i=1:numel(hh)
zdata = ones(size( get(hh(i),'XData') ));
set(hh(i), 'ZData',-10*zdata)
end
And add the extra grid lines:
v = get(gca);
hg=gridxy(get(gca,'XTick'),get(gca,'YTick'), 'Color',[1,1,1]*0.25,'Linestyle',':');
set(hg,'Zdata',repmat(v.ZLim(1)+eps,[1 numel(get(hg,'Ydata'))]));
However, is there a reason not to use surfc
? For example:
Z = peaks(20);
surfc(Z);
view(-45, 20);
Upvotes: 3