graph rendering in python (flowchart visualization)
Solution 1
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];
}
Solution 2
Like doug, I would suggest Graphviz.
I would also like to mention that you can also directly write graphs in the very simple dot language (they can then be plotted with Graphviz or other tools); this is a more lightweight alternative to using pydot, with no dependency of your code on any module.
Solution 3
gprof2dot.py
can automatically profile and visualize the execution flow in your program. It can be found as reciple 578138 on ActiveState Code. Please note the batch file at the end of the program.
Comments
-
eWizardII over 4 years
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)
-
Deepak Mathpal over 13 yearsalways a fan of minimalist solutions (creating dot files directly), +1 from me.
-
Paweł Prażak over 13 yearsI think the question is about automatic generator. Sorry, I haven't seen one, but what's good about automatic flow chart generation? AFAIK charts and fancy UML stuff, should help to rethink the solution and to gain perspective other than code, so to make it automatic to me is a shoot in the foot.
-
Pietro Battiston almost 4 yearsProbably worth mentioning that the flowchart above was obtained with the code below processed via the "dot" layout (which is not the default, for instance, in
pygraphviz
).