【问题标题】:python+igrph. TypeError: plotting not available蟒蛇+图形。 TypeError:绘图不可用
【发布时间】:2017-09-08 18:36:08
【问题描述】:

我想用python notebook,igraph包画图,示例代码在这里(我认为是对的)

!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

我想我已经安装了 cairo,但还是不行

【问题讨论】:

    标签: python error-handling igraph


    【解决方案1】:

    Python 3.7 venv:

    (/home/victoria/venv/py37)$ python
    
      Python 3.7.3 (default, Mar 26 2019, 21:43:19) 
      [GCC 8.2.1 20181127] on linux
      Type "help", "copyright", "credits" or "license" for more information.
    
      >>> from igraph import *
      >>> g = Graph.Famous("petersen")
      >>> plot(g)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        ...
      TypeError: plotting not available
    
    (/home/victoria/venv/py37)$ pip install cairocffi
      ...
      Successfully installed cairocffi-1.0.2 cffi-1.12.3 pycparser-2.19
    

    现在绘图(忽略警告):

    (/home/victoria/venv/py37)$ python
    
      Python 3.7.3 (default, Mar 26 2019, 21:43:19) 
      [GCC 8.2.1 20181127] on linux
      Type "help", "copyright", "credits" or "license" for more information.
      >>> from igraph import *
      >>> g = Graph.Famous("petersen")
      >>> plot(g)
    
      (gthumb:31636): Gtk-WARNING **: 14:43:58.342: Failed to register client: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: Method "RegisterClient" with signature "ss" on interface "org.xfce.Session.Manager" doesn't exist
      <igraph.drawing.Plot object at 0x7f1810e36e80>
    
      >>>
    

    结果:

    【讨论】:

      【解决方案2】:

      如果您使用的是 Windows,您很可能已经从 Unofficial Windows Binaries 下载了 wheel 并安装了 python-igraph。这对我来说非常适合使用这样的东西:

      pip install python_igraph-0.7.1.post6-cp37-cp37m-win_amd64.whl
      

      但是,绘图对我也不起作用,因为我还没有安装 pycairocairocffi。此外,pip install pycairopip install cairocffi 都不适合我。我花了很长时间才明白需要下载 pycairo 的轮子并使用它进行安装

      pip install pycairo-1.19.0-cp37-cp37m-win_amd64.whl
      

      经验教训。

      【讨论】:

      • 截至 2021 年,在最新版本的 python-igraph == 0.9.8 中不需要非官方的二进制文件。 pip install python-igraphpip install pycairo 完美运行。
      【解决方案3】:

      我不知道您的 ig.plot() 究竟采用什么数据类型,但正如“TypeError”所暗示的,您的某些 args 的数据类型错误。 而且您似乎使用的是 Python3,它应该是 pip3 而不是 pip。 希望对您有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-12-15
        • 1970-01-01
        • 2021-10-08
        • 1970-01-01
        • 2019-04-14
        • 2021-09-20
        • 1970-01-01
        • 2022-01-09
        相关资源
        最近更新 更多