Issue
Similarly to this question, I wanted to draw multiple graphs from a single ipython-notebook cell with the following code:
[1]:
%matplotlib inline
import igraph # it is `pip install python-igraph` on py2
import matplotlib.pyplot as plt
import numpy as np
[2]:
# draws a graph successfully
igraph.plot(igraph.Graph.Erdos_Renyi(10, .5))
[3]:
for p in np.arange(.3, .8, .1):
g = igraph.Graph.Erdos_Renyi(10, p)
igraph.plot(g)
How can I show multiple graphs from [3]
cell on a notebook?
It seems I could use this solution if I wanted to draw some matplotlib charts like this:
[4]:
for p in np.arange(.3, .8, .1):
g = igraph.Graph.Erdos_Renyi(10, p)
plt.loglog(sorted(g.degree(), reverse=True), marker='o')
plt.show()
But this is not applicable to igraph graphs AFAICS. Is there some way to convert igraph.drawing.Plot
to a more matplotlib familiar object?
Solution
I ended up to a solution like this:
from IPython.core.display import display, SVG
for p in np.arange(.3, .8, .1):
g = igraph.Graph.Erdos_Renyi(10, p)
print(p)
display(SVG(igraph.plot(g)._repr_svg_()))
Same can be used for any object that supports _repr_svg_()
or _repr_png_()
so this is not python-igraph limited so far.
Answered By - Ebrahim Byagowi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.