我使用图表工具GraphView()
生成过滤图。
g = gt.GraphView(g, vfilt= label_largest_component(g, directed=False))
原始图g
有10,069个顶点,而结果图有9,197个。但是,使用新的(已过滤的)图表,当我使用indeg = g.degree_property_map("in")
列出度数时,list(indeg.a)
中的元素总数仍为10,069。当使用9,197个节点绘制新的过滤图时,这会成为问题,其中顶点大小设置为indeg
的函数,主要是因为元素数量不匹配。
代码段看起来像这样
g = load_graph("ppnet.xml")
g = GraphView(g, vfilt=label_largest_component(g, directed=False))
indeg = g.degree_property_map("in")
indeg.a = np.sqrt(indeg.a) + 2
graph_draw(g, vertex_size = indeg, vertex_fill_color=indeg, pos = sfdp_layout(g),
vcmap=plt.cm.gist_heat, output_size=(400, 400), output="gc.png")
运行时,会提供以下ValueError
ValueError: operands could not be broadcast together with shapes (10069,) (9197,)
为GraphView
对象添加预期样式的正确方法是什么?
答案 0 :(得分:0)
找到解决方案。我首先创建了GraphView
对象的副本,然后清除了此副本的顶点。请注意,为了清晰起见,我引入了一个新变量g
,而不是保留变量名gc
。
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")