When you plot a linear plot on top of a surface plot, the linear plot disappears because both the surface plot and linear plot are located in the XY-plane (Z = 0). Hence, neither plot is actually on top. To avoid this issue, place the
surface plot at a -Z offset. For example, execute the following commands:
x = peaks;
h = surface(x);
hold on
z = get(h,'ZData');
set(h,'ZData',z-10)
plot(1:50,'color','r','linewidth',3)
The above code moves the surface plot by 10. You will be able to see the linear plot on the top of the surface plot now.
In the second scenario where instead of lowering the surface plot the line needs to be drawn in raised plane, a similar technique as above can be employed.
Following code first plots the surface and then draws a line in plane Z = max value in the surface plot so that the line sits on top of the surface.
x = peaks;
h = surface(x);
hold on
z_max = max(max(get(h,'Zdata')))
line(1:50,1:50,z_max*ones(1,50))
Best Answer