graphviz 分割错误

发布于 2024-08-28 11:53:19 字数 1204 浏览 5 评论 0原文

我正在构建一个包含许多节点的图,大约 3000 个。我编写了一个简单的 python 程序来使用 graphviz 来实现这一点,但它给了我分段错误,我不知道为什么,如果图太大或者我'我缺少一些东西。

代码是:

#!/usr/bin/env python

# Import graphviz
import sys
sys.path.append('..')
sys.path.append('/usr/lib/graphviz')
import gv

# Import pygraph
from pygraph.classes.graph import graph
from pygraph.classes.digraph import digraph
from pygraph.algorithms.searching import breadth_first_search
from pygraph.readwrite.dot import write

# Graph creation
gr = graph()

file = open('nodes.dat', 'r')
line = file.readline()
while line:
        gr.add_nodes([line[0:-1]])
        line = file.readline()

file.close()
print 'nodes finished, beginning edges'

edges = open('edges_ok.dat', 'r')
edge = edges.readline()
while edge:
        gr.add_edge((edge.split()[0], edge.split()[1]))
        edge = edges.readline()

edges.close()
print 'edges finished'
print 'Drawing'

# Draw as PNG
dot = write(gr)
gvv = gv.readstring(dot)
gv.layout(gvv,'dot')
gv.render(gvv,'svg','graph.svg')

它在调用 gv.layout() 时崩溃。

这些文件是这样的: 节点:

   node1
   node2
   node3

edges_ok:

   node1 node2
   node2 node3

I'm building a graph with many nodes, around 3000. I wrote a simple python program to do the trick with graphviz, but it gives me segmentation fault and I don't know why, if the graph is too big or if i'm missing something.

The code is:

#!/usr/bin/env python

# Import graphviz
import sys
sys.path.append('..')
sys.path.append('/usr/lib/graphviz')
import gv

# Import pygraph
from pygraph.classes.graph import graph
from pygraph.classes.digraph import digraph
from pygraph.algorithms.searching import breadth_first_search
from pygraph.readwrite.dot import write

# Graph creation
gr = graph()

file = open('nodes.dat', 'r')
line = file.readline()
while line:
        gr.add_nodes([line[0:-1]])
        line = file.readline()

file.close()
print 'nodes finished, beginning edges'

edges = open('edges_ok.dat', 'r')
edge = edges.readline()
while edge:
        gr.add_edge((edge.split()[0], edge.split()[1]))
        edge = edges.readline()

edges.close()
print 'edges finished'
print 'Drawing'

# Draw as PNG
dot = write(gr)
gvv = gv.readstring(dot)
gv.layout(gvv,'dot')
gv.render(gvv,'svg','graph.svg')

and it crashes at the gv.layout() call.

The files are somthing like:
nodes:

   node1
   node2
   node3

edges_ok:

   node1 node2
   node2 node3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱绻入梦 2024-09-04 11:53:19

我将布局类型从点更改为neato,这解决了问题。

我搜索了一下,似乎大图上的点布局有点错误。

I changed the layout type from dot to neato and that solved the problem.

I searched a bit and it seems that the dot layout is a bit faulty on large graphs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文