<divid="unreleased-message"> You are reading an old version of the documentation (v3.2.2). 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="py class">
<dtid="matplotlib.sankey.Sankey">
<emclass="property">class </em><codeclass="descclassname">matplotlib.sankey.</code><codeclass="descname">Sankey</code><spanclass="sig-paren">(</span><em><spanclass="n">ax</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <em><spanclass="n">scale</span><spanclass="o">=</span><spanclass="default_value">1.0</span></em>, <em><spanclass="n">unit</span><spanclass="o">=</span><spanclass="default_value">''</span></em>, <em><spanclass="n">format</span><spanclass="o">=</span><spanclass="default_value">'%G'</span></em>, <em><spanclass="n">gap</span><spanclass="o">=</span><spanclass="default_value">0.25</span></em>, <em><spanclass="n">radius</span><spanclass="o">=</span><spanclass="default_value">0.1</span></em>, <em><spanclass="n">shoulder</span><spanclass="o">=</span><spanclass="default_value">0.03</span></em>, <em><spanclass="n">offset</span><spanclass="o">=</span><spanclass="default_value">0.15</span></em>, <em><spanclass="n">head_angle</span><spanclass="o">=</span><spanclass="default_value">100</span></em>, <em><spanclass="n">margin</span><spanclass="o">=</span><spanclass="default_value">0.4</span></em>, <em><spanclass="n">tolerance</span><spanclass="o">=</span><spanclass="default_value">1e-06</span></em>, <em><spanclass="o">**</span><spanclass="n">kwargs</span></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>
If <em>ax</em> isn't provided, new axes will be created.</td>
</tr>
<trclass="row-odd"><td><em>scale</em></td>
<td>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).</td>
</tr>
<trclass="row-even"><td><em>unit</em></td>
<td>string representing the physical unit associated
with the flow quantities
If <em>unit</em> is None, then none of the quantities are
labeled.</td>
</tr>
<trclass="row-odd"><td><em>format</em></td>
<td>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)</td>
</tr>
<trclass="row-even"><td><em>gap</em></td>
<td>space between paths that break in/break away
to/from the top or bottom</td>
</tr>
<trclass="row-odd"><td><em>radius</em></td>
<td>inner radius of the vertical paths</td>
</tr>
<trclass="row-even"><td><em>shoulder</em></td>
<td>size of the shoulders of output arrowS</td>
</tr>
<trclass="row-odd"><td><em>offset</em></td>
<td>text offset (from the dip or tip of the arrow)</td>
</tr>
<trclass="row-even"><td><em>head_angle</em></td>
<td>angle of the arrow heads (and negative of the angle
of the tails) [deg]</td>
</tr>
<trclass="row-odd"><td><em>margin</em></td>
<td>minimum space between Sankey outlines and the edge
of the plot area</td>
</tr>
<trclass="row-even"><td><em>tolerance</em></td>
<td>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>.</td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>The optional arguments listed above are applied to all subdiagrams so
that there is consistent alignment and formatting.</p>
<p>If <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> is instantiated with any keyword arguments other
than those explicitly listed above (<codeclass="docutils literal notranslate"><spanclass="pre">**kwargs</span></code>), they 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>, which will create the first subdiagram.</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>
<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><spanclass="n">self</span></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