gpt4 book ai didi

python - 在 pygraph 中设置图形属性

转载 作者:行者123 更新时间:2023-11-28 23:05:50 25 4
gpt4 key购买 nike

我在 documentation of pygraph 中找到如何更改 attributes of the nodes and the edges ,但我没有找到有关如何更改图形属性的帮助。

我尝试过但没有成功:

gr = graph()
gr.__setattr__('aspect',2)

你有什么建议?

谢谢!

[更新]我也试过:

gr = graph()
gr.__setattr__('rotate',90)
gr.rotate = 90
gr.color = 'red'
setattr(gr,'bgcolor','red')

[更新 2]来自具有不同想法的网站的示例代码来更改属性:

#!/usr/bin/env python

# Copyright (c) 2007-2008 Pedro Matiello <pmatiello@gmail.com>
# License: MIT (see COPYING file)

# Import graphviz
import sys
sys.path.append('..')
sys.path.append('/usr/lib/graphviz/python/')
sys.path.append('/usr/lib64/graphviz/python/')
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()

gr.__setattr__('rotate',90)
gr.rotate = 90
gr.color = 'red'
setattr(gr,'bgcolor','red')

# Add nodes and edges
gr.add_nodes(["Portugal","Spain","France","Germany","Belgium","Netherlands","Italy"])
gr.add_nodes(["Switzerland","Austria","Denmark","Poland","Czech Republic","Slovakia","Hungary"])
gr.add_nodes(["England","Ireland","Scotland","Wales"])

gr.add_edge(("Portugal", "Spain"))
gr.add_edge(("Spain","France"))
gr.add_edge(("France","Belgium"))
gr.add_edge(("France","Germany"))
gr.add_edge(("France","Italy"))
gr.add_edge(("Belgium","Netherlands"))
gr.add_edge(("Germany","Belgium"))
gr.add_edge(("Germany","Netherlands"))
gr.add_edge(("England","Wales"))
gr.add_edge(("England","Scotland"))
gr.add_edge(("Scotland","Wales"))
gr.add_edge(("Switzerland","Austria"))
gr.add_edge(("Switzerland","Germany"))
gr.add_edge(("Switzerland","France"))
gr.add_edge(("Switzerland","Italy"))
gr.add_edge(("Austria","Germany"))
gr.add_edge(("Austria","Italy"))
gr.add_edge(("Austria","Czech Republic"))
gr.add_edge(("Austria","Slovakia"))
gr.add_edge(("Austria","Hungary"))
gr.add_edge(("Denmark","Germany"))
gr.add_edge(("Poland","Czech Republic"))
gr.add_edge(("Poland","Slovakia"))
gr.add_edge(("Poland","Germany"))
gr.add_edge(("Czech Republic","Slovakia"))
gr.add_edge(("Czech Republic","Germany"))
gr.add_edge(("Slovakia","Hungary"))

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

最佳答案

显然,您可以使用 gv.setv() 来设置图形的属性。

import gv
g = gv.digraph('19261920')
gv.setv(g, 'overlap', 'compress')

我通过检查 /usr/include/graphviz/gv.i 中的 gv.py 接口(interface)定义文件找到了 gv.setv() >

在 interwebz 中搜索 "import gv"overlap setv 让我找到了 this old post它演示了 gv.setv() 的使用。

我找到了这个 PDF gv_python man page其中包含有关 setv 的更多文档。

这么简单的事情要进行大量调查,是吧?

关于python - 在 pygraph 中设置图形属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5639049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com