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

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

问题描述

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



寻找一个python库来显示这些图形数据。

用python或Python绑定编写的库,是好的



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

解决方案

div>

Graphviz 是我认为最好的选择。

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

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



我最熟悉的python-Graphviz库是 pygraphviz ,这是非常好的。

另外两个是 pydot yapgvb 。至少我已经使用了这两个。每个比pygraphviz小(这可能是一个优点,取决于你的用例);另外既没有文档也没有pygraphviz。



幸运的是,这三个python库都比 Graphviz 更薄,所以没有隐藏轻量级,优雅的Graphviz语法( dot 语言)。





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

  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 - >第2步;
Step1 - > Step2a;
Step2a - > Step3a;
Step3;
Step3a - >第三步;
Step3a - > Step2b;
第2步 - > Step2b;
Step2b - >第三步;
End [shape = rectangle,
color = darkgoldenrod2,
fontcolor = navy];
第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天全站免登陆