user2305193
user2305193

Reputation: 2059

xaxis/yaxis lines in matlab plot

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?

bsdf

after scaling:

asdf

what I would prefer:

enter image description here

Upvotes: 1

Views: 118

Answers (2)

Cris Luengo
Cris Luengo

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

user1097111
user1097111

Reputation: 662

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

enter image description here

Upvotes: 0

Related Questions