Skip to content

Stacked Barplot API

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

Stacked Barplot FUNCTION

This API provides a function to create a stacked bar plot from KEGGaNOG multi-sample output. It visualizes pathway completeness grouped by functional categories across samples using stacked vertical bars.


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)
cmap Colormap name (e.g. "tab20") or list of HEX colors for pathway groups
TYPE: str or List[str]
DEFAULT: "tab20"
bar_width Width parameter for sample
TYPE: float
DEFAULT: 0.6
edgecolor Color of the edges around each stacked area
TYPE: str
DEFAULT: "black"
edge_linewidth Line width of group borders in each stacked bar
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 Line style for the grid (e.g. "--")
TYPE: str
DEFAULT: "--"
grid_alpha Transparency of grid lines
TYPE: float
DEFAULT: 0.7
legend_fontsize Font size of the legend
TYPE: float
DEFAULT: 9.0
legend_loc Location of the legend
TYPE: str
DEFAULT: "upper left"
legend_bbox Manual anchor for legend box
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 convenience.


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 visualize the completeness of pathway groups across samples:

import kegganog as kgn
import pandas as pd

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

kgnstbar = kgn.stacked_barplot(
    df,
    figsize=(14, 7),
    cmap="tab20",
    xlabel="Samples",
    ylabel="Completeness",
    xticks_rotation=0,
    xticks_ha="center",
    )

# Show the figure
kgnstbar.plotfig()

Sample output:

kgnstbar_OLD

To save the plot:

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

Clone this wiki locally