保存iGraph python数字?

时间:2017-04-20 18:59:01

标签: python matplotlib igraph

我使用igraph来生成使用igraph.plot()的网络图,但我只能弹出这些图,而不是实际保存而不手动保存每个图:

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')

它保存了一张空白图片。有什么提示吗?

2 个答案:

答案 0 :(得分: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')

答案 1 :(得分:0)

您还可以直接使用以下方式保存图表:

 DB::select(DB::raw("select * from (SELECT *, 6371
    * ACOS(COS(RADIANS(" . $lat . "))
    * COS(RADIANS(table_name.lat))
    * COS(RADIANS(table_name.lon)
    - RADIANS(" . $lon . "))
    + SIN(RADIANS(" . $lat . "))
    * SIN(RADIANS(table_name.lat))) AS distance
    FROM table WHERE status = 1 ) t where distance < 500"))

有关(某些)更多信息,请参见:https://igraph.org/python/doc/tutorial/tutorial.html#saving-plots