tiledlayout

Creates a grid of tiles in the figure to hold several plots.

Category: Graphics > Formatting and Annotation

Syntax

tiledlayout(m, n)

Creates a layout with m rows and n columns.

tiledlayout('flow')

Creates a layout that grows as tiles are added.

tiledlayout(___, Name, Value)

Sets options such as 'TileSpacing' and 'Padding', each 'loose', 'compact' or 'tight'.

t = tiledlayout(___)

Returns the layout object.

Description

The layout is empty until tiles are filled with nexttile, one axes per tile. Compared with subplot, the layout object manages the gaps itself, can share a title and axis labels for the whole grid (title(t, ...), xlabel(t, ...)), and lets a tile span several rows or columns.

Calling tiledlayout again in the same figure replaces the previous layout.

Input arguments

m, n
Number of rows and columns of tiles.
TileSpacing, Padding
Spacing between tiles and around the grid. The default is 'loose'.

Output arguments

t
Layout object with properties such as GridSize, TileSpacing and Padding.

Example

A two-by-two grid

t = tiledlayout(2, 2, 'TileSpacing', 'compact');
for k = 1:4
  nexttile
  plot(1:5, (1:5).^k)
end
title(t, 'Powers')
t.GridSize
t.TileSpacing
Output
ans = 1×2

     2     2
ans = 'compact'

See also

nexttile tilenum tilerowcol subplot sgtitle