如何改变y轴的极限?“ylim”不工作

时间:2022-12-09 20:17:21

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.

当下面的图绘制出来的时候,NSS1就是一个常数集,等于一个在图的最上面的边界,因此很难看到。

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

如何改变y轴的长度,使NSS1能更清晰地显示出来?

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)

1 个解决方案

#1


1  

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.

如果您将ylim放在plot命令之前,那么它不能工作的原因是它没有与之相关的坐标轴对象。

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:

或者第二,你先绘图,命令自动生成一个坐标轴对象,然后你可以修改它的y限制:

plot(tau,NSS1,'-k*',tau,NSS2,'-k+',tau,NSS3,'-ko');
ylim([0, 1.2])

#1


1  

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.

如果您将ylim放在plot命令之前,那么它不能工作的原因是它没有与之相关的坐标轴对象。

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:

或者第二,你先绘图,命令自动生成一个坐标轴对象,然后你可以修改它的y限制:

plot(tau,NSS1,'-k*',tau,NSS2,'-k+',tau,NSS3,'-ko');
ylim([0, 1.2])