matplotlib.sankey: boxes spliced into flow?

Hullo matplotlib list,

I've discovered (with pleasure!) that matplotlib has recently learned how to create Sankey diagrams. Thank you Kevin and Yannick!

One of my less-technically inclined fellow graduate students is searching for his toolset of choice for generating these suckers, and is currently looking at Stan. As I'm an open-source advocate I'd love to be able to say, "you can do this with X", where X in this case is clearly matplotlib.

Specifically, I've not heavily used matplotlib before, and from the given examples I see on matplotlib.sf.net, I'm not clear on exactly the capabilities of this recently-added code. What my fellow grad student has opined would be nice for his uses would be boxes that are built into the flows, rather than just used as labels. Something like:

"Page Load"
http://modernl.com/images/diagrams/web-traffic-sankey-diagram.png

"Input", "Gas Turbine", "HRSG", "Waste", "BP Turbine", "Output"
http://www.bucknell.edu/images/Depts/Facilities/sankeythumb.jpg

Is this currently possible, /without/ manually adjusting the graphic?

Thanks!

Kevin

Hi Kevin,

Thanks for your post. I think the short answer is that the solution will require some manual adjustments.

It has been a little while since I worked with the Sankey class, but I'll try to give some detail. The entire Sankey diagram is a composite of sub-diagrams. Each sub-diagram may have its own input and output branches. The sub-diagrams are joined at matching inputs/outputs.

So, based on the images you shared, I think there are several areas that will need some manual work or hacks:
1. Since the height of "Page Load" (first diagram) is greater than the sum of the heights of its inputs and outputs, it will be tricky. You could try creating "Page Load" as a sub diagram with 5 inputs and 5 outputs, where the first and last inputs/outputs are "dummy" branches to add the additional height. You could also add page load as an additional rectangular patch, but that would require manual placement, and it would need to be placed in the proper order to overlay "Browsing loop." That might require 2 unconnected Sankey diagrams.
2. It may require tweaking or more sub-diagrams that you'd expect to get the +/- 30 or so degree angles on the "Organic" and "Direct" branches (first diagram).
3. The second diagram introduces additional complexities. The white backgrounds of the text boxes might be possible by specifying the properties of the existing text, but I'm not sure.
4. It will be necessary to manually adjust the length of the "Electricity" branch so that it lines up with the "Steam" branch (second diagram). Likewise for the "Fuel" and "Auxiliary Fuel." That is one definite drawback of the matplotlib Sankey class as it is; where branches split and rejoin or form a circuit, manual adjustment may be necessary.
4. Finally, it may be difficult to reproduce the shading of the branches in the second diagram.

I'm sorry that there's no "out of the box" solution. However, since matplotlib and Python is so flexible, it may be fairly straightforward to automate these additional features. I also suspect that some of the features of the diagrams may be artifacts of the particular software used--not necessarily due to the preferences of your colleague.

Kevin

ยทยทยท

On 03/15/2012 10:56 AM, Kevin Hunter wrote:

Hullo matplotlib list,

I've discovered (with pleasure!) that matplotlib has recently learned
how to create Sankey diagrams. Thank you Kevin and Yannick!

One of my less-technically inclined fellow graduate students is
searching for his toolset of choice for generating these suckers, and is
currently looking at Stan. As I'm an open-source advocate I'd love to
be able to say, "you can do this with X", where X in this case is
clearly matplotlib.

Specifically, I've not heavily used matplotlib before, and from the
given examples I see on matplotlib.sf.net, I'm not clear on exactly the
capabilities of this recently-added code. What my fellow grad student
has opined would be nice for his uses would be boxes that are built into
the flows, rather than just used as labels. Something like:

"Page Load"
http://modernl.com/images/diagrams/web-traffic-sankey-diagram.png

"Input", "Gas Turbine", "HRSG", "Waste", "BP Turbine", "Output"
http://www.bucknell.edu/images/Depts/Facilities/sankeythumb.jpg

Is this currently possible, /without/ manually adjusting the graphic?

Thanks!

Kevin

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users