MATLAB Axis Limits

Set Axis Limits Using
axis()
Function in MATLAB 
Set Axis Limits Using
xlim()
Function in MATLAB 
Set Axis Limits Using
ylim()
Function in MATLAB 
Set Axis Limits Using
zlim()
Function in MATLAB 
Set Axis Limits Using
set()
Function in MATLAB
In this tutorial, we will discuss how to set the axis limits using the axis()
, xlim()
, ylim()
, zlim()
, and set()
function in MATLAB.
Set Axis Limits Using axis()
Function in MATLAB
To set the axis limits of a plot in MATLAB, you can use the axis()
function. You can put the minimum and maximum value of each axis in this function. To set the xaxis and yaxis limit, see the code below.
axis([xMin xMax yMin yMax])
In the above code, xMin
is the minimum value of the xaxis, xMax
is the maximum value of the xaxis, yMin
is the minimum value of the yaxis, and yMax
is the maximum value of the yaxis. If you have a threeaxis plot and want to set the axes limits, you can also set them using the axis()
function. See the code below.
axis([xMin xMax yMin yMax zMin zMax])
Here, zMin
is the minimum value of the zaxis, and zMax
is the maximum value of the zaxis. If you want the axis limits to be equal to each other, you can use the equal
command after plotting the variables. See the code below.
axis equal
Set Axis Limits Using xlim()
Function in MATLAB
If you want to set only the limit of the xaxis, you can use the xlim()
function after plotting the variables. See the code below.
xlim([xMin xMax])
In the above code, xMin
is the minimum value of the xaxis and xMax
is the maximum value of the xaxis.
Set Axis Limits Using ylim()
Function in MATLAB
If you want to set only the limit of the yaxis, you can use the ylim()
function after plotting the variables. See the code below.
ylim([yMin yMax])
In the above code, yMin
is the minimum value of the yaxis and yMax
is the maximum value of the yaxis.
Set Axis Limits Using zlim()
Function in MATLAB
If you want to set only the limit of the zaxis, you can use the zlim()
function after plotting the variables. See the code below.
zlim([zMin zMax])
In the above code, zMin
is the minimum value of the zaxis and zMax
is the maximum value of the xaxis.
Set Axis Limits Using set()
Function in MATLAB
If you want to set only the limit of the xaxis, yaxis, or zaxis, you can use the set()
function after plotting the variables. To set the limit of an axis, you have to pass that axis’s name and its limit in this function. See the code below.
set(gca,'axisName',[Min Max])
In the above code, axisName
is the name of the axis, Min
is the minimum value of the defined axis, and Max
is the maximum value of the defined axis. To set the limits of the xaxis, use the function given below.
set(gca,'XLim',[1.5 1.5])
In the above code, we have set the limit of the xaxis from 1.5 to 1.5.