Skip to content

neurostatx.io.viz

Functions

NameDescription
determine_layoutReturn a compact subplot grid for nb_axes panels.
flexible_barplotWrite a multi-panel bar plot from a dataframe.
flexible_histWrite a single histogram of all dataframe columns.
generate_coef_plotWrite a horizontal coefficient bar plot with significance stars.

determine_layoutfunction#

def determine_layout(nb_axes)

Return a compact subplot grid for nb_axes panels.

Parameters

NameTypeDescription
nb_axesintNumber of axes to plot.

Returns

num_rowsint
Number of rows.
num_colsint
Number of columns.

Examples

>>> from neurostatx.io.viz import determine_layout
>>> determine_layout(4)
(2, 2)

flexible_barplotfunction#

def flexible_barplot(df, nb_axes, output, cmap='magma', title='Barplot', xlabel=None, ylabel=None)

Write a multi-panel bar plot from a dataframe.

Parameters

NameTypeDefaultDescription
dfpd.DataFramerequiredValues to plot. The index is used as the x-axis and each column is drawn on its own axis.
nb_axesintrequiredNumber of axes to plot.
outputstrrequiredOutput filename.
cmapstr'magma'Colormap name. Defaults to "magma".
titlestr'Barplot'Title of the figure. Defaults to "Barplot".
xlabelstrNoneLabel for the x-axis. Defaults to None.
ylabelstrNoneLabel for the y-axis. Defaults to None.

Examples

>>> import pandas as pd
>>> from neurostatx.io.viz import flexible_barplot
>>> df = pd.DataFrame({"a": [0.1, 0.2], "b": [0.3, 0.4]}, index=["x", "y"])
>>> flexible_barplot(df, nb_axes=2, output="barplot.png")

flexible_histfunction#

def flexible_hist(df, output, cmap='magma', title='Histogram', xlabel=None, ylabel=None)

Write a single histogram of all dataframe columns.

Parameters

NameTypeDefaultDescription
dfpd.DataFramerequiredValues to plot. Columns are treated as separate variables.
outputstrrequiredOutput filename.
cmapstr'magma'Colormap name. Defaults to "magma".
titlestr'Histogram'Title of the plot. Defaults to "Histogram".
xlabelstrNoneLabel for the x-axis. Defaults to None.
ylabelstrNoneLabel for the y-axis. Defaults to None.

Examples

>>> import pandas as pd
>>> from neurostatx.io.viz import flexible_hist
>>> df = pd.DataFrame({"a": [0.1, 0.2, 0.3], "b": [1.0, 1.1, 0.9]})
>>> flexible_hist(df, "hist.png")

generate_coef_plotfunction#

def generate_coef_plot(df, pval, coefname, varname, output, cmap='magma')

Write a horizontal coefficient bar plot with significance stars.

Parameters

NameTypeDefaultDescription
dfpd.DataFramerequiredTable of coefficients and variable names.
pvalarray - likerequiredP-values aligned with df. Values below 0.05 are marked with *.
coefnamestrrequiredName of the column containing the coefficients.
varnamestrrequiredName of the column containing the variable names.
outputstrrequiredOutput filename.
cmapstr'magma'Colormap name. Defaults to "magma".

Examples

>>> import pandas as pd
>>> from neurostatx.io.viz import generate_coef_plot
>>> df = pd.DataFrame({"var": ["a", "b"], "coef": [0.4, -0.2]})
>>> generate_coef_plot(df, [0.01, 0.2], "coef", "var", "coef.png")