Python中的树图 [英] Tree plotting in Python

查看:101
本文介绍了Python中的树图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Python绘制树.决策树,组织结构图等.有什么图书馆可以帮助我吗?

I want to plot trees using Python. Decision trees, Organizational charts, etc. Any library that helps me with that?

推荐答案

有graphviz- http://www.graphviz. org/.它使用"DOT"语言绘制图形.您既可以自己生成DOT代码,也可以使用pydot- https://code.google.com/p /pydot/.您也可以使用networkx- http://networkx.lanl.gov/tutorial/tutorial .html#drawing-graphs ,可以轻松地绘制到graphviz或matplotlib.

There's graphviz - http://www.graphviz.org/. It uses the "DOT" language to plot graphs. You can either generate the DOT code yourself, or use pydot - https://code.google.com/p/pydot/. You could also use networkx - http://networkx.lanl.gov/tutorial/tutorial.html#drawing-graphs, which make it easy to draw to either graphviz or matplotlib.

networkx + matplotlib + graphviz为您提供最大的灵活性和功能,但是您需要安装很多.

networkx + matplotlib + graphviz gives you the most flexibility and power, but you need to install a lot.

如果您想快速解决问题,请尝试:

If you want a quick solution, try:

安装Graphviz.

Install Graphviz.

open('hello.dot','w').write("digraph G {Hello->World}")
import subprocess
subprocess.call(["path/to/dot.exe","-Tpng","hello.dot","-o","graph1.png"]) 
# I think this is right - try it form the command line to debug

然后安装pydot,因为pydot已经为您完成了此操作.然后,您可以使用networkx来驱动" pydot.

Then you install pydot, because pydot already does this for you. Then you can use networkx to "drive" pydot.

这篇关于Python中的树图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆