Module for creating Sankey diagrams using Matplotlib.
class matplotlib.sankey.Sankey(ax=None, scale=1.0, unit='', format='%G', gap=0.25, radius=0.1, shoulder=0.03, offset=0.15, head_angle=100, margin=0.4, tolerance=1e-06, **kwargs)
Sankey diagram.Sankey diagrams are a specific type of flow diagram, in which the width of the arrows is shown proportionally to the flow quantity. They are typically used to visualize energy or material or cost transfers between processes. Wikipedia (6/1/2011)
Create a new Sankey instance.
Optional keyword arguments:
|ax||axes onto which the data should be plotted If ax isn't provided, new axes will be created.|
|scale||scaling factor for the flows scale sizes the width of the paths in order to maintain proper layout. The same scale is applied to all subdiagrams. The value should be chosen such that the product of the scale and the sum of the inputs is approximately 1.0 (and the product of the scale and the sum of the outputs is approximately -1.0).|
|unit||string representing the physical unit associated with the flow quantities If unit is None, then none of the quantities are labeled.|
|format||a Python number formatting string to be used in labeling the flow as a quantity (i.e., a number times a unit, where the unit is given)|
|gap||space between paths that break in/break away to/from the top or bottom|
|radius||inner radius of the vertical paths|
|shoulder||size of the shoulders of output arrowS|
|offset||text offset (from the dip or tip of the arrow)|
|head_angle||angle of the arrow heads (and negative of the angle of the tails) [deg]|
|margin||minimum space between Sankey outlines and the edge of the plot area|
|tolerance||acceptable maximum of the magnitude of the sum of flows The magnitude of the sum of connected flows cannot be greater than tolerance.|
The optional arguments listed above are applied to all subdiagrams so that there is consistent alignment and formatting.
In order to draw a complex Sankey diagram, create an instance of
Sankey by calling it without any kwargs:
sankey = Sankey()
Then add simple Sankey sub-diagrams:
sankey.add() # 1 sankey.add() # 2 #... sankey.add() # n
Finally, create the full diagram:
Or, instead, simply daisy-chain those calls:
add(self, patchlabel='', flows=None, orientations=None, labels='', trunklength=1.0, pathlengths=0.25, prior=None, connect=(0, 0), rotation=0, **kwargs)
Add a simple Sankey diagram with flows at the same hierarchical level.
Adjust the axes and return a list of information about the Sankey subdiagram(s).
Return value is a list of subdiagrams represented with the following fields:
|patch||Sankey outline (an instance of |
|flows||values of the flows (positive for input, negative for output)|
|angles||list of angles of the arrows [deg/90] For example, if the diagram has not been rotated, an input to the top side will have an angle of 3 (DOWN), and an output from the top side will have an angle of 1 (UP). If a flow has been skipped (because its magnitude is less than tolerance), then its angle will be None.|
|tips||array in which each row is an [x, y] pair indicating the positions of the tips (or "dips") of the flow paths If the magnitude of a flow is less the tolerance for the instance of |
|texts||list of |
© 2012–2018 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.