Perhaps overplotting the left and right axes (and the tick lines if you want the tick lines) will do what you want:
x = linspace(0, 1, 1000);
y = rand(1, 1000);
figure
plot(x, y)
ax = gca;
ax.Layer = 'bottom';
tl = ax.TickLength(1);
yaxtl = diff(xlim)*tl;
yt = ax.YTick;
hold on
plot([1 1]*min(xlim), ylim, '-k')
plot([1 1]*max(xlim), ylim, '-k')
plot([0; yaxtl]*ones(size(yt)), [yt; yt], '-k')
plot([max(xlim); max(xlim)-yaxtl]*ones(size(yt)), [yt; yt], '-k')
hold off
grid
This overplots the vertical axes and the tick lines, so neither will be hidden. If you don’t want the tick lines, don’t plot them.
Best Answer