pygraphviz 1.5默认边缘没有箭头? [英] pygraphviz 1.5 default edge no arrow?

查看:143
本文介绍了pygraphviz 1.5默认边缘没有箭头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里使用此转盘已将pygraphviz 1.5更新为

I have updated to pygraphviz 1.5 using this wheel here Installing pygraphviz on Windows 10 64-bit, Python 3.6.

我遇到了问题.

import pygraphviz as pgv

G = pgv.AGraph()

G.add_node('a')
G.add_node('b')
G.add_edge('a', 'b')
g_string = G.string()

print(g_string)

给我

strict digraph {
    a -- b;
}

在先前版本1.3上运行的相同代码给了我

while the same code ran on previous version 1.3 gives me

strict digraph {
    a -> b;
}

我什至尝试过

G.add_edge('a', 'b', arrowhead="normal")给出a -- b [arrowhead=normal];,但没有箭头绘制.

G.add_edge('a', 'b', arrowhead="normal") which gives a -- b [arrowhead=normal]; but draws with no arrowheads.

我正在运行graphviz 2.38. python 2.7上的pygraphviz 1.3. pygraphviz 1.5在python 3.6上.

I'm running graphviz 2.38. pygraphviz 1.3 on python 2.7. pygraphviz 1.5 on python 3.6.

推荐答案

我首先要指出,为了使该示例正常工作,仅凭 PyGraphviz不够 模块已安装(请检查 [SO]:在Windows 10 64位Python 3.6(@CristiFati的答案))上安装pygraphviz,但还需要 Graphviz 版本,以及 PyGraphviz 使用其工具之一(称为 nop ).
它可以下载,无论如何我选择构建它(对于 32bit ,但这无关紧要).

I want to start by pointing out that in order for this example to work, it's not enough to have the PyGraphviz module installed (check [SO]: Installing pygraphviz on Windows 10 64-bit, Python 3.6 (@CristiFati's answer)), but a version of Graphviz is required as well, as PyGraphviz uses one of its tools (called nop).
It is available for download, anyway I chose to build it (for 32bit, but that's not relevant).

我还用2个 .whl s进行了测试:

Also, I tested with 2 .whls:

  • 一个(我为) Python 3.6 (64位)
  • 构建的
  • 一个为 Python 2.7 (64位)
  • 构建的
  • One (that I've) built for Python 3.6 (64 bit)
  • One built for Python 2.7 (64 bit)

由于我有可能不得不修改它们(出于调试目的),所以我没有pip install它们,而是将它们解压缩为 cwd (这需要一些额外的代码):

Since there was the possibility of me having to modify them (for debugging purposes), I didn't pip install them, but rather unpacked them in cwd (which required some extra code):

[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q055196206]> dir /b
code00.py
pygraphviz131_27
pygraphviz15_36

[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q055196206]> tree /a
Folder PATH listing for volume Work
Volume serial number is 3655-6FED
E:.
+---pygraphviz131_27
|   \---pygraphviz
|       \---tests
\---pygraphviz15_36
    \---pygraphviz
        \---tests

code00.py :

#!/usr/bin/env python3

import sys


# @TODO - cfati: The 5 lines below are because I unpacked the 2 `.whl`s in the current dir, instead of `pip install`ing them
maj, min = sys.version_info[:2]
if maj == 3 and min == 6:
    sys.path.insert(0, "pygraphviz15_36")
elif maj == 2 and min == 7:
    sys.path.insert(0, "pygraphviz131_27")
# @TODO end

import pygraphviz as pgv


def main():
    print(pgv)
    g = pgv.AGraph(directed=len(sys.argv) > 1)
    g.add_node("a")
    g.add_node("b")
    g.add_edge("a", "b")
    #print(dir(g))
    g_string = g.string()  # Nice var name, btw :)
    print(g_string)


if __name__ == "__main__":
    print("Python {:s} on {:s}\n".format(sys.version, sys.platform))
    main()

输出:

[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q055196206]> set PATH=%PATH%;e:\Work\Dev\Fati\WinBuild\graphviz\src\graphviz\Release\Graphviz\bin

[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q055196206]> "e:\Work\Dev\VEnvs\py_064_02.07.15_test0\Scripts\python.exe" code00.py
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32

<module 'pygraphviz' from 'pygraphviz131_27\pygraphviz\__init__.pyc'>
strict digraph {
        a -> b;
}


[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q055196206]> "e:\Work\Dev\VEnvs\py_064_03.06.08_test0\Scripts\python.exe" code00.py
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32

<module 'pygraphviz' from 'pygraphviz15_36\\pygraphviz\\__init__.py'>
strict graph "" {
        a -- b;
}

如图所示,该问题很容易重现.现在,输出 - vs. -> 我将如何表示无向 vs.有向图边.我查看了源代码,发现了一些奇怪的地方.

As seen, the problem is easily reproducible. Now, the outputs -- vs. -> look awfully a lot to how I'd represent an undirected vs. directed graph edge. I looked in the source code and found something strange.

[GitHub.PyGraphviz 1.5]:类 AGraph ( thing = None,filename = None,data = None,string = None,handle = None,name ='',strict = True,directed = False,** attr )具有directed=False arg.将其设置为 True 即可解决此问题.

[GitHub.PyGraphviz 1.5]: class AGraph(thing=None, filename=None, data=None, string=None, handle=None, name='', strict=True, directed=False, **attr) has the directed=False arg. Setting it to True, fixed the problem.

输出:

[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q055196206]> "e:\Work\Dev\VEnvs\py_064_02.07.15_test0\Scripts\python.exe" code00.py dummy_arg
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32

<module 'pygraphviz' from 'pygraphviz131_27\pygraphviz\__init__.pyc'>
strict digraph {
        a -> b;
}


[cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q055196206]> "e:\Work\Dev\VEnvs\py_064_03.06.08_test0\Scripts\python.exe" code00.py dummy_arg
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32

<module 'pygraphviz' from 'pygraphviz15_36\\pygraphviz\\__init__.py'>
strict digraph "" {
        a -> b;
}

我说我发现了一件奇怪的事情:好吧,因为 PyGraphviz 1.3.1 事情是一样的: directed=False (代码文档),但它会以某种方式初始化图形,将其定向.
快速查看 agraph.py (在2个软件包版本中)并没有发现这种差异的来源,因此我可以放心地认为这是由于 Graphviz 包含2个 PyGraphviz 版本的软件包版本.

I said that I discovered something strange: well, for PyGraphviz 1.3.1 things are the same: directed=False (code and doc), yet it somehow initializes the graph as it would be directed.
A quick check on agraph.py (on the 2 package versions) didn't reveal where this difference comes from, so I can safely assume that it's because of Graphviz package versions that the 2 PyGraphviz versions were built with.

尽管如此, PyGraphviz 1.5 (由我构建)的行为是正确的.

Nevertheless, PyGraphviz 1.5 (built by me) behavior is the correct one.

这篇关于pygraphviz 1.5默认边缘没有箭头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆