是否有可能在cygwin上绘制iGraph情节?

时间:2015-05-31 15:17:39

标签: python plot cygwin igraph

虽然在 Ubuntu上生成iGraph图没有问题,但我在 cygwin上遇到以下错误:

$ python
Python 2.7.8 (default, Jul 28 2014, 01:34:03)
[GCC 4.8.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from igraph import Graph, plot
>>>
>>> g = Graph([(0,1), (0,2), (2,3), (3,4), (4,2), (2,5), (5,0), (6,3), (5,6)])
>>> g.vs["name"] = ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]
>>>
>>> layout = g.layout("kk")
>>> plot(g, layout = layout)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/igraph/drawing/__init__.py", line 475, in plot
    result.show()
  File "/usr/lib/python2.7/site-packages/igraph/drawing/__init__.py", line 327, in show
    "on this platform: %s" % plat)
NotImplementedError: showing plots is not implemented on this platform: CYGWIN_NT-6.1-WOW
>>>

是否有人成功在 cygwin上制作iGraph图?

编辑: documentation州:

  

绘图取决于提供Python的pycairo库   绑定到流行的开罗图书馆。这意味着,如果你不这样做   如果安装了pycairo,你将无法使用绘图   能力。

我会检查py2cairo安装是否有问题。


请注意,其他iGraph功能在 cygwin:

上运行正常
$ python
Python 2.7.8 (default, Jul 28 2014, 01:34:03)
[GCC 4.8.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from igraph import Graph, plot
>>> g = Graph()
>>> print(g)
IGRAPH U--- 0 0 --
>>> g = Graph([(0,1), (0,2), (2,3), (3,4), (4,2), (2,5), (5,0), (6,3), (5,6)])
>>> g.vs["name"] = ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]
>>> g.vs["age"] = [25, 31, 18, 47, 22, 23, 50]
>>> g.vs["gender"] = ["f", "m", "f", "m", "f", "m", "m"]
>>> g.es["is_formal"] = [False, False, True, True, True, False, True, False, False]
>>> g.es[0]["is_formal"] = True
>>> g.es[0]
igraph.Edge(<igraph.Graph object at 0xffcb542c>, 0, {'is_formal': True})
>>> g["date"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'Attribute does not exist'
>>> g["date"] = "2015-05-31"
>>> g["date"]
'2015-05-31'
>>> g.degree()
[3, 1, 4, 3, 2, 3, 2]
>>> g.edge_betweenness()
[6.0, 6.0, 4.0, 2.0, 4.0, 3.0, 4.0, 3.0, 4.0]
>>> g.vs[2].degree()
4
>>>

环境:

  • Windows 7
  • Cygwin CYGWIN_NT-6.1-WOW Ron 2.0.1(0.287 / 5/3)
  • iGraph 0.7.1

1 个答案:

答案 0 :(得分:0)

您的计算机上的py2cairo可能没有任何问题,但您可以自行测试。尝试plot(g, "test.png", layout=layout) - 这会将绘图保存到文件中而不是显示它。您看到的错误消息是由igraph引发的,因为它无法弄清楚如何指示操作系统在窗口中显示PNG文件(保存图表)。

用于显示绘图的命令存储在名为apps.image_viewer的配置变量中。您可以按如下方式更改它:

>>> from igraph import Configuration
>>> cfg = Configuration.instance()
>>> cfg["apps.image_viewer"] = "start"

这可能会起到作用,因为如果您将PNG文件的名称传递给它,Windows上的start命令应该打开默认图像查看器。如果有效,您可以通过将以下内容写入cfg.filename指向的文件来保留更改:

[apps]
image_viewer=start

对于它的价值,应该找出在特定操作系统上使用哪个图像查看器(如果apps.image_viewer键不存在)的igraph部分位于{{1}在名为igraph/configuration.py的函数中。此函数使用get_platform_image_viewer()来确定您正在使用的操作系统。如果你能告诉我你的Python中platform.system()打印的内容,我将提交一个补丁,使igraph以与Windows相同的方式处理Cygwin。