ASCII可视化python中的节点图

aul*_*mus 10 python ascii visualization graph

我有一个名为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
Run Code Online (Sandbox Code Playgroud)

我有一个节点列表(nodeList).这些节点可以在彼此的父列表或子列表中.我希望能够将他们的childLists和父代列表中指定的节点之间的关系可视化到stdout上(作为ASCII绘图).

例如,下面的名称是nodeList中节点的名称.

                           Classifier
                                |
                                |
                         FeatureCombiner
                          /           \
                         /             \
                        /               \
               FeatureGenerator1     FeatureGenerator2
                      \                     /
                       \                   /
                        \                 /
                         \               /
                          \             /
                           \           /
                            \         /
                            Image Loader
Run Code Online (Sandbox Code Playgroud)

分类器具有空的parentList和长度为1的包含FeatureCombiner的childList.FeatureGenerator1和2分别具有相同的parent和childList,包含FeatureCombiner和Image Loader.Image Loader有一个空的childList和一个包含FeatureGenerator1和2的parentList.

提前谢谢你,马特

Rus*_*iev 11

我们在DVC 项目中遇到了类似的问题,在潜伏甚至尝试将Graph::Easy移植到 Python 中之后,我们意识到没有跨平台的 Python 库可以做到这一点,并且不需要像 Graphviz 这样的重依赖。因此,我们最终使用了一个名为Grandalf的令人惊叹的库,它为我们处理了布局,然后我们自己以 ASCII 渲染结果并使用分页器呈现它们(这就是像这样的东西如何git log使其输出漂亮并且可以水平和垂直滚动) )。请参阅此处的完整代码

+-------------------+           +--------------------+
| test_data.csv.dvc |           | train_data.csv.dvc |
+-------------------+           +--------------------+
                  **              **                  
                    ***        ***                    
                       **    **                       
                +-------------------+                 
                | featurization.dvc |                 
                +-------------------+                 
                  ***            ***                  
                **                  ***               
              **                       **             
    +--------------+                     **           
    | training.dvc |                   **             
    +--------------+                ***               
                  ***            ***                  
                     **        **                     
                       **    **                       
                     +---------+                      
                     | Dvcfile |                      
                     +---------+                      
Run Code Online (Sandbox Code Playgroud)

  • 这真的很棒:) (2认同)

Jos*_*del 7

这在ascii中是非常重要的,因为缺乏完整的答案证明:

Python ASCII图形绘制

也就是说,有许多工具可用于以非ascii方式绘制图形.查看与NetworkX和Matplotlib相关的绘图功能的初学者:

http://networkx.lanl.gov/

http://matplotlib.sourceforge.net/

还有pydot:

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


sam*_*ias 5

也许从Perl中移植ASCII图形布局逻辑Graph::Easy