ylim
设置或查询 y 轴限制
Syntax
ylim(limits)
yl = ylim
ylim auto
ylim manual
m = ylim('mode')
___ = ylim(target,___)
Description
ylim(limits) 设置当前坐标轴或图表的 y 轴限制。将限制指定为窗体的两个元素向量 [ymin ymax], 其中 ymax 大于 ymin。
例子:
Plot a line and set the y-axis limits to range from -2 to 2.
x = linspace(0,10);
y = sin(x);
plot(x,y)
ylim([-2 2])
yl = ylim 将当前限制返回为两个元素向量。
例子:
创建随机数据的散点图。返回 y 轴限制的值。
x = randn(50,1);
y = randn(50,1);
scatter(x,y)
ylim auto 设置自动模式, 使轴能够确定 y 轴限制。限制跨越绘制数据的范围。如果更改限制, 然后希望将其设置回默认值, 请使用此选项。此命令将轴的 YLimMode 属性设置为 "auto"。
ylim manual 设置手动模式, 冻结当前值的限制。如果要在使用 thehold 命令将新数据添加到坐标轴时保留当前限制, 请使用此选项。此命令将轴的 YLimMode 属性设置为 "手动"。
例子:Maintain Current y-Axis Limits
First, plot a line.
x = linspace(0,10);
y = sin(x);
plot(x,y)
Set the y-axis limits mode to manual so that the limits to not change. Use hold on to add a second plot to the axes.
ylim manual
hold on
y2 = 2*sin(x);
plot(x,y2)
hold off
The y-axis limits do not update to incorporate the new plot.
Switch back to automatically updated limits by resetting the mode to automatic.
ylim auto
___ = ylim(target,___) 使用由目标指定的轴或图表, 而不是当前坐标轴。将目标指定为以前任何语法的第一个输入参数。如果原始语法支持输出参数, 则可以包括输出参数。在模式输入周围使用单引号, 例如, ylim (target , "auto")。
例子:
Create a figure with two subplots and assign the Axes objects to the variables ax1 and ax2. Plot the same data in each subplot. Set the y-axis limits for the bottom subplot by specifying ax2 as the first input to ylim.
创建一副拥有两个子图的图像,并把 Axes对象赋值给两个变量 ax1和ax2。在两幅子图中画同样的数据。通过将 ax2 指定为 ylim 的第一个输入, 为底部子图设置 y 轴限制。
clc
clear
close all
x = linspace(0,10,1000);
y = sin(10*x).*exp(.5*x);
ax1 = subplot(2,1,1);
plot(x,y)
ax2 = subplot(2,1,2);
plot(x,y)
ylim(ax2,[-10 10])
再送几个案例:
Use Semiautomatic y-Axis Limits
Create a surface plot and show only y values greater than 0. Specify the minimum y-axis limit as 0 and let MATLAB choose the maximum limit.
意思是画一个surface图,仅仅显示y大于0的部分:
[X,Y,Z] = peaks;
surf(X,Y,Z)
ylim([0 inf])
如果不加限制,也就是全都是auto模式:
clc
clear
close all
[X,Y,Z] = peaks;
surf(X,Y,Z)
只关注y轴就可以看出区别了。
Set Limits for y-Axis with Dates
Create a horizontal bar chart with dates along the y-axis. Set the y-axis limits to range from June 1, 2014 to June 10, 2014.
意思是创建一个水平条形图,日期位于y轴,设置y轴的限制为从 June 1, 2014 to June 10, 2014.
t = datetime(2014,06,1) + caldays(0:20);
y = rand(21,1);
barh(t,y)
tstart = datetime(2014,06,1);
tend = datetime(2014,06,10);
ylim([tstart tend])
如果不设限制:
clc
clear
close all
t = datetime(2014,06,1) + caldays(0:20);
y = rand(21,1);
barh(t,y)
xlim的用法和ylim几乎一模一样,这里仅仅给出英文版介绍,就不详述了。zlim也一样,就不说了。
xlim
Set or query x-axis limits
Syntax
xlim(limits)
xl = xlim
xlim auto
xlim manual
m = xlim('mode')
___ = xlim(target,___)
Description
xlim(limits) sets the x-axis limits for the current axes or chart. Specify limits as a two-element vector of the form [xmin xmax], where xmax is greater than xmin.
xl = xlim returns the current limits as a two-element vector.
xlim auto sets an automatic mode, enabling the axes to determine the x-axis limits. The limits span the range of the plotted data. Use this option if you change the limits and then want to set them back to the default values. This command sets the XLimMode property for the axes to 'auto'.
xlim manual sets a manual mode, freezing the limits at the current values. Use this option if you want to retain the current limits when adding new data to the axes using thehold on command. This command sets the XLimMode property for the axes to 'manual'.
m = xlim('mode') returns the current x-axis limits mode, which is either 'auto' or 'manual'. By default, the mode is automatic unless you specify limits or set the mode to manual.
___ = xlim(target,___) uses the axes or chart specified by target instead of the current axes. Specify target as the first input argument for any of the previous syntaxes. You can include an output argument if the original syntax supports an output argument. Use single quotes around the mode inputs, for example, xlim(target,'auto').
本文同步分享在 博客“李锐博恩”(CSDN)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。