Reputation: 15
I have data as below in excel and I want show the data in graphical form showing layers of hierarchy. Also, when a search criteria like a child is searched then need to show only the path that leads to that node from top. I am new to python and I am trying to learn visualizing hierarchy data using Python. I also checked Python Library NetworKx for this. Can somebody please guide me right direction. Data:
child parent
1 2010 1000
7 2100 1000
5 2110 1000
3 3000 2110
2 3011 2010
4 3033 2100
0 3102 2010
6 3111 2110
Output:
Upvotes: 0
Views: 398
Reputation: 1061
This question seems to consist of two parts: searching and visualization. The library you mentioned seems well suited for both tasks, but perhaps you are looking for more lightweight solutions.
One approach would be to use some limited own code in combination with Graphviz (it also has excellent python bindings). Given the parsed data, it would go something like this:
from graphviz import Digraph
# child-parent pairs
data = [(2010, 1000), (2100, 1000), (2110, 1000),
(3000, 2110), (3011, 2010), (3033, 2100),
(3102, 2010), (3111, 2110)]
g = Digraph(format='svg')
for child, parent in data:
g.edge(str(parent), str(child))
g.render('graph')
You can also highlight nodes and edges by setting the color
attribute. Note that Graphviz only handles visualization. You'd have to write your own Node
and/or Edge
classes to search for a path.
Upvotes: 1