ASCII visualization of node graph in python

I have a class called Node

class Node: def __init__(self,name, childList, parentList): self.name = name # a list of all nodes which are children of this node # may have length 0 to many self.childList = childList # a list of all nodes which are parents of this node # may have length 0 to many self.parentList = parentList 

I have a list of nodes (nodeList). These nodes can be in the parent lists of others or in child lists. I want to be able to visualize the relationship between nodes dictated by their child lists and parent lists on stdout (as an ASCII picture).

for example, where the names below are the names of the nodes in the List node.

  Classifier | | FeatureCombiner / \ / \ / \ FeatureGenerator1 FeatureGenerator2 \ / \ / \ / \ / \ / \ / \ / Image Loader 

The classifier has an empty parent list and a child list of length 1 containing FeatureCombiner. FeatureGenerator1 and 2 have the same parent and child elements containing FeatureCombiner and Image Loader respectively. Image Loader has an empty child list and a parent list containing FeatureGenerator1 and 2.

Thanks in advance, Matt

+7
source share
2 answers

This is not trivial to do in ascii, as evidenced by the lack of complete answers in:

Python ASCII Graphic Drawing

However, there are many tools available for drawing graphs in non-ascii ways. Check out the networking options related to NetworkX and Matplotlib for starters:

http://networkx.lanl.gov/

http://matplotlib.sourceforge.net/

as well as pydot:

http://code.google.com/p/pydot/

+6
source

Perhaps porting the ASCII charting logic from Perl Graph::Easy ?

+4
source

All Articles