Python中节点图的ASCII可视化

问题描述 投票:11回答:3

我有一个叫做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

我有一个节点列表(nodeList)。这些节点可以彼此位于父列表或子列表中。我希望能够将其childList和Parentlist中指定的Node之间的关系可视化到stdout(作为ASCII绘图)。

例如,以下名称是nodeList中节点的名称。

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

分类器具有一个空的parentList和一个包含FeatureCombiner的长度为1的childList。 FeatureGenerator1和2具有相同的父和子列表,分别包含FeatureCombiner和Image Loader。 Image Loader的空子列表和父列表包含FeatureGenerator1和2。

谢谢你,马特

python graph ascii visualization
3个回答
7
投票

这在ascii中是不平凡的,这在以下方面没有完整的答案就可以证明:

Python ASCII Graph Drawing

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

http://networkx.lanl.gov/

http://matplotlib.sourceforge.net/

还有pydot:

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


5
投票

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


0
投票

[我们在Graph::Easy中遇到了类似的问题,潜伏甚至尝试将DVC project移植到Python之后,我们已经意识到,没有跨平台的python库可以做到这一点,并且不需要像Graphviz。因此,我们最终使用了一个名为Graph::Easy的令人惊叹的库来为我们处理布局,然后我们将结果自己以ASCII呈现并使用分页器进行呈现(这是Grandalf之类的东西使它的输出很好并且可水平和垂直滚动)。 git log

© www.soinside.com 2019 - 2024. All rights reserved.