Main Content

layout

Change layout of graph plot

Description

example

layout(H)changes the layout of graph plotHby using an automatic choice of layout method based on the structure of the graph. Thelayoutfunction modifies theXDataYDATAproperties ofH

example

layout(H,method)可选地指定布局方法。methodcan be'圆圈','force',“分层”,'subspace','force3', 或者'subspace3'

example

layout(H,method,姓名,Value)uses additional options specified by one or more name-value pair arguments. For example,layout(H,'force','Iterations',N)specifies the number of iterations to use in computing the force layout, andlayout(H,'layered','Sources',S)使用源节点的分层布局S包括在第一层中。

Examples

collapse all

Create and plot a graph using the'force'layout.

s = [1 1 1 1 1 6 6 6 6 6]; t = [2 3 4 5 6 7 8 9 10 11]; G = graph(s,t); h = plot(G,'Layout','force');

图包含一个轴对象。轴对象包含类型图形图的对象。

将布局更改为默认plotdetermines based on the structure and properties of the graph. The result is the same as usingplot(G)

布局(h)

图包含一个轴对象。轴对象包含类型图形图的对象。

Create and plot a graph using the“分层”layout.

s = [1 1 1 2 2 3 3 4 5 5 6 7]; t = [2 4 5 3 6 4 7 8 6 8 7 8]; G = graph(s,t); h = plot(G,'Layout',“分层”);

图包含一个轴对象。轴对象包含类型图形图的对象。

Change the layout of the graph to use the'subspace'method.

布局(h,'subspace')

图包含一个轴对象。轴对象包含类型图形图的对象。

Create and plot a graph using the“分层”布局方法。

s = [1 1 1 2 3 3 3 4 4]; t = [2 4 5 6 2 4 7 8 1]; G = digraph(s,t); h = plot(G,'Layout',“分层”);

图包含一个轴对象。轴对象包含类型图形图的对象。

Use thelayoutfunction to refine the hierarchical layout by specifying source nodes and a horizontal orientation.

布局(h,“分层”,'Direction','right','Sources',[1 4])

图包含一个轴对象。轴对象包含类型图形图的对象。

绘制具有多个组件的图,然后显示如何使用“用途”option to improve the visualization.

Create and plot a graph that has 150 nodes separated into many disconnected components. MATLAB® lays the graph components out on a grid.

s = [1 3 5 7 7 10:100]; t = [2 4 6 8 9 randi([10 100],1,91)]; G = graph(s,t,[],150); h = plot(G);

图包含一个轴对象。轴对象包含类型图形图的对象。

更新图对象的布局坐标,并指定“用途”as真的因此,组件围绕原点径向布置,为较大的组件分配了更多空间。

布局(h,'force',“用途”,真的)

图包含一个轴对象。轴对象包含类型图形图的对象。

Plot a graph using the'WeightEffect'name-value pair to make the length of graph edges proportional to their weights.

创建并绘制具有加权边缘的有向图。

s = [1 1 1 1 1 2 2 2 3 3 3 3 3]; t = [2 4 5 6 7 3 8 9 10 11 12 13 14]; weights = randi([1 20],1,13); G = graph(s,t,weights); p = plot(G,'Layout','force','EdgeLabel',G.Edges.Weight);

图包含一个轴对象。轴对象包含类型图形图的对象。

Recompute the layout of the graph using the'WeightEffect'name-value pair, so that the length of each edge is proportional to its weight. This makes it so that the edges with the largest weights are the longest.

布局(P,'force','WeightEffect','直接的')

图包含一个轴对象。轴对象包含类型图形图的对象。

Input Arguments

collapse all

输入图图, specified as a图形图目的。Use thegraph或者digraphfunctions to create a graph, and then useplotwith an output argument to return a图形图目的。

Example:H = plot(G)

布局方法,指定为表中的选项之一。该表还列出了兼容的名称值对,以进一步完善每个布局方法。

选项 Description Layout-Specific Name-Value Pairs
'auto'(default)

Automatic choice of layout method based on the size and structure of the graph.

'圆圈'

Circular layout. Places the graph nodes on a circle centered at the origin with radius 1.

'中心'— Center node in circular layout

'force'

力量-directed layout[1]。Uses attractive forces between adjacent nodes and repulsive forces between distant nodes.

'迭代'— Number of force-directed layout iterations

'WeightEffect'— Effect of edge weights on layout

“用途”- 带有多个组件的布局的重力切换

'xstart'— Startingx- 节点的坐标

'YStart'— Startingy- 节点的坐标

“分层”

Layered layout[2],[3],[4]。将图节点放入一组层中,从而揭示层次结构。默认情况下,层向下进展(有向无环图指向下方的箭头)。

'Direction'- 层的方向

'Sources'- 在第一层中包含的节点

'Sinks'- 在最后一层中包含的节点

'AssignLayers'- 层分配方法

'subspace'

子空间embedding layout[5]。将图节点绘制在高维嵌入式子空间中,然后将位置投射回2-D。默认情况下,子空间维度为100或节点总数,以较小者为准。

'方面'— Dimension of embedded subspace

'force3' 3-D力定向布局。

'迭代'— Number of force-directed layout iterations

'WeightEffect'— Effect of edge weights on layout

“用途”- 带有多个组件的布局的重力切换

'xstart'— Startingx- 节点的坐标

'YStart'— Startingy- 节点的坐标

'zstart'— Startingz- 节点的坐标

'subspace3' 3-D subspace embedding layout.

'方面'— Dimension of embedded subspace

Example:布局(H,“分层”)

Example:layout(H,'force3','Iterations',10)

Example:layout(H,'subspace','Dimension',50)

姓名-Value Arguments

Specify optional comma-separated pairs of姓名,Valuearguments.姓名is the argument name and价值是相应的值。姓名must appear inside quotes. You can specify several name and value pair arguments in any order as姓名1,Value1,...,NameN,ValueN

Example:布局(H,“子空间”,“ Dimension”,200)
力量

collapse all

Number of force-directed layout iterations, specified as the comma-separated pair consisting of'迭代'和a positive scalar integer.

This option is available only whenmethodis'force'或者'force3'

Example:layout(H,'force','Iterations',250)

Data Types:单身的|double|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64

边缘权重对布局的影响,指定为逗号分隔对'WeightEffect'这表中的值之一。如果两个节点之间存在多个边缘(如在每个方向上有边缘的有向图中,或一个多编码),则在计算之前将权重求和。'WeightEffect'

This option is available only whenmethodis'force'或者'force3'

价值

Description

'none'(default)

Edge weights do not affect the layout.

'直接的'

边缘长度与边缘的重量成正比,G.Edges.Weight。Larger edge weights produce longer edges.

'inverse'

Edge length is inversely proportional to the edge weight,1./G.Edges.Weight。较大的边缘重量会产生较短的边缘。

Example:layout(H,'force','WeightEffect','inverse')

重力切换用于具有多个组件的布局,指定为逗号分隔对“用途”和either'off','on',真的, 或者false。一个值'on'相当于真的, 和'off'相当于false

By default, MATLAB®在网格上列出具有多个组件的图形。网格可以掩盖较大组件的细节,因为它们的空间与较小的组件相同。和“用途”set to'on'或者真的径向安放,多个组件ly around the origin. This layout spreads out the components in a more natural way, and provides more space for larger components.

This option is available only whenmethodis'force'或者'force3'

Example:布局(h,'force',“ usegravity”,true)

Data Types:char|logical

启动节点的X坐标, specified as the comma-separated pair consisting of'xstart'和a vector of node coordinates. Use this option together with'YStart'指定2D起始坐标(或使用'YStart''zstart'要指定3-D启动坐标)之前的力定向算法更改节点位置。

This option is available only whenmethodis'force'或者'force3'

Example:layout(H,'force','XStart',x,'YStart',y)

Data Types:单身的|double|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64

Starting y-coordinates for nodes, specified as the comma-separated pair consisting of'YStart'和a vector of node coordinates. Use this option together with'xstart'指定2D起始坐标(或使用'xstart''zstart'要指定3-D启动坐标)之前的力定向算法更改节点位置。

This option is available only whenmethodis'force'或者'force3'

Example:layout(H,'force','XStart',x,'YStart',y)

Example:layout(H,'force','XStart',x,'YStart',y,'ZStart',z)

Data Types:单身的|double|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64

启动节点的z坐标,指定为逗号分隔对,由'zstart'和a vector of node coordinates. Use this option together with'xstart''YStart'to specify the startingx,y, 和z节点在迭代之前进行坐标,以更改节点位置。

This option is available only whenmethodis'force3'

Example:layout(H,'force','XStart',x,'YStart',y,'ZStart',z)

Data Types:单身的|double|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64

Layered

collapse all

方向of layers, specified as the comma-separated pair consisting of'Direction'和either'down','up','剩下'或者'right'。For directed acyclic (DAG) graphs, the arrows point in the indicated direction.

This option is available only whenmethodis“分层”

Example:layout(H,'layered','Direction','up')

在第一层中包含的节点,指定为逗号分隔对'Sources'和one or more node indices or node names.

该表显示了通过其数字节点索引或通过其节点名称引用一个或多个节点的不同方法。

Form 单节点 多个节点
节点索引

Scalar

Example:1

Vector

Example:[1 2 3]

节点名称

Character vector

Example:'一个'

字符向量的单元格数

Example:{'a''b''c'}

字符串标量

Example:"A"

String array

Example:["A" "B" "C"]

This option is available only whenmethodis“分层”

Example:layout(H,'layered','Sources',[1 3 5])

在最后一层中包含的节点,指定为逗号分隔对'Sinks'和one or more node indices or node names.

This option is available only whenmethodis“分层”

Example:layout(H,'layered','Sinks',[2 4 6])

Layer assignment method, specified as the comma-separated pair consisting of'AssignLayers'和one of the options in this table.

选项 Description
'auto'(default) Node assignment uses either'asap'或者'alap', whichever is more compact.
'asap' As soon as possible. Each node is assigned to the first possible layer, given the constraint that all its predecessors must be in earlier layers.
'alap' As late as possible. Each node is assigned to the last possible layer, given the constraint that all its successors must be in later layers.

This option is available only whenmethodis“分层”

Example:layout(H,'layered','AssignLayers','alap')

子空间

collapse all

嵌入式子空间的尺寸,指定为逗号分隔对'方面'和a positive scalar integer.

  • The default integer value ismin([100, numnodes(G)])

  • 为了'subspace'布局,整数必须大于或等于2。

  • 为了'subspace3'布局,整数必须大于或等于3。

  • In both cases, the integer must be less than the number of nodes.

This option is available only whenmethodis'subspace'或者'subspace3'

Example:layout(H,'subspace','Dimension',d)

Data Types:单身的|double|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64

Circle

collapse all

Center node in circular layout, specified as the comma-separated pair consisting of'中心'这表中的值之一。

价值 Example
Scalar node index 1
Character vector node name '一个'
字符串标量节点名称 "A"

This option is available only whenmethodis'圆圈'

Example:layout(H,'circle','Center',3)将节点放在中心。

Example:layout(H,'circle','Center','Node1')places the node named'Node1'at the center.

Tips

  • Use theLayoutname-value pair to change the layout of a graph when you plot it. For example,plot(G,'Layout','circle')plots the graphG带有圆形布局。

  • When using the'force'或者'force3'layout methods, a best practice is to use more iterations with the algorithm instead of usingXStart,YStart, 和ZSTARTto restart the algorithm using previous outputs. The result of executing the algorithm with 100 iterations is different in comparison to executing 50 iterations, and then restarting the algorithm from the ending positions to execute 50 more iterations.

References

[1] Fruchterman, T., and E. Reingold,. “Graph Drawing by Force-directed Placement.”Software — Practice & Experience。卷。21(11),1991年,第1129–1164页。

[2]Gansner, E., E. Koutsofios, S. North, and K.-P Vo. “A Technique for Drawing Directed Graphs.”IEEE软件工程交易。卷。19, 1993, pp. 214–230.

[3] Barth, W., M. Juenger, and P. Mutzel. “Simple and Efficient Bilayer Cross Counting.”Journal of Graph Algorithms and Applications。第8卷(2),2004年,第179-194页。

[4] Brandes, U., and B. Koepf. “Fast and Simple Horizontal Coordinate Assignment.”LNCS。卷。2265, 2002, pp. 31–44.

[5] Y. Koren. “Drawing Graphs by Eigenvectors: Theory and Practice.”Computers and Mathematics with Applications。卷。49, 2005, pp. 1867–1888.

在R2015B中引入