Skip to content

Barplot API

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

Barplot FUNCTION

This API provides a function to create a customizable horizontal barplot from KEGGaNOG single mode output, typically used to visualize pathways completeness — it only takes pathways with completeness > 0.

barplot(df, ...)

PARAMETERS

PARAMETER DESCRIPTION
df Input data as a pandas DataFrame
TYPEpd.DataFrame
figsize Size of the figure (width, height)
TYPETuple[int, int]
DEFAULT(8, 12)
cmap Colormap name or list of colors
TYPEstr or list
DEFAULT"Greens"
cmap_range Colormap index range
TYPETuple[int, int]
DEFAULT(8, 30)
title Plot title
TYPEstr or None
DEFAULTNone
title_fontsize Font size of title
TYPEfloat
DEFAULT16.0
title_color Font color of title
TYPEstr
DEFAULT"black"
title_weight Font weight of title
TYPEstr
DEFAULT"normal"
title_style Font style of title
TYPEstr
DEFAULT"normal"
xlabel Label for X-axis
TYPEstr
DEFAULT"Pathway completeness"
xlabel_fontsize Font size of X-axis label
TYPEfloat
DEFAULT14.0
xlabel_color Font color of X-axis label
TYPEstr
DEFAULT"black"
xlabel_weight Font weight of X-axis label
TYPEstr
DEFAULT"normal"
xlabel_style Font style of X-axis label
TYPEstr
DEFAULT"normal"
ylabel Label for Y-axis
TYPEstr
DEFAULT"Pathway"
ylabel_fontsize Font size of Y-axis label
TYPEfloat
DEFAULT14.0
ylabel_color Font color of Y-axis label
TYPEstr
DEFAULT"black"
ylabel_weight Font weight of Y-axis label
TYPEstr
DEFAULT"normal"
ylabel_style Font style of Y-axis label
TYPEstr
DEFAULT"normal"
xticks_fontsize Font size of X-axis ticks
TYPEfloat
DEFAULT12.0
xticks_color Font color of X-axis ticks
TYPEstr
DEFAULT"black"
xticks_weight Font weight of X-axis ticks
TYPEstr
DEFAULT"normal"
xticks_style Font style of X-axis ticks
TYPEstr
DEFAULT"normal"
yticks_fontsize Font size of Y-axis ticks
TYPEfloat
DEFAULT12.0
yticks_color Font color of Y-axis ticks
TYPEstr
DEFAULT"black"
yticks_weight Font weight of Y-axis ticks
TYPEstr
DEFAULT"normal"
yticks_style Font style of Y-axis ticks
TYPEstr
DEFAULT"normal"
grid Display grid
TYPEbool
DEFAULTTrue
grid_linestyle Line style of grid lines
TYPEstr
DEFAULT: "--"
grid_alpha Opacity of grid lines
TYPEfloat
DEFAULT: 0.5
background_color Background color of the figure
TYPEstr or None
DEFAULT: None
sort_order Sort bars by value ("ascending" or "descending")
TYPEstr 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 single-sample mode

Where to get demo data? Here

! KEGGaNOG -i demo_data/LaPla/LaPla.emapper.annotations -o KEGGaNOG_single_output

Then user can easily build a barplot on KEGGaNOG output

import kegganog as kgn
import pandas as pd

df = pd.read_csv("KEGGaNOG_single_output/SAMPLE_pathways.tsv", sep="\t")

kgnbar = kgn.barplot(df,
    figsize = (8, 10),
    sort_order="descending",
    yticks_fontsize = 8, 
    cmap = "Blues",
)

# To plot a fig please use:
kgnbar.plotfig()

Sample output:

image

kgn.barplot() returns an object containing the barplot figure and axis, so, user is able to further customize its plot!
E.g. user wants to divide pathways with completeness > 0.5 and < 0.5:

kgnbar.ax.axvline(0.5, color="red", linestyle="--")

kgnbar.plotfig()

Sample output:

image

For saving a plot please use:

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

Clone this wiki locally