-
Notifications
You must be signed in to change notification settings - Fork 4
Stacked Barplot API
Ilia Popov edited this page Sep 25, 2025
·
4 revisions
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.
| 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 groupsTYPE: str or List[str]DEFAULT: "tab20"
|
bar_width |
Width parameter for sample TYPE: floatDEFAULT: 0.6
|
edgecolor |
Color of the edges around each stacked area TYPE: strDEFAULT: "black"
|
edge_linewidth |
Line width of group borders in each stacked bar TYPE: floatDEFAULT: 0.3
|
title |
Plot title TYPE: str or NoneDEFAULT: None
|
title_fontsize |
Font size of the title TYPE: floatDEFAULT: 16.0
|
title_color |
Font color of the title TYPE: strDEFAULT: "black"
|
title_weight |
Font weight of the title TYPE: strDEFAULT: "normal"
|
title_style |
Font style of the title TYPE: strDEFAULT: "normal"
|
xlabel |
Label for the x-axis TYPE: strDEFAULT: "Samples"
|
xlabel_fontsize |
Font size for x-axis label TYPE: floatDEFAULT: 12.0
|
xlabel_color |
Font color of x-axis label TYPE: strDEFAULT: "black"
|
xlabel_weight |
Font weight of x-axis label TYPE: strDEFAULT: "normal"
|
xlabel_style |
Font style of x-axis label TYPE: strDEFAULT: "normal"
|
ylabel |
Label for the y-axis TYPE: strDEFAULT: "Total Completeness"
|
ylabel_fontsize |
Font size for y-axis label TYPE: floatDEFAULT: 12.0
|
ylabel_color |
Font color of y-axis label TYPE: strDEFAULT: "black"
|
ylabel_weight |
Font weight of y-axis label TYPE: strDEFAULT: "normal"
|
ylabel_style |
Font style of y-axis label TYPE: strDEFAULT: "normal"
|
xticks_rotation |
Rotation angle of x-axis tick labels TYPE: floatDEFAULT: 45.0
|
xticks_ha |
Horizontal alignment of x-axis tick labels TYPE: strDEFAULT: "center"
|
xticks_fontsize |
Font size of x-axis tick labels TYPE: floatDEFAULT: 12.0
|
xticks_color |
Font color of x-axis tick labels TYPE: strDEFAULT: "black"
|
xticks_weight |
Font weight of x-axis tick labels TYPE: strDEFAULT: "normal"
|
xticks_style |
Font style of x-axis tick labels TYPE: strDEFAULT: "normal"
|
grid |
Whether to show grid lines TYPE: boolDEFAULT: True
|
grid_linestyle |
Line style for the grid (e.g. "--")TYPE: strDEFAULT: "--"
|
grid_alpha |
Transparency of grid lines TYPE: floatDEFAULT: 0.7
|
legend_fontsize |
Font size of the legend TYPE: floatDEFAULT: 9.0
|
legend_loc |
Location of the legend TYPE: strDEFAULT: "upper left"
|
legend_bbox |
Manual anchor for legend box TYPE: Tuple[float, float]DEFAULT: (1.05, 1)
|
show_legend |
Whether to display legend TYPE: boolDEFAULT: True
|
background_color |
Background color of the figure TYPE: str or NoneDEFAULT: None
|
Returns an object with:
-
fig: the Matplotlib figure -
ax: the Matplotlib axis
The object includes .plotfig() and .savefig() methods for convenience.
First, run KEGGaNOG in multi-sample mode:
Where to get demo data? Here
KEGGaNOG -M -i demo_data/listFile.txt -o KEGGaNOG_multi_outputThen 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:

To save the plot:
kgnstbar.savefig("pic_name.png", dpi=600)