layout

Changes how a graph plot places its nodes.

Category: Mathematics > Graph and Network Algorithms

Syntax

layout(p, method)

Re-lays out the plot p with the named method.

layout(p, 'layered', 'Direction', dir)

Layered layout with the flow direction 'down', 'up', 'left' or 'right'.

Description

'circle' puts the nodes evenly on a circle. 'layered' arranges them in rows following the edge directions, which suits DAGs and trees. 'force' treats edges as springs, and 'subspace' is a related method for larger graphs.

The coordinates are stored in the XData and YData properties of the plot, so they can be read back or set directly.

Input arguments

p
GraphPlot object returned by plot(G).
method
'auto', 'circle', 'layered', 'force' or 'subspace'.

Example

Circle layout

G = graph([1 2 3 4], [2 3 4 1]);
p = plot(G);
layout(p, 'circle')
round([p.XData; p.YData], 3)
Output
ans = 2×4

     1     0    -1     0
     0     1     0    -1

Notes

Node positions match MATLAB for 'circle' and for simple 'layered' layouts. The 'force' and 'subspace' layouts are valid but place nodes differently.

See also

plot highlight labelnode graph