matplotlib_sankey#

Attributes#

Functions#

from_matrix(mtx[, source_indicies, target_indicies])

Convert weight matrix to tuple of source, target and weight.

sankey(data[, figsize, frameon, ax, spacing, ...])

Sankey plot.

Package Contents#

matplotlib_sankey.__version__: str#
matplotlib_sankey.from_matrix(mtx, source_indicies=None, target_indicies=None)#

Convert weight matrix to tuple of source, target and weight.

Parameters:
  • mtx (Sequence[Sequence[int | float]], optional) – Weight matrix (source x target).

  • source_indicies (list[int | str] | None, optional) – List of source indices. Defaults to None.

  • target_indicies (list[int | str] | None, optional) – List of target indices. Defaults to None.

Returns:

List of tuples containing source, target and weight.

Return type:

collections.abc.Sequence[tuple[int | str, int | str, float | int]]

ReturnType:

list[tuple[int | str, int | str, float | int]]

matplotlib_sankey.sankey(data, figsize=None, frameon=False, ax=None, spacing=0.0, annotate_columns=None, rel_column_width=0.15, color='tab10', curve_type='curve4', ribbon_alpha=0.2, ribbon_color='black', title=None, show=True, show_legend=False, legend_labels=None, column_labels=None, annotate_columns_font_kwargs=None, annotate_columns_font_color='auto', column_item_totals=None)#

Sankey plot.

Parameters:
  • data (list[list[tuple[int | str, int | str, float | int]]]) – Input data.

  • figsize (tuple[int, int] | None) – Size of figure. Defaults to None.

  • frameon (bool, optional) – Draw frame. Defaults to True.

  • ax (matplotlib.Axes | None, optional) – Provide matplotlib Axes instance for plotting. Defaults to None.

  • spacing (float, optional) – Spacing between column and ribbon patches. Defaults to 0.0.

  • annotate_columns (Literal["index", "weight", "weight_percent"], optional) – Annotate columns of plot. Annotations options are column name (index), column total weight (weight) or percent of weight (weight_percent). Defaults to None.

  • rel_column_width (float, optional) – Relative width of columns compared to ribbons. Defaults to 0.15. Value must be between 0 and 1.

  • color (Sequence[str] | Colormap | str | Sequence[tuple[float, float, float]], optional) – Colors or colormap for columns.

  • curve_type (Literal["curve3", "curve4", "line"], optional) – Curve type ofo ribbon. Defaults to "curve4".

  • ribbon_alpha (float, optional) – Alpha of ribbons. Defaults to 0.2.

  • ribbon_color (str, optional) – Color of ribbons. Defaults to "black".

  • title (str | None, optional) – Title of figure. Defaults to None.

  • show (bool, optional) – Show figure. Defaults to True.

  • show_legend (bool, optional) – Show legend. Defaults to False. If legend should be displayed, also provide legend_labels.

  • legend_labels (list[str] | None, optional) – Labels to display in legend. Defaults to None.

  • column_labels (list[str] | None, optional) – Labels for columns. Defaults to None.

  • annotate_columns_font_kwargs (dict[str, Any] | None, optional) – Extra arguments for column ax.text method of column annotation. Defaults to None.

  • annotate_columns_font_color (Literal["auto"] | ColorTuple | str, optional) – Color of column annotation text. Defaults to "auto", thereby automatically selectes text color based on background color.

  • column_item_totals (list[dict[int | str, float | int]] | None, optional) – Total values for each column item. If provided, column items are sized based on these totals instead of the sum of ribbon weights. Ribbons are adjusted proportionally within the column items. Defaults to None.

Returns:

Matplotlib axes instance.

Return type:

matplotlib.axes.Axes

ReturnType:

matplitlib.Axes