Reputation: 87
How to mark edges in a graph constructed using python and xdot
I have figured out a way to construct graph in python using dot language.
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())
The above program will create a graph with an edge between operating system and file management concepts automatically. The concepts will be marked in the ellipses.
My problem is to mark a "subclass" of label on that edge using python language so that the relationship is clear between the concepts
Is there any mechanism available to do so ?
Upvotes: 5
Views: 10120
Reputation: 87
def add_node(self, parent, node,i):
self.graph.add_edge(parent, node, label = i)
self.xdot.set_dotcode(nx.to_agraph(self.graph).to_string())
self.xdot.show_all()
so this way,i think we can dynamically pass the labels each time and capture all the relations and not just sub class of .
Upvotes: 1
Reputation: 12898
You can specify edge's label as a named argument to add_edge
:
self.graph.add_edge(parent, node, label='subclass')
Upvotes: 9