Reputation: 413
I am using igraph to generate network plots using igraph.plot(), but I can only get these to pop up, not actually save without manually saving each figure:
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()
When I try to do the following, where plt is 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')
It saves an empty picture. Any tips?
Upvotes: 4
Views: 4334
Reputation: 643
You can also save the plot directly with:
igraph.plot(g, "name.png")
For (some) more information see: https://igraph.org/python/doc/tutorial/tutorial.html#saving-plots
Upvotes: 1
Reputation: 13041
igraph.plot
does not create a matplotlib figure, so there is nothing to save (unlike other packages such as networkx
). This should work:
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')
Upvotes: 5