图形工具图形视图对象

2024-09-24 22:32:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用图形工具的GraphView()生成的过滤图。在

g = gt.GraphView(g, vfilt= label_largest_component(g, directed=False))

原始图g有10069个顶点,而结果图有9197个顶点。但是,使用新的(过滤)图,当我使用indeg = g.degree_property_map("in")列出in度时,list(indeg.a)中的元素总数仍然是10069。当绘制带有9197个节点的新过滤图时,这就成了问题,其中顶点大小被设置为indeg的函数,这主要是因为元素数量不匹配。在

代码片段如下所示

^{pr2}$

当运行时,给出如下ValueError

ValueError: operands could not be broadcast together with shapes (10069,) (9197,) 

GraphView对象添加预期样式的正确方法是什么?在


Tags: 工具ingtfalse图形元素labelcomponent
1条回答
网友
1楼 · 发布于 2024-09-24 22:32:31

找到了解决办法。我首先创建了GraphView对象的副本,然后清除了这个copy的顶点。注意,为了清晰起见,我引入了一个新变量gc,而不是保留变量名g。在

g = load_graph("ppnet.xml")
gc = GraphView(g, vfilt=label_largest_component(g, directed=False)).copy()
gc.purge_vertices()
indeg = gc.degree_property_map("in")
indeg.a = np.sqrt(indeg.a)+2
graph_draw(gc, vertex_size = indeg, vertex_fill_color=indeg, pos = sfdp_layout(gc),
    vcmap=plt.cm.gist_heat, output_size=(400, 400), output="gc.png")

相关问题 更多 >