# daspect

Control data unit length along each axis.

## 📝 Syntax

* daspect(ratio)
* d = daspect()
* daspect('auto')
* daspect('manual')
* m = daspect('mode')
* daspect(ax, ...)

## 📥 Input argument

* ratio - Three-element vector of positive values specifying the relative lengths of data units along the x, y, and z axes.
* 'auto' - Set the data aspect ratio mode to automatic.
* 'manual' - Set the data aspect ratio mode to manual.
* 'mode' - Query the current data aspect ratio mode ('auto' or 'manual').
* ax - Target axes object. If not specified, uses current axes.

## 📤 Output argument

* d - Three-element vector representing the current data aspect ratio.
* m - Current data aspect ratio mode: 'auto' or 'manual'.

## 📄 Description

daspect controls the relative lengths of data units along the x, y, and z axes.

daspect(ratio) sets the data aspect ratio for the current axes. ratio is a three-element vector of positive values. For example, \[1 2 3] means the length from 0 to 1 along the x-axis equals the length from 0 to 2 along the y-axis and 0 to 3 along the z-axis.

d = daspect() returns the current data aspect ratio as a three-element vector.

daspect('auto') sets the data aspect ratio mode to automatic, enabling the axes to choose the ratio.

daspect('manual') sets the mode to manual and uses the ratio stored in the axes.

m = daspect('mode') returns the current mode, either 'auto' or 'manual'.

daspect(ax, ...) operates on the axes specified by ax instead of the current axes.

Setting the data aspect ratio disables the stretch-to-fill behavior of the axes.

## 💡 Examples

stretch X relative to Y

```matlab

plot(-5:5, (-5:5).^2)
daspect([2 1 1])
```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-30fb7ceab2bafb2e83c6a598377fb807e99015be%2Fdaspect_1.svg?alt=media) Set different data unit lengths for each axis

```matlab

sphere(40);
daspect([2 1 0.5])

```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-47d7fbabbfe7408afeb951bab9f4bb48768eddc6%2Fdaspect_2.svg?alt=media) Switch between manual and auto aspect ratio modes

```matlab

[X, Y, Z] = sphere(30);
surf(X, Y, Z)
daspect([2 1 1])
disp(daspect('mode'))
daspect('auto')
disp(daspect('mode'))

```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-e143dbc94d6c9bffb4b59cbd378809614a55ab73%2Fdaspect_3.svg?alt=media) Query the current data aspect ratio

```matlab

[x, y] = meshgrid(-2:0.2:2);
z = x .* exp(-x.^2 - y.^2);
surf(x, y, z)
d = daspect()
disp(d)

```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-33c6c1591cdcae901e80e033ee881fbb63b58b40%2Fdaspect_4.svg?alt=media)

## 🔗 See also

[pbaspect](https://nelson-9.gitbook.io/nelson/markdown/en/graphics/pbaspect), [axis](https://nelson-9.gitbook.io/nelson/markdown/en/graphics/axis), [xlim](https://nelson-9.gitbook.io/nelson/markdown/en/graphics/xlim), [ylim](https://nelson-9.gitbook.io/nelson/markdown/en/graphics/ylim), [zlim](https://nelson-9.gitbook.io/nelson/markdown/en/graphics/zlim).

## 🕔 History

| Version | 📄 Description  |
| ------- | --------------- |
| 1.16.0  | initial version |
