python+igrph。类型错误:打印不可用

2024-06-16 10:18:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用python笔记本,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,
       )

还有一个错误。我不知道怎么解决这个问题,谢谢!在

^{pr2}$

我想我已经安装了cairo,但它仍然不起作用


Tags: nameplotwidthlabelcairovsvertexlayout
2条回答

Python 3.7版本:

(/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
^{pr2}$

现在绘制(忽略警告):

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

  >>>

结果:

enter image description here

我不知道你的数据类型是什么ig.图()接受,但正如“TypeError”所示,某些参数的数据类型错误。 而且似乎你在用Python3,它应该是pip3而不是pip。 希望这对你有帮助。在

相关问题 更多 >