Skip to content

Streamgraph API

Ilia Popov edited this page Sep 25, 2025 · 3 revisions

Streamgraph FUNCTION

This API provides a function to create a streamgraph from KEGGaNOG multi-sample output. It visualizes completeness values of pathway groups across multiple samples using a flowing stacked area plot.


PARAMETERS

PARAMETER DESCRIPTION
df Input data as a pandas DataFrame
TYPE: pd.DataFrame
figsize Size of the figure (width, height)
TYPE: Tuple[int, int]
DEFAULT: (14, 7)
bar_width Width parameter for sample
TYPE: float
DEFAULT: 0.6
cmap Colormap name (e.g. "tab20") or list of HEX colors for groups
TYPE: str or List[str]
DEFAULT: "tab20"
fill_alpha Transparency of the filled area
TYPE: float
DEFAULT: 1.0
edgecolor Outline color for each stacked area (group layer)
TYPE: str or None
DEFAULT: None
edge_linewidth Width of group layer outlines
TYPE: float
DEFAULT: 0.3
title Plot title
TYPE: str or None
DEFAULT: None
title_fontsize Font size of the title
TYPE: float
DEFAULT: 16.0
title_color Font color of the title
TYPE: str
DEFAULT: "black"
title_weight Font weight of the title
TYPE: str
DEFAULT: "normal"
title_style Font style of the title
TYPE: str
DEFAULT: "normal"
xlabel Label for the x-axis
TYPE: str
DEFAULT: "Samples"
xlabel_fontsize Font size for x-axis label
TYPE: float
DEFAULT: 12.0
xlabel_color Font color of x-axis label
TYPE: str
DEFAULT: "black"
xlabel_weight Font weight of x-axis label
TYPE: str
DEFAULT: "normal"
xlabel_style Font style of x-axis label
TYPE: str
DEFAULT: "normal"
ylabel Label for the y-axis
TYPE: str
DEFAULT: "Total Completeness"
ylabel_fontsize Font size for y-axis label
TYPE: float
DEFAULT: 12.0
ylabel_color Font color of y-axis label
TYPE: str
DEFAULT: "black"
ylabel_weight Font weight of y-axis label
TYPE: str
DEFAULT: "normal"
ylabel_style Font style of y-axis label
TYPE: str
DEFAULT: "normal"
xticks_rotation Rotation angle of x-axis tick labels
TYPE: float
DEFAULT: 45.0
xticks_ha Horizontal alignment of x-axis tick labels
TYPE: str
DEFAULT: "center"
xticks_fontsize Font size of x-axis tick labels
TYPE: float
DEFAULT: 12.0
xticks_color Font color of x-axis tick labels
TYPE: str
DEFAULT: "black"
xticks_weight Font weight of x-axis tick labels
TYPE: str
DEFAULT: "normal"
xticks_style Font style of x-axis tick labels
TYPE: str
DEFAULT: "normal"
grid Whether to show grid lines
TYPE: bool
DEFAULT: True
grid_linestyle Grid line style (e.g. "--")
TYPE: str
DEFAULT: "--"
grid_alpha Transparency of grid lines
TYPE: float
DEFAULT: 0.7
legend_fontsize Font size of legend labels
TYPE: float
DEFAULT: 9.0
legend_loc Legend position keyword
TYPE: str
DEFAULT: "upper left"
legend_bbox Manual legend box anchor
TYPE: Tuple[float, float]
DEFAULT: (1.05, 1)
show_legend Whether to display legend
TYPE: bool
DEFAULT: True
background_color Background color of the figure
TYPE: str or None
DEFAULT: None

RETURNS

Returns an object with:

  • fig: the Matplotlib figure
  • ax: the Matplotlib axis

The object includes .plotfig() and .savefig() methods for visualization or export.


USAGE EXAMPLE

First, run KEGGaNOG in multi-sample mode:

Where to get demo data? Here

! KEGGaNOG -M -i demo_data/listFile.txt -o KEGGaNOG_multi_output

Then you can visualize pathway group completeness across samples:

import kegganog as kgn
import pandas as pd

df = pd.read_csv("KEGGaNOG_multi_output/merged_pathways.tsv", sep="\t")

kgnstream = kgn.streamgraph(
    df,
    figsize=(14, 7),
    cmap="tab20",
    xlabel="Samples",
    ylabel="Completeness",
    edgecolor="black",
    grid=True
    )

# Show the figure
kgnstream.plotfig()

Sample output:

kgnstream_OLD

To save the plot:

kgnstream.savefig("pic_name.png", dpi=600)

Clone this wiki locally