Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change limits of y-axis? `ylim` does not work

When the graph below is plotted, NSS1 which is simply a constant set equal to one is right on the top border of the graph and thus hard to see.

How can I change the length of the y-axis to say 1.2 so that the NSS1 can be seen more clearly?

lambda=5;
tau=0:30;

tau(1)=0.000001;

NSS1=1*ones(1,31);
NSS2=(1-exp(-tau/lambda))./(tau/lambda);
NSS3=((1-exp(-tau/lambda))./(tau/lambda)-exp(-tau/lambda));

%ylim([0, 1.2])
plot(tau,NSS1,'-k*',tau,NSS2,'-k+',tau,NSS3,'-ko');
xlabel('t = 0 to 30y', 'FontSize',30)
ylabel('yield','FontSize',30)
like image 252
Bazman Avatar asked Oct 15 '25 15:10

Bazman


1 Answers

The reason why ylim doesn't work if you put it before the plot command is that there is no axes object it can relate to.

So there are two options:

First, you create an axes object and hold it with hold on, so the upcoming plot is plotted on the same axis.

ax = axes; hold on;
ylim([0, 1.2])

plot(tau,NSS1,'-k*',tau,NSS2,'-k+',tau,NSS3,'-ko');

or second, you plot first, the command automatically generates an axes object and you can modify its y-limits afterwards:

plot(tau,NSS1,'-k*',tau,NSS2,'-k+',tau,NSS3,'-ko');
ylim([0, 1.2])
like image 183
Robert Seifert Avatar answered Oct 18 '25 07:10

Robert Seifert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!