Graph drawn over axis box- error in clipping or graphics object order

11 views (last 30 days)
Hi,
I am adding some plots to a figure in a for loop. After the loop I add a box to the plot like this:
box on
set(gca,'FontSize',8,'FontWeight','bold','linewidth',1.3)
set(gca,'TickLength',[0.015, 0.01])
However, when exporting to pdf (I have also tried with tiff, svg, and emf, it's the same for all), at the points where the end of the plotted data meets the box of the figure, the plotted data lies on top as illustrated in this image:
My data extends outside of the plotted range, so Matlab is Clipping the data to fit it into the frame. However, when I want to have thick lines as shown in the image, the way this turns out doesn't look nice. I guess I either need to change the clipping, or to rearrange the order of the graphics objects, placing the box on top of the plot, but I haven't figured out how to do this. Anyone has an idea?
Thanks!

Accepted Answer

OCDER
OCDER on 15 Sep 2017
Edited: OCDER on 15 Sep 2017
This worked for me - set the axes Layer to Top:
set(gca, 'Layer', 'Top')

More Answers (1)

Daniel Fleischer
Daniel Fleischer on 8 Mar 2020
I am able to move the axes on top of my lines with set(gca, 'Layer', 'top'), but the line still shows past when it runs on the edge of the axis. Is there any way to prevent this besides making the axis thicker to cover it, or using thinner lines?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!