Reputation: 2059
couldn't find this:
I would like to plot a line on X and Y axis that always fits to 100% to the width or height of the figure.
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
with grid on
it's possible to get a grid that scales automatically, however it seems impossible to only limit the grid to the X/Y axes. Ideas?
after scaling:
what I would prefer:
Upvotes: 1
Views: 118
Reputation: 60809
The functions xline
and yline
were introduced in MATLAB R2018b, and do exactly as you need.
Furthermore, it is possible to add a (text) label to the line.
Upvotes: 2