# subplot

Create axes in tiled positions.

## Syntax

* subplot(m, n, p)
* subplot('mnp')
* subplot('Position', pos)
* ax = subplot(...)

## Input argument

* m - Number of grid rows: scalar positive integer.
* n - Number of grid columns: scalar positive integer.
* p - Grid position for new axes: scalar or vector.
* pos - Custom position for new axes: \[left bottom width height].

## Output argument

* ax - a graphics object: axes type.

## Description

subplot(n, m, p) divides the current figure into a 2-dimensional grid.

Each of which can contain a plot of some kind.

## Examples

```matlab
f = figure();
X = linspace(-pi, pi) * 2;
Y1 = cos(X) .* exp(-2 * X);
Y2 = cos(X * 2) .* exp(-2 * X);
Y3 = cos(X * 3) .* exp(-2 * X);
Y4 = cos(X * 4) .* exp(-2 * X);

subplot(4, 1, 1)
plot(X, Y1,'b');
subplot(4, 1, 2)
plot(X, Y2, 'r');
subplot(4, 1, 3);
plot(X, Y3, 'g');
subplot(4, 1, 4);
plot(X, Y4, 'k');
```

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

```matlab
f = figure();
t = 0 : (2 * pi/100) : (2 * pi);
X = cos(t * 2) .* (2 + sin(t * 3) * 0.3);
Y = sin(t * 2) .* (2 + sin(t * 3) * 0.3);
Z = cos(t * 3) * 0.3;
subplot(2, 2, 1)
surf(peaks());
axis equal
view(3)
subplot(2, 2, 2);
plot(t, X);
subplot(2, 2, 3);
plot(t, Y);
subplot(2, 2, 4);
plot(t, Z);
```

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

## See also

[plot](plot), [axes](axes).

## History

| Version | Description     |
| ------- | --------------- |
| 1.0.0   | initial version |

## Author

Allan CORNET
