# neurostatx.io.viz

*module*

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/io/viz.py#L1-L1)

## neurostatx.io.viz.determine_layout

*function*

```python
def determine_layout(nb_axes)
```

Return a compact subplot grid for ``nb_axes`` panels.

**Parameters**

- `nb_axes` (`int`) — Number of axes to plot.

**Returns**

- `num_rows` (`int`) — Number of rows.
- `num_cols` (`int`) — Number of columns.

**Examples**

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

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/io/viz.py#L6-L31)

## neurostatx.io.viz.flexible_barplot

*function*

```python
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**

- `df` (`pd.DataFrame`) — Values to plot. The index is used as the x-axis and each column is drawn on its own axis.
- `nb_axes` (`int`) — Number of axes to plot.
- `output` (`str`) — Output filename.
- `cmap` (`str`) (default: `'magma'`) — Colormap name. Defaults to ``"magma"``.
- `title` (`str`) (default: `'Barplot'`) — Title of the figure. Defaults to ``"Barplot"``.
- `xlabel` (`str`) (default: `None`) — Label for the x-axis. Defaults to None.
- `ylabel` (`str`) (default: `None`) — Label for the y-axis. Defaults to None.

**Examples**

```pycon
>>> 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")
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/io/viz.py#L34-L111)

## neurostatx.io.viz.flexible_hist

*function*

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

Write a single histogram of all dataframe columns.

**Parameters**

- `df` (`pd.DataFrame`) — Values to plot. Columns are treated as separate variables.
- `output` (`str`) — Output filename.
- `cmap` (`str`) (default: `'magma'`) — Colormap name. Defaults to ``"magma"``.
- `title` (`str`) (default: `'Histogram'`) — Title of the plot. Defaults to ``"Histogram"``.
- `xlabel` (`str`) (default: `None`) — Label for the x-axis. Defaults to None.
- `ylabel` (`str`) (default: `None`) — Label for the y-axis. Defaults to None.

**Examples**

```pycon
>>> 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")
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/io/viz.py#L181-L228)

## neurostatx.io.viz.generate_coef_plot

*function*

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

Write a horizontal coefficient bar plot with significance stars.

**Parameters**

- `df` (`pd.DataFrame`) — Table of coefficients and variable names.
- `pval` (`array - like`) — P-values aligned with ``df``. Values below 0.05 are marked with ``*``.
- `coefname` (`str`) — Name of the column containing the coefficients.
- `varname` (`str`) — Name of the column containing the variable names.
- `output` (`str`) — Output filename.
- `cmap` (`str`) (default: `'magma'`) — Colormap name. Defaults to ``"magma"``.

**Examples**

```pycon
>>> 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")
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/io/viz.py#L114-L178)
