【问题标题】:Graph-Tool GraphView Object图形工具 GraphView 对象
【发布时间】:2015-06-15 07:51:47
【问题描述】:

我有一个使用图表工具的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 的函数,主要是因为元素数量不匹配。

sn-p的代码是这样的

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 对象添加预期样式的正确方法是什么?

【问题讨论】:

    标签: python graph graph-tool


    【解决方案1】:

    找到了解决办法。我首先创建了GraphView 对象的副本,然后清除了这个副本 的顶点。请注意,为了清楚起见,我引入了一个新变量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")
    

    【讨论】:

    • 这确实是一个错误。我会尽快修复它。更好的解决方法是使用“g = Graph(g, prune=True)”而不是复制和清除。
    • 仅供参考,最近版本的图形工具中已修复此问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多