How can I place a linear plot on top of a surface plot?
22 views (last 30 days)
Show older comments
I would like to know how to place a linear plot on top of a surface plot.
Accepted Answer
MathWorks Support Team
on 1 Sep 2010
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))
0 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!