<divid="unreleased-message"> You are reading an old version of the documentation (v3.3.0). For the latest version see <ahref="https://matplotlib.org/stable/api/sankey_api.html">https://matplotlib.org/stable/api/sankey_api.html</a></div>
<spanid="matplotlib-sankey"></span><h1><codeclass="docutils literal notranslate"><spanclass="pre">matplotlib.sankey</span></code><aclass="headerlink" href="#module-matplotlib.sankey" title="Permalink to this headline">¶</a></h1>
<p>Module for creating Sankey diagrams using Matplotlib.</p>
<dlclass="class">
<dtid="matplotlib.sankey.Sankey">
<emclass="property">class </em><codeclass="descclassname">matplotlib.sankey.</code><codeclass="descname">Sankey</code><spanclass="sig-paren">(</span><em>ax=None</em>, <em>scale=1.0</em>, <em>unit=''</em>, <em>format='%G'</em>, <em>gap=0.25</em>, <em>radius=0.1</em>, <em>shoulder=0.03</em>, <em>offset=0.15</em>, <em>head_angle=100</em>, <em>margin=0.4</em>, <em>tolerance=1e-06</em>, <em>**kwargs</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/sankey.html#Sankey"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.sankey.Sankey" title="Permalink to this definition">¶</a></dt>
<p>The optional arguments listed below are applied to all subdiagrams so
that there is consistent alignment and formatting.</p>
<p>In order to draw a complex Sankey diagram, create an instance of
<aclass="reference internal" href="#matplotlib.sankey.Sankey" title="matplotlib.sankey.Sankey"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Sankey</span></code></a> by calling it without any kwargs:</p>
<trclass="field-odd field"><thclass="field-name">Other Parameters:</th><tdclass="field-body"><dlclass="first last docutils">
<dt><strong>ax</strong><spanclass="classifier"><aclass="reference internal" href="axes_api.html#matplotlib.axes.Axes" title="matplotlib.axes.Axes"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Axes</span></code></a></span></dt><dd><p>Axes onto which the data should be plotted. If <em>ax</em> isn't
provided, new Axes will be created.</p>
</dd>
<dt><strong>scale</strong><spanclass="classifier">float</span></dt><dd><p>Scaling factor for the flows. <em>scale</em> 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).</p>
</dd>
<dt><strong>unit</strong><spanclass="classifier">str</span></dt><dd><p>The physical unit associated with the flow quantities. If <em>unit</em>
is None, then none of the quantities are labeled.</p>
</dd>
<dt><strong>format</strong><spanclass="classifier">str</span></dt><dd><p>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).</p>
</dd>
<dt><strong>gap</strong><spanclass="classifier">float</span></dt><dd><p>Space between paths that break in/break away to/from the top or
bottom.</p>
</dd>
<dt><strong>radius</strong><spanclass="classifier">float</span></dt><dd><p>Inner radius of the vertical paths.</p>
</dd>
<dt><strong>shoulder</strong><spanclass="classifier">float</span></dt><dd><p>Size of the shoulders of output arrows.</p>
</dd>
<dt><strong>offset</strong><spanclass="classifier">float</span></dt><dd><p>Text offset (from the dip or tip of the arrow).</p>
</dd>
<dt><strong>head_angle</strong><spanclass="classifier">float</span></dt><dd><p>Angle, in degrees, of the arrow heads (and negative of the angle of
the tails).</p>
</dd>
<dt><strong>margin</strong><spanclass="classifier">float</span></dt><dd><p>Minimum space between Sankey outlines and the edge of the plot
area.</p>
</dd>
<dt><strong>tolerance</strong><spanclass="classifier">float</span></dt><dd><p>Acceptable maximum of the magnitude of the sum of flows. The
magnitude of the sum of connected flows cannot be greater than
<em>tolerance</em>.</p>
</dd>
<dt><strong>**kwargs</strong></dt><dd><p>Any additional keyword arguments will be passed to <aclass="reference internal" href="#matplotlib.sankey.Sankey.add" title="matplotlib.sankey.Sankey.add"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">add()</span></code></a>,
<dt><strong>patchlabel</strong><spanclass="classifier">str</span></dt><dd><p>Label to be placed at the center of the diagram.
Note that <em>label</em> (not <em>patchlabel</em>) can be passed as keyword
argument to create an entry in the legend.</p>
</dd>
<dt><strong>flows</strong><spanclass="classifier">list of float</span></dt><dd><p>Array of flow values. By convention, inputs are positive and
outputs are negative.</p>
<p>Flows are placed along the top of the diagram from the inside out
in order of their index within <em>flows</em>. They are placed along the
sides of the diagram from the top down and along the bottom from
the outside in.</p>
<p>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.</p>
</dd>
<dt><strong>orientations</strong><spanclass="classifier">list of {-1, 0, 1}</span></dt><dd><p>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).</p>
</dd>
<dt><strong>labels</strong><spanclass="classifier">list of (str or None)</span></dt><dd><p>List of labels for the flows (or a single label to be used for all
flows). Each label may be <em>None</em> (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 <em>unit</em> of the main diagram is None, then quantities are never
shown, regardless of the value of this argument.</p>
</dd>
<dt><strong>trunklength</strong><spanclass="classifier">float</span></dt><dd><p>Length between the bases of the input and output groups (in
data-space units).</p>
</dd>
<dt><strong>pathlengths</strong><spanclass="classifier">list of float</span></dt><dd><p>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 <em>pathlengths</em>
are not applied to the horizontal inputs and outputs.</p>
</dd>
<dt><strong>prior</strong><spanclass="classifier">int</span></dt><dd><p>Index of the prior diagram to which this diagram should be
connected.</p>
</dd>
<dt><strong>connect</strong><spanclass="classifier">(int, int)</span></dt><dd><p>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 <em>prior</em> is <em>None</em>, <em>connect</em> will be ignored.</p>
</dd>
<dt><strong>rotation</strong><spanclass="classifier">float</span></dt><dd><p>Angle of rotation of the diagram in degrees. The interpretation of
the <em>orientations</em> argument will be rotated accordingly (e.g., if
<em>rotation</em> == 90, an <em>orientations</em> entry of 1 means to/from the
left). <em>rotation</em> is ignored if this diagram is connected to an
existing one (using <em>prior</em> and <em>connect</em>).</p>
<codeclass="descname">finish</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/sankey.html#Sankey.finish"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.sankey.Sankey.finish" title="Permalink to this definition">¶</a></dt>
<dd><p>Adjust the axes and return a list of information about the Sankey
subdiagram(s).</p>
<p>Return value is a list of subdiagrams represented with the following
<td>values of the flows (positive for input, negative
for output)</td>
</tr>
<trclass="row-even"><td><em>angles</em></td>
<td>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 <em>tolerance</em>),
then its angle will be <em>None</em>.</td>
</tr>
<trclass="row-odd"><td><em>tips</em></td>
<td>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 <em>tolerance</em>
for the instance of <aclass="reference internal" href="#matplotlib.sankey.Sankey" title="matplotlib.sankey.Sankey"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Sankey</span></code></a>, the flow is
skipped and its tip will be at the center of the
diagram.</td>
</tr>
<trclass="row-even"><td><em>text</em></td>
<td><aclass="reference internal" href="text_api.html#matplotlib.text.Text" title="matplotlib.text.Text"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Text</span></code></a> instance for the