Sankey diagrams in Python

女生的网名这么多〃 提交于 2019-12-23 07:08:52

问题


Is there a Python library for generating Sankey diagrams?

I've seen this list of Sankey diagram applications and libraries, but none of them is in Python.


回答1:


Apparently matplotlib 1.1 can now do this. Code and sample output is here.

Below is a screenshot demonstrating what it can do.




回答2:


I did a Google search on "Python graph visualization" and found some stuff. There are several libraries that have "spring" behavior where the software balances out a graph and makes it pretty; they do much of the work for you. But they draw graph diagrams, with nodes and edges, nothing like a Sankey diagram.

A Google search on "Python sankey" produced no useful results.

I did some Google searches on "Python vector graphics" and found this very promising result:

http://pypi.python.org/pypi/Things

With Things, apparently you draw basic shapes in Inkscape (a free vector editing program) and then you write Python to scale, rotate, etc. the shapes to produce an image or an animation. It should be possible to write Python code to automatically make the Sankey arrows spring away from their sources, turning up, down, whatever.

See also the StackOverflow discussion of drawing vector diagrams in Python: svg diagrams using python

That page led me to: http://cairographics.org/ which looks very useful.

The blog you linked has a posting about an article on automatic Sankey diagram creation:

http://www.sankey-diagrams.com/sankey-diagrams-are-directed-weighted-graphs/

http://www.svgopen.org/2003/papers/RenderingGraphs/index.html

I didn't find a turnkey solution for you, but I did find some parts that could potentially be used in a solution. Good luck.




回答3:


In my research group we use Sankey diagrams from Python inside Jupyter notebooks, using open-source projects (note: I'm the developer of these projects) to embed D3/SVG-based Sankey in the output.

  • floWeaver provides more structure to the data aggregation that's often involved in drawing a Sankey diagram,
  • ipysankeywidget just draws the Sankey diagram.

Both of these are based on a d3 library, d3-sankey-diagram which adds some features to the standard d3 sankey plugin (loops, multiple flow types, more control over layout).



来源:https://stackoverflow.com/questions/1620125/sankey-diagrams-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!