I'm trying to follow a simple tutorial on how the igraph library works but the first piece of code didn't show me a plotted graph as it should. I do have everything installed with pip. The code runs fine but doesn't show me anything.
from igraph import *
g = Graph()
g.add_vertices(4)
g.add_edges([(1, 2), (2, 3), (0, 3)])
plot(g)
CodePudding user response:
Not a perfect answer, since it should work and it doesn't, and I don't know how to make it work as is. You'll find some answers for similar question explaining how to fix (or install) cairo, so that it shows.
But I am used to avoid the problem by using matplotlib. Which usually works on all machines/OS.
So
from igraph import *
import matplotlib.pyplot as plt
g = Graph()
g.add_vertices(4)
g.add_edges([(1, 2), (2, 3), (0, 3)])
fig, ax=plt.subplots()
plot(g, target=ax)
plt.show()
So, it's your code; but it creates a matplotlib figure and axes, and then ask igraph to plot on this axes. Then plt.show
actually displays the window.