drawing rectangle on surface plots
Show older comments
Hi,
I draw a rectangle on a surface plot with the rectangle command however only some part of the rectangle is displayed. What could be the problem with this?
subplot(1,2,2)
surface(c/20,b/20,dset2(120:180,1:s(1)), 'EdgeAlpha',0)
set(gca,'XTickLabel',[])
set(gca,'YTickLabel',[])
xlim([0 2.5]);
ylim([-1.5 1.5]);
hold on;
rectangle('Position',[0,-0.5,2,1],...
'LineWidth',2,'LineStyle','-')
daspect([1,1,1])
hold on;
Answers (1)
Walter Roberson
on 5 Sep 2011
0 votes
rectangle() is a 2D object only, and is not certain to show up at all unless the viewpoint is from directly above or directly below.
There are other MATLAB handle-graphic objects that are 2D only as well, such as image objects; the same difficulty applies to them.
line and lineseries objects such as are produced by plot() can have this same difficulty if only X and Y was specified, but fortunately these line objects can be made 3D by set()'ing their ZData property to be non-empty.
If you need your shape to be visible at other angles, you need to draw it as a patch() or surface(). (For images, usually the easiest approach is to texture-map them on to a patch or surface object.)
Categories
Find more on Lighting, Transparency, and Shading 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!