【问题标题】:Draw trees or graph using python from a relationship table使用 python 从关系表中绘制树或图形
【发布时间】:2016-06-24 07:33:02
【问题描述】:

有没有办法使用 python 从某个关系(父/子)表中绘制树结构或图形?孩子可能有不止一个父母。例如,

|Parent  |Child
|none    |node 1
|none    |node 2
|node 1  |node 3
|node 2  |node 3
|node 2  |node 4

这给了

  node1    node2
     \      / \
      node3    node4

【问题讨论】:

  • 你可以使用 turtle docs.python.org/2/library/turtle.html 并学习如何按照一些逻辑在不同的方向上绘制
  • 欢迎来到 StackOverflow。请阅读并遵循帮助文档中的发布指南。 Minimal, complete, verifiable example 适用于此。在您发布代码并准确描述问题之前,我们无法有效地帮助您。 StackOverflow 不是编码或教程服务。

标签: python graph tree


【解决方案1】:

来自其他内置树的语言,python 可能看起来有点奇怪,因为它没有树。

我建议为子字典构建一个父级,其中的值实际上是子级列表:

{node1:[node3], node2:[node3, node4]}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-04
    • 2013-01-14
    • 2018-11-18
    • 2015-06-06
    • 1970-01-01
    • 2020-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多