# MATLAB Axis Limits

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 x-axis and y-axis limit, see the code below.

``````axis([xMin xMax yMin yMax])
``````

In the above code, `xMin` is the minimum value of the x-axis, `xMax` is the maximum value of the x-axis, `yMin` is the minimum value of the y-axis, and `yMax` is the maximum value of the y-axis. If you have a three-axis 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 z-axis, and `zMax` is the maximum value of the z-axis. 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 x-axis, 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 x-axis and `xMax` is the maximum value of the x-axis.

## Set Axis Limits Using `ylim()` Function in MATLAB

If you want to set only the limit of the y-axis, 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 y-axis and `yMax` is the maximum value of the y-axis.

## Set Axis Limits Using `zlim()` Function in MATLAB

If you want to set only the limit of the z-axis, 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 z-axis and `zMax` is the maximum value of the x-axis.

## Set Axis Limits Using `set()` Function in MATLAB

If you want to set only the limit of the x-axis, y-axis, or z-axis, 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 x-axis, use the function given below.

``````set(gca,'XLim',[-1.5 1.5])
``````

In the above code, we have set the limit of the x-axis as -1.5 to 1.5.

Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

## Related Article - MATLAB Plot

• MATLAB Plot Color Map
• MATLAB Plot Line Styles