2

I want to use python notebook, igraph package to draw picture, example code is here( which i think is right)

!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,
       )

And there's still an error. I don't know how to fix this problem, thanks!

---------------------------------------------------------------------------
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

I think i have installed cairo, but it still not work

kkjoe
  • 745
  • 2
  • 8
  • 18

4 Answers4

2

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

Now plots (ignore the warning):

(/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>

  >>>

Result:

enter image description here

Victoria Stuart
  • 4,610
  • 2
  • 44
  • 37
1

Try use an older version of python-igraph (e.g., 0.9.6). Note that you should uninstall and install before importing the igraph module.

First,

!pip uninstall igraph -y
!pip uninstall python-igraph -y
!pip install python-igraph==0.9.6
!pip install cairocffi

Then,

import igraph
print(igraph.__version__)
% 0.9.6
Lorry
  • 382
  • 2
  • 7
0

If you are using Windows, the most probably you have downloaded wheel and installed python-igraph from Unofficial Windows Binaries. This worked perfect for me using something like this:

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

Plotting, however, was not working for me too because I haven't installed pycairo neither cairocffi. Also, neither pip install pycairo nor pip install cairocffi was not working for me. It took a really lot time for me to understand that one needs to download wheel of pycairo and install it using

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

Lesson learnt.

mathfux
  • 5,759
  • 1
  • 14
  • 34
  • 1
    As of 2021, in the latest release of `python-igraph == 0.9.8` no unofficial binaries needed. `pip install python-igraph` and `pip install pycairo` works perfect. – mathfux Nov 28 '21 at 15:29
-3

I don't know what exactly data types your ig.plot() takes, but as the "TypeError" suggests, some of your args have wrong data type. And also it seems you are using Python3, it should be pip3 instead of pip. Hope this helps you.