-
Notifications
You must be signed in to change notification settings - Fork 4
Boxplot API
Ilia Popov edited this page May 6, 2025
·
5 revisions
This API provides a function to create a customizable boxplot from KEGGaNOG multi mode output, typically used to visualize pathway completeness across multiple samples.
It includes features for styling axes, grid lines, background color, and boxplot outlier visibility.
boxplot(df, ...)
| PARAMETER | DESCRIPTION |
|---|---|
df |
Input data as a pandas DataFrame TYPE: pd.DataFrame
|
figsize |
Size of the figure (width, height) TYPE: Tuple[int, int]DEFAULT: (12, 6)
|
color |
Box color TYPE: str or NoneDEFAULT: "blue"
|
showfliers |
Whether to show outlier points TYPE: boolDEFAULT: True
|
title |
Plot title TYPE: str or NoneDEFAULT: None
|
title_fontsize |
Font size of title TYPE: floatDEFAULT: 16.0
|
title_color |
Font color of title TYPE: strDEFAULT: "black"
|
title_weight |
Font weight of title TYPE: strDEFAULT: "normal"
|
title_style |
Font style of title TYPE: strDEFAULT: "normal"
|
xlabel |
Label for X-axis TYPE: strDEFAULT: "Samples"
|
xlabel_fontsize |
Font size of X-axis label TYPE: floatDEFAULT: 14.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 Y-axis TYPE: strDEFAULT: "Completeness Value"
|
ylabel_fontsize |
Font size of Y-axis label TYPE: floatDEFAULT: 14.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 for X-axis tick labels TYPE: floatDEFAULT: 45.0
|
xticks_ha |
Horizontal alignment of X-axis ticks TYPE: strDEFAULT: "center"
|
xticks_fontsize |
Font size of X-axis ticks TYPE: floatDEFAULT: 12.0
|
xticks_color |
Font color of X-axis ticks TYPE: strDEFAULT: "black"
|
xticks_weight |
Font weight of X-axis ticks TYPE: strDEFAULT: "normal"
|
xticks_style |
Font style of X-axis ticks TYPE: strDEFAULT: "normal"
|
yticks_fontsize |
Font size of Y-axis ticks TYPE: floatDEFAULT: 12.0
|
yticks_color |
Font color of Y-axis ticks TYPE: strDEFAULT: "black"
|
yticks_weight |
Font weight of Y-axis ticks TYPE: strDEFAULT: "normal"
|
yticks_style |
Font style of Y-axis ticks TYPE: strDEFAULT: "normal"
|
grid |
Display grid TYPE: boolDEFAULT: True
|
grid_color |
Color of grid lines TYPE: strDEFAULT: "grey"
|
grid_linestyle |
Style of grid lines TYPE: strDEFAULT: "--"
|
grid_linewidth |
Width of grid lines TYPE: floatDEFAULT: 0.5
|
background_color |
Background color of the figure TYPE: str or NoneDEFAULT: None
|
Returns an object with:
-
fig: the Matplotlib figure object -
ax: the Matplotlib axis object
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_output
Then You can easily build a boxplot on KEGGaNOG output
import kegganog as kgn
import pandas as pd
df = pd.read_csv("KEGGaNOG_multi_output/merged_pathways.tsv", sep="\t")
kgnbox = kgn.boxplot(
df,
color="#90ee90",
title="", title_fontsize = 12, title_weight = "normal",
xticks_rotation = 0,
ylabel="Pathways completeness value", ylabel_fontsize = 12, ylabel_weight = "normal",
figsize=(10, 6),
)
# To plot a fig please use:
kgnbox.plotfig()Sample output:

kgn.boxplot() returns an object containing the boxplot figure and axis, so, user is able to further customize its plot!
E.g. the user wants to visually highlight a completeness threshold of 0.3 across samples:
kgnbox.ax.axhline(0.3, color="red", linestyle="--", linewidth=1.5)
kgnbox.plotfig()Sample output:

For saving a plot please use:
kgnbox.savefig("pic_name.png", dpi=600)