xaxis/yaxis matlab 图中的线条

xaxis/yaxis lines in matlab plot

找不到这个:

我想在 X 轴和 Y 轴上绘制一条线,该线始终适合图形宽度或高度的 100%。

figure; hold on;
plot(rand(1,100));
line(xlim,[.5 .5],'Color','red');
line([50 50],ylim,'Color','red');
pause(.5)
xlim([1 200]);% lines should now automatically extend

使用 grid on 可以获得自动缩放的网格,但是似乎不可能只将网格限制在 X/Y 轴上。想法?

缩放后:

我更喜欢什么:

figure;
plot([1:10]);
set(gca, 'position', [0 0  1 1]);

函数xlineyline 在 MATLAB R2018b 中引入,并完全按照您的需要进行操作。

此外,可以向该行添加(文本)标签。