在Python中使用igraph绘制杉山布局

时间:2019-05-24 20:04:29

标签: python igraph

我想通过使用Sugiyama布局(iGraph中有一种方法)来优化图形布局,并绘制此优化图形。

我正在使用Jupyter和Python 3。

from igraph import *

gs = Graph()
gs.add_vertices(13)
gs.vs["name"] = ["1","2","3","4","5","6","7","8","9","10","11","12","13"]
gs.add_edges([(0,1),(0,2),(1,3),(1,4),(2,5),(2,3),(2,7),(3,9),(5,8),
              (6,9),(7,11),(8,10),(9,10),(10,11),(4,11),(11,12)])
print(gs)



g1=gs.layout_sugiyama(layers=None, weights=None, hgap=1, vgap=1, maxiter=100, return_extended_graph=True)
print(g1)
plot(g1)   

我在笔记本上收到以下错误(无任何图):

IGRAPH UN-- 13 16 --
+ attr: name (v)
+ edges (vertex names):
1--2, 1--3, 2--4, 2--5, 3--6, 3--4, 3--8, 4--10, 6--9, 7--10, 8--12, 9--11,
10--11, 11--12, 5--12, 12--13
(<Layout with 13 vertices and 2 dimensions>, <igraph.Graph object at 0x7fb9645617c8>)
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345                 return method()
    346             return None
    347         else:

~/anaconda3/lib/python3.6/site-packages/igraph/drawing/__init__.py in _repr_svg_(self)
    346         context = cairo.Context(surface)
    347         # Plot the graph on this context
--> 348         self.redraw(context)
    349         # No idea why this is needed but python crashes without
    350         context.show_page()

~/anaconda3/lib/python3.6/site-packages/igraph/drawing/__init__.py in redraw(self, context)
    260             plotter = getattr(obj, "__plot__", None)
    261             if plotter is None:
--> 262                 warn("%s does not support plotting" % obj)
    263             else:
    264                 if opacity < 1.0:

TypeError: not all arguments converted during string formatting

<igraph.drawing.Plot at 0x7fb96451e780>

我该如何解决这个问题?

0 个答案:

没有答案