如何在使用
python和xdot构造的图形中标记边缘
我已经找到了一种使用点语言在python中构建图形的方法.
import sys
import threading
import time
import networkx as nx
import xdot
import gtk
class MyClass(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.graph = nx.DiGraph(name="my_tree")
self.xdot = xdot.DotWindow()
self.xdot.connect('destroy', gtk.main_quit)
def run(self):
gtk.main()
def add_node(self, parent, node):
self.graph.add_edge(parent, node)
self.xdot.set_dotcode(nx.to_agraph(self.graph).to_string())
self.xdot.show_all()
def main(argv=None):
gtk.gdk.threads_init()
my_class = MyClass()
my_class.start()
my_class.add_node('operating_system', 'file_mgmt')
time.sleep(1.5)
if __name__ == "__main__":
sys.exit(main())
上述程序将自动创建一个在操作系统和文件管理概念之间具有优势的图形.概念将在省略号中标记.
我的问题是使用python语言在该边缘上标记标签的“子类”,以便概念之间的关系清晰
有没有可用的机制?
最佳答案 您可以将edge的标签指定为add_edge的命名参数:
self.graph.add_edge(parent, node, label='subclass')