2017-04-12 51 views
0

我想使用Python筆記本,IGRAPH包繪製的圖片,例如代碼是在這裏(我認爲這是正確的)python + igrph。類型錯誤:繪圖不可

!pip install cairocffi 
import cairocffi as cairo 

corlor = [] 
for i in g.vs['name']: 
    if set([i]) < set(degree_15): 
     corlor.append('red') 
    elif set([i]) < set(degree_30): 
     corlor.append('rgba(255,0,0,0.5)') 
    elif set([i]) < set(degree_60): 
     corlor.append('orange') 
    else: 
     corlor.append('yellow') 
ig.plot(g, 
     #'C:\Users\Vincent Du\Desktop\degree_plot.jpg', 
     layout=geometry_layout, 
     vertex_label=g.vs['name'], 
     scale=1.0, 
     vertex_color=corlor, 
     vertex_frame_width=0.5, 
     edge_width=0.05, 
     vertex_label_size=ig.rescale(g.degree(),out_range=(1,12)), 
     vertex_size=ig.rescale(g.degree(),out_range=(5,25)), 
     bbox=(1200,800), 
     margin = 10, 
     ) 

而且還是一個錯誤。我不知道如何解決這個問題,謝謝!

--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
<ipython-input-120-73eb4de82dd4> in <module>() 
    21   vertex_size=ig.rescale(g.degree(),out_range=(5,25)), 
    22   bbox=(1200,800), 
---> 23   margin = 10, 
    24  ) 

//anaconda/lib/python3.5/site-packages/igraph/drawing/__init__.py in plot(obj, target, bbox, *args, **kwds) 
    444   bbox = BoundingBox(bbox) 
    445 
--> 446  result = Plot(target, bbox, background=kwds.get("background", "white")) 
    447 
    448  if "margin" in kwds: 

//anaconda/lib/python3.5/site-packages/igraph/drawing/__init__.py in __init__(self, target, bbox, palette, background) 
    115   """ 
    116   self._filename = None 
--> 117   self._surface_was_created = not isinstance(target, cairo.Surface) 
    118   self._need_tmpfile = False 
    119 

//anaconda/lib/python3.5/site-packages/igraph/drawing/utils.py in __getattr__(self, _) 
    394 
    395  def __getattr__(self, _): 
--> 396   raise TypeError("plotting not available") 
    397  def __call__(self, _): 
    398   raise TypeError("plotting not available") 

TypeError: plotting not available 

我想我已經安裝了開羅,但它仍然無法正常工作

回答

0

我不知道究竟是什麼數據類型的ig.plot()有,但作爲「類型錯誤」表明,一些你的參數有錯誤的數據類型。 也似乎你使用的是Python3,它應該是pip3而不是pip。 希望這可以幫助你。