2017-04-20 42 views
0

我使用的igraph使用igraph.plot()来生成网络图,但我只能得到这些流行起来,没有真正节省,而无需手动保存每个人物:保存iGraph python数字?

def testplot(graph): 
    graph.vs['label'] = graph.vs['name'] 
    x = plot(graph, vertex_size=[a/5 for a in graph.betweenness()], 
      layout = graph.layout('grid')) 
    x.show() 

当我尝试做以下,其中plt是matplotlib:

def testplot(graph, name): 
    graph.vs['label'] = graph.vs['name'] 
    igraph.plot(graph, vertex_size=[a/5 for a in graph.betweenness()], 
       layout = graph.layout('grid')) 
    plt.savefig(name + '_allyBetweenness.png') 

它保存一个空的图片。有小费吗?

回答

1

igraph.plot不会创建matplotlib图形,所以没有什么可以保存的(不像其他包,如networkx)。这应该工作:

def testplot(graph, name): 
    graph.vs['label'] = graph.vs['name'] 
    out = igraph.plot(graph, vertex_size=[a/5 for a in graph.betweenness()], 
         layout = graph.layout('grid')) 
    out.save(name + '_allyBetweenness.png') 
+0

谢谢你,那正是我正在寻找! –