MATLAB: Is the line plotting beyond the box

bugissue plottingplot

I have been encountering this problem lately, and I don't know how to solve it. Using the plot function, the line plotted would go beyond the box. Any idea how to fix this? See figure below in the top right corner.
P.S. I have just upgraded my Matlab from 2016a to 2017b, and the issue was there before.

Best Answer

This behavior is governed by the "Clipping" property of the axes. It must have been set to "off" somehow. For example,

x = 1:0.1:11;
y = x;
figure
plot(x,y)
xlim([0 10])
set(gca,'Clipping','off')

yields

Try

set(gca,'Clipping','on')