module documentation
igraph库中与布局相关的代码。
这个包包含了Layout对象的实现。
| 类 | |
表示图的布局。 |
| 函数 | _3d |
为给定布局算法的3D版本创建别名。 |
| 函数 | _layout |
根据布局算法返回图的布局。 |
| 函数 | _layout |
根据图的简单拓扑属性选择并运行合适的布局函数。 |
| 函数 | _layout |
包装现有的布局方法,以确保它返回一个布局而不是列表的列表。 |
| 函数 | _layout |
使用分层的Sugiyama布局放置顶点。 |
| 变量 | _layout |
未记录 |
根据布局算法返回图的布局。
未在此处指定的参数和关键字参数直接传递给布局算法。有关这些参数的说明,请参阅布局算法的文档。
此方法理解的已注册布局名称有:
- auto, automatic: automatic layout (see
Graph.layout_auto) - bipartite: bipartite layout (see
GraphBase.layout_bipartite) - circle, circular: circular layout (see
GraphBase.layout_circle) - dh, davidson_harel: Davidson-Harel layout (see
GraphBase.layout_davidson_harel) - drl: DrL layout for large graphs (see
GraphBase.layout_drl) - drl_3d: 3D DrL layout for large graphs (see
GraphBase.layout_drl) - fr, fruchterman_reingold: Fruchterman-Reingold layout (see
GraphBase.layout_fruchterman_reingold). - fr_3d, fr3d, fruchterman_reingold_3d: 3D Fruchterman- Reingold layout (see
GraphBase.layout_fruchterman_reingold). - grid: regular grid layout in 2D (see
GraphBase.layout_grid) - grid_3d: regular grid layout in 3D (see
GraphBase.layout_grid) - graphopt: the graphopt algorithm (see
GraphBase.layout_graphopt) - kk, kamada_kawai: Kamada-Kawai layout (see
GraphBase.layout_kamada_kawai) - kk_3d, kk3d, kamada_kawai_3d: 3D Kamada-Kawai layout (see
GraphBase.layout_kamada_kawai) - lgl, large, large_graph: Large Graph Layout (see
GraphBase.layout_lgl) - mds: multidimensional scaling layout (see
GraphBase.layout_mds) - random: random layout (see
GraphBase.layout_random) - random_3d: random 3D layout (see
GraphBase.layout_random) - rt, tree, reingold_tilford: Reingold-Tilford tree layout (see
GraphBase.layout_reingold_tilford) - rt_circular, reingold_tilford_circular: circular Reingold-Tilford tree layout (see
GraphBase.layout_reingold_tilford_circular) - sphere, spherical, circle_3d, circular_3d: spherical layout (see
GraphBase.layout_circle) - star: star layout (see
GraphBase.layout_star) - sugiyama: Sugiyama layout (see
Graph.layout_sugiyama)
| 参数 | |
| graph | 未记录 |
| layout | 要使用的布局。这可以是已注册的布局名称之一,也可以是一个可调用对象,该对象返回一个Layout对象或包含坐标的列表的列表。如果None,则使用plotting.layout配置键的值。 |
| *args | 未记录 |
| **kwds | 未记录 |
| 返回 | |
一个 Layout 对象。 | |
根据图的简单拓扑属性选择并运行合适的布局函数。
此函数尝试使用以下规则为图形选择合适的布局函数:
- If the graph has an attribute called layout, it will be used. It may either be a
Layoutinstance, a list of coordinate pairs, the name of a layout function, or a callable function which generates the layout when called with the graph as a parameter. - Otherwise, if the graph has vertex attributes called x and y, these will be used as coordinates in the layout. When a 3D layout is requested (by setting dim to 3), a vertex attribute named z will also be needed.
- Otherwise, if the graph is connected and has at most 100 vertices, the Kamada-Kawai layout will be used (see
GraphBase.layout_kamada_kawai()). - Otherwise, if the graph has at most 1000 vertices, the Fruchterman-Reingold layout will be used (see
GraphBase.layout_fruchterman_reingold()). - If everything else above failed, the DrL layout algorithm will be used (see
GraphBase.layout_drl()).
除了dim之外,此函数的所有参数都传递给所选的布局函数(以防我们需要调用某些布局函数)。
| 参数 | |
| graph | 未记录 |
| *args | 未记录 |
| dim | 指定我们是否希望获得2D或3D布局。 |
| 返回 | |
一个 Layout 对象。 | |
def _layout_sugiyama(graph, layers=None, weights=None, hgap=1, vgap=1, maxiter=100, return_extended_graph=False):
(source)
¶
使用分层的Sugiyama布局放置顶点。
这是一个分层布局,最适合用于有向无环图,尽管它也可以用于无向图或循环图。
每个顶点被分配到一个层,并且每一层被放置在一个水平线上。然后使用重心启发式算法对同一层内的顶点进行排列,以尽量减少边的交叉。
在跨越多个层的边上将添加虚拟顶点。因此,返回的布局包含比原始图中节点数量更多的行;这些额外的行对应于虚拟顶点。
参考文献:
- K Sugiyama, S Tagawa, M Toda: Methods for visual understanding of hierarchical system structures. IEEE Systems, Man and Cybernetics 11(2):109-125, 1981.
- P Eades, X Lin and WF Smyth: A fast effective heuristic for the feedback arc set problem. Information Processing Letters 47:319-323, 1993.
| 参数 | |
| graph | 未记录 |
| layers | 一个向量,指定每个顶点的非负整数层索引,或包含层索引的数值顶点属性的名称。如果为None,将自动确定分层。对于无向图,将提取一个生成树,并使用从度数最大的节点开始的广度优先搜索将顶点分配到层。对于有向图,通过使用Eades、Lin和Smyth的启发式方法反转近似反馈弧集中的边来打破循环,然后使用最长路径分层将顶点放置在层中。 |
| weights | 要使用的边权重。可以是序列、可迭代对象,甚至是边属性名称。 |
| hgap | 同一层顶点之间的最小水平间距。 |
| vgap | 层之间的垂直间隙。层索引将乘以vgap以获得Y坐标。 |
| maxiter | 在交叉减少步骤中执行的最大迭代次数。如果您觉得得到的边交叉过多,请增加此值。 |
| return | 指定是否还应返回添加了虚拟顶点的扩展图。当此参数为True时,结果将是一个包含布局和扩展图的元组。扩展图的前|V|个节点将对应于原始图的节点,其余的是虚拟节点。使用返回的布局和隐藏的虚拟节点绘制扩展图将产生一个与原始图相似的布局,但增加了边弯曲。扩展图还包含一个名为_original_eid的边属性,该属性指定了扩展图中边的原始图中边的ID。 |
| 返回 | |
| 计算出的布局,可能(通常也会)比顶点的数量有更多的行;剩余的行对应于分层步骤中引入的虚拟节点。当return_extended_graph为True时,它还将包含扩展图。 | |