matplotlib.sankey¶
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)[source]¶ Bases:
objectSankey 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.
The optional arguments listed below 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
Sankeyby 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:
sankey.finish()
Or, instead, simply daisy-chain those calls:
Sankey().add().add... .add().finish()
See also
Examples
-
add(self, patchlabel='', flows=None, orientations=None, labels='', trunklength=1.0, pathlengths=0.25, prior=None, connect=(0, 0), rotation=0, **kwargs)[source]¶ Add a simple Sankey diagram with flows at the same hierarchical level.
Parameters: - patchlabelstr
Label to be placed at the center of the diagram. Note that label (not patchlabel) can be passed as keyword argument to create an entry in the legend.
- flowslist of float
Array of flow values. By convention, inputs are positive and outputs are negative.
Flows are placed along the top of the diagram from the inside out in order of their index within flows. They are placed along the sides of the diagram from the top down and along the bottom from the outside in.
If the sum of the inputs and outputs is nonzero, the discrepancy will appear as a cubic Bezier curve along the top and bottom edges of the trunk.
- orientationslist of {-1, 0, 1}
List of orientations of the flows (or a single orientation to be used for all flows). Valid values are 0 (inputs from the left, outputs to the right), 1 (from and to the top) or -1 (from and to the bottom).
- labelslist of (str or None)
List of labels for the flows (or a single label to be used for all flows). Each label may be None (no label), or a labeling string. If an entry is a (possibly empty) string, then the quantity for the corresponding flow will be shown below the string. However, if the unit of the main diagram is None, then quantities are never shown, regardless of the value of this argument.
- trunklengthfloat
Length between the bases of the input and output groups (in data-space units).
- pathlengthslist of float
List of lengths of the vertical arrows before break-in or after break-away. If a single value is given, then it will be applied to the first (inside) paths on the top and bottom, and the length of all other arrows will be justified accordingly. The pathlengths are not applied to the horizontal inputs and outputs.
- priorint
Index of the prior diagram to which this diagram should be connected.
- connect(int, int)
A (prior, this) tuple indexing the flow of the prior diagram and the flow of this diagram which should be connected. If this is the first diagram or prior is None, connect will be ignored.
- rotationfloat
Angle of rotation of the diagram in degrees. The interpretation of the orientations argument will be rotated accordingly (e.g., if rotation == 90, an orientations entry of 1 means to/from the left). rotation is ignored if this diagram is connected to an existing one (using prior and connect).
Returns: - Sankey
The current
Sankeyinstance.
Other Parameters: - **kwargs
Additional keyword arguments set
matplotlib.patches.PathPatchproperties, listed below. For example, one may want to usefill=Falseorlabel="A legend entry".Property Description agg_filtera filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array alphafloat or None animatedbool antialiasedor aaunknown capstyle{'butt', 'round', 'projecting'} clip_boxBboxclip_onbool clip_pathPatch or (Path, Transform) or None colorcolor containsunknown edgecoloror eccolor or None or 'auto' facecoloror fccolor or None figureFigurefillbool gidstr hatch{'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'} in_layoutbool joinstyle{'miter', 'round', 'bevel'} labelobject linestyleor ls{'-', '--', '-.', ':', '', (offset, on-off-seq), ...} linewidthor lwfloat or None path_effectsAbstractPathEffectpickerNone or bool or callable rasterizedbool or None sketch_params(scale: float, length: float, randomness: float) snapbool or None transformTransformurlstr visiblebool zorderfloat
See also
-
