# pbaspect

Control relative lengths of each axis in the plot box.

## 📝 Syntax

* pbaspect(ratio)
* pb = pbaspect()
* pbaspect('auto')
* pbaspect('manual')
* m = pbaspect('mode')
* pbaspect(ax, ...)

## 📥 Input argument

* ratio -

Three-element vector of positive values specifying the relative lengths of the x, y, and z axes in the plot box.

* 'auto' -

Set the plot box aspect ratio mode to automatic.

* 'manual' -

Set the plot box aspect ratio mode to manual.

* 'mode' -

Query the current plot box aspect ratio mode ('auto' or 'manual').

* ax -

Target axes object. If not specified, uses current axes.

## 📤 Output argument

* pb -

Three-element vector representing the current plot box aspect ratio.

* m -

Current plot box aspect ratio mode: 'auto' or 'manual'.

## 📄 Description

pbaspect controls the relative lengths of the x, y, and z axes in the plot box.

pbaspect(ratio) sets the plot box aspect ratio for the current axes. ratio is a three-element vector of positive values. For example, \[3 1 1] means the x-axis is three times as long as the y- and z-axes.

pb = pbaspect() returns the current plot box aspect ratio as a three-element vector.

pbaspect('auto') sets the plot box aspect ratio mode to automatic, enabling the axes to choose the ratio.

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

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

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

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

## 💡 Examples

Use equal axis lengths

```matlab

x = linspace(0,10,100);
y = sin(x);
plot(x, y)
pbaspect([1 1 1])

```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-d62c20963f09440f782e2d5bb5d345da510deaf7%2Fpbaspect_1.svg?alt=media) Use different axis lengths

```matlab

[x, y] = meshgrid(-2:0.2:2);
z = x .* exp(-x.^2 - y.^2);
surf(x, y, z)
pbaspect([2 1 1])
disp(pbaspect('mode'))

```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-b24c052284fbceab8cfe0f2dd9eb469e9695153e%2Fpbaspect_2.svg?alt=media) Revert back to default plot box aspect ratio

```matlab

X = rand(100,1);
Y = rand(100,1);
Z = rand(100,1);
scatter3(X, Y, Z)
pbaspect([3 2 1])
pbaspect('auto')

```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-3ddbf4c9447af53c5b871defd21ba088abd1e3b7%2Fpbaspect_3.svg?alt=media) Query plot box aspect ratio

```matlab

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

```

![](https://160667757-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LdPvJ6mJve3gz5MU4d1%2Fuploads%2Fgit-blob-33c6c1591cdcae901e80e033ee881fbb63b58b40%2Fpbaspect_4.svg?alt=media) Set plot box aspect ratio for specific axes object

```matlab

f = figure();
ax1 = subplot(2, 1, 1);
plot(ax1, 1:10)
ax2 = subplot(2, 1, 2);
plot(ax2, 1:10)
pbaspect(ax2, [2 2 1])

```

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

## 🔗 See also

[daspect](https://nelson-9.gitbook.io/nelson/markdown/en/graphics/daspect), [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 |
