Skip to content

Boxplot API

Ilia Popov edited this page May 6, 2025 · 5 revisions

Boxplot FUNCTION

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, ...)

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: (12, 6)
color Box color
TYPE: str or None
DEFAULT: "blue"
showfliers Whether to show outlier points
TYPE: bool
DEFAULT: True
title Plot title
TYPE: str or None
DEFAULT: None
title_fontsize Font size of title
TYPE: float
DEFAULT: 16.0
title_color Font color of title
TYPE: str
DEFAULT: "black"
title_weight Font weight of title
TYPE: str
DEFAULT: "normal"
title_style Font style of title
TYPE: str
DEFAULT: "normal"
xlabel Label for X-axis
TYPE: str
DEFAULT: "Samples"
xlabel_fontsize Font size of X-axis label
TYPE: float
DEFAULT: 14.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 Y-axis
TYPE: str
DEFAULT: "Completeness Value"
ylabel_fontsize Font size of Y-axis label
TYPE: float
DEFAULT: 14.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 for X-axis tick labels
TYPE: float
DEFAULT: 45.0
xticks_ha Horizontal alignment of X-axis ticks
TYPE: str
DEFAULT: "center"
xticks_fontsize Font size of X-axis ticks
TYPE: float
DEFAULT: 12.0
xticks_color Font color of X-axis ticks
TYPE: str
DEFAULT: "black"
xticks_weight Font weight of X-axis ticks
TYPE: str
DEFAULT: "normal"
xticks_style Font style of X-axis ticks
TYPE: str
DEFAULT: "normal"
yticks_fontsize Font size of Y-axis ticks
TYPE: float
DEFAULT: 12.0
yticks_color Font color of Y-axis ticks
TYPE: str
DEFAULT: "black"
yticks_weight Font weight of Y-axis ticks
TYPE: str
DEFAULT: "normal"
yticks_style Font style of Y-axis ticks
TYPE: str
DEFAULT: "normal"
grid Display grid
TYPE: bool
DEFAULT: True
grid_color Color of grid lines
TYPE: str
DEFAULT: "grey"
grid_linestyle Style of grid lines
TYPE: str
DEFAULT: "--"
grid_linewidth Width of grid lines
TYPE: float
DEFAULT: 0.5
background_color Background color of the figure
TYPE: str or None
DEFAULT: None

RETURNS

Returns an object with:

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

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 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:

image

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:

image

For saving a plot please use:

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

Clone this wiki locally