关节点

此示例展示了如何使用 igraph.GraphBase.articulation_points() 计算并可视化图中的 关节点。有关桥的示例,请参见 Bridges

import igraph as ig
import matplotlib.pyplot as plt

首先,我们构建一个图。这个例子展示了图公式的使用:

g = ig.Graph.Formula(
    "0-1-2-0, 3:4:5:6 - 3:4:5:6, 2-3-7-8",
)

现在我们准备将关节点作为一个顶点序列来查找

articulation_points = g.vs[g.articulation_points()]

最后,我们可以绘制图表

fig, ax = plt.subplots()
ig.plot(
    g,
    target=ax,
    vertex_size=30,
    vertex_color="lightblue",
    vertex_label=range(g.vcount()),
    vertex_frame_color = ["red" if v in articulation_points else "black" for v in g.vs],
    vertex_frame_width = [3 if v in articulation_points else 1 for v in g.vs],
    edge_width=0.8,
    edge_color='gray'
)
plt.show()
articulation points

脚本的总运行时间: (0 分钟 0.331 秒)

Gallery generated by Sphinx-Gallery