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?
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')
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With