python中的图形渲染(流程图可视化) [英] graph rendering in python (flowchart visualization)

查看:184
本文介绍了python中的图形渲染(流程图可视化)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可视化由python编码的边连接的节点序列.

正在寻找一个 Python 库来可视化此类图形数据.

用python编写的库或python绑定都可以

(我知道 Visustin,但正在寻找替代品)

解决方案

Graphviz 在我看来是最好的选择.

Graphviz 是首屈一指的图形渲染/布局库;它成熟、稳定、开源且免费.它不是一个专用的流程图或图表包,而是它的核心用例——即由节点和边组成的对象的高效和美观渲染,显然包含流程图绘制——特别是因为它的 api 允许用户设置各种 布局上的约束以鼓励以各种格式呈现——例如,您可以要求在单个居中对齐的行中呈现相同级别的所有节点(来自根的相同数量的父节点).>

Graphviz 不是 Python 库(它是用 C 编写的);但是有高质量的 python 绑定可用.

我最熟悉的python-Graphviz库是pygraphviz,非常棒.

另外两个是 pydotyapgvb.我至少使用过这两种方法几次.每个都小于 pygraphviz(根据您的用例,这可能是一个优势);此外,既没有记录也没有记录 pygraphviz.

幸运的是,这三个 Python 库都是 Graphviz 的薄包装,因此没有一个隐藏轻量级、优雅的 Graphviz 语法( 语言).

这是我用来创建下面的小流程图"的代码(使用 graphviz'dot 语言):

有向图{节点[填充=矢车菊蓝,字体颜色=白色,形状=钻石,样式=填充];Step1 [ color=darkgoldenrod2,字体颜色=海军,标签=开始,形状=框];第2步;Step3a [样式=填充,填充颜​​色=灰色80,颜色=灰色80,形状=圆形,字体颜色=海军];步骤 1 ->第2步;步骤 1 ->步骤2a;步骤2a->步骤3a;步骤3;步骤3a->步骤3;步骤3a->步骤2b;步骤 2 ->步骤2b;步骤2b->步骤3;结束 [ 形状=矩形,颜色=darkgoldenrod2,字体颜色=海军];步骤 3 ->结束[标签=193];}

to visualize a sequence of nodes connected by edges encoded in python.

looking for a python library to visualize such graph data.

either a library written in python or python bindings, is ok

(i am aware of Visustin, but looking for alternatives)

解决方案

Graphviz is the best option in my opinion.

Graphviz is the premiere graph rendering/layout library; it's mature, stable, open-source, and free of charge. It is not a dedicated flowchart or diagramming package, but its core use case--i.e., efficient and aesthetic rendering of objects comprised of nodes and edges, obviously subsumes flowchart drawing--particularly because its api allows the user to set various constraints on the layout to encourage rendering in the various formats--eg, you can require all nodes of the same level (same number of parents from the root) to be rendered in a single center-aligned row.

Graphviz is not a python library (it's written in C); however there are high quality python bindings available.

The python-Graphviz library I am most familar with is pygraphviz, which is excellent.

The other two are pydot and yapgvb. I have used both of these at least a few times. Each is smaller than pygraphviz (which might be an advantage depending on your use case); in addition neither is documented as well as pygraphviz.

Fortunately, all three of these python libraries are thin wrappers over Graphviz, so none conceal the lightweight, elegant Graphviz syntax (the dot language).

Here's the code (in graphviz' dot language) I used to create the small "flowchart" below:

digraph {

  node [    fill=cornflowerblue,
            fontcolor=white,
            shape=diamond,
            style=filled];

  Step1 [   color=darkgoldenrod2,
            fontcolor=navy,
            label=start,
            shape=box];

  Step2;

  Step3a [  style=filled,
            fillcolor=grey80,
            color=grey80,
            shape=circle,
            fontcolor=navy];

  Step1  -> Step2;
  Step1  -> Step2a;
  Step2a -> Step3a;
  Step3;
  Step3a -> Step3;
  Step3a -> Step2b;
  Step2  -> Step2b;
  Step2b -> Step3;
  End [ shape=rectangle,
        color=darkgoldenrod2,
        fontcolor=navy];
  Step3  -> End [label=193];
}

这篇关于python中的图形渲染(流程图可视化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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