# xlim

Set or query *x*-axis limits

## Syntax

## Description

### Specify Limits

`xlim(`

sets the `limits`

)*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`

.

`xlim(`

specifies the
limit method MATLAB`limitmethod`

)^{®} uses for automatic limit selection. Specify the limit method as
`"tickaligned"`

, `"tight"`

, or
`"padded"`

. MATLAB sets the `XLimitMethod`

property of the axes to
the value you specify. The limit method is not supported for standalone
visualizations.

You can specify the `limitmethod`

argument without
parentheses. For example, `xlim tight`

enables tight
*x*-axis limits.

`xlim(`

specifies automatic
or manual limit selection. The `limitmode`

)`limitmode`

can have either of
two values:

`"auto"`

— Enable automatic limit selection. MATLAB selects the limits based on the range of your data and the value of the`XLimitMethod`

property of the axes. If you plot into the axes multiple times, the limits update to encompass all the data.`"manual"`

— Freeze the*x*-axis limits at their current value.

You can specify the `limitmode`

argument without
parentheses. For example, `xlim auto`

enables automatic limit
selection.

### Query Limits

returns
the current `limmethod`

= xlim("method")*x*-axis limits method, which can be
`'tickaligned'`

, `'tight'`

, or
`'padded'`

.

returns the current
`limmode`

= xlim("mode")*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.

### Specify Target Axes or Chart

`___ = xlim(`

uses
the axes or standalone visualization specified by `target`

,___)`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 quotes around
the mode inputs, for example, `xlim(target,"auto")`

.

## Examples

## Input Arguments

## Output Arguments

## Algorithms

The `xlim`

function sets and queries several
axes properties related to the *x*-axis limits.

`XLim`

— Property that stores the*x*-axis limits.`XLimMode`

— Property that stores the*x*-axis limits mode. When you set the*x*-axis limits, this property changes to`"manual"`

.`XLimitMethod`

— Property that controls how the*x*-axis limits are calculated when the`XLimMode`

property is set to`"auto"`

.

## Version History

**Introduced before R2006a**