在图形工具中仅绘制最大的连接子图



在图形工具中,有没有办法只绘制最大的连接子图?我目前有一个大的连接子图和一些我不是特别感兴趣的较小的连接子图。我不确定如何在绘制子图之前找到它们,所以如果有 graph_tool 提供的方法,我会很感兴趣。

如果有帮助,这是来源:https://github.com/jvdheyden/DBS/blob/master/projekt/phase3/main.py

您可以使用GraphView过滤掉最大的组件,然后对其进行绘制。

import graph_tool.all as gt
# Load a disconnected graph
g = gt.collection.data["netscience"]
# Extract the largest component
largest_comp = gt.GraphView(g, vfilt = gt.label_largest_component(g))
# Draw the largest component
gt.graph_draw(largest_comp, output = "largest_comp.svg")

这样,在绘制后需要它时,您不会丢失整个图形。

最新更新