Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASCII Visualisation of a graph of nodes 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 may be in each others parentLists or childLists. I want to be able to visualise the relationships between the Nodes dictated in their childLists and parentlists onto stdout (as an ASCII drawing).

e.g where the names below are names of the nodes in the nodeList.

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

Classifier has an empty parentList and a childList of length 1 containing FeatureCombiner. FeatureGenerator1 and 2 have the same parent and childList containing FeatureCombiner and Image Loader respectively. Image Loader has an empty childList and a parentList containing FeatureGenerator1 and 2.

Thankyou in advance, Matt

like image 523
aultimus Avatar asked Mar 23 '11 16:03

aultimus


1 Answers

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

Python ASCII Graph Drawing

That said, there are a lot of tools available to draw graphs in non-ascii ways. Check out the plotting capabilities associated with NetworkX and Matplotlib for starters:

http://networkx.lanl.gov/

http://matplotlib.sourceforge.net/

and also pydot:

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

like image 70
JoshAdel Avatar answered Sep 23 '22 06:09

JoshAdel