explore_violin_plot_by_group

source

explore_violin_plot_by_group(
    df,
    by_var,
    var,
    *,
    order_by_mean=False,
    group_on_y=True,
    title=None,
    subtitle=None,
)

Violin plots of var distribution across by_var groups.

Parameters

Name Type Description Default
df pd.DataFrame Data frame containing the grouping factor and the numeric variable. required
by_var str Grouping column. required
var str Numeric variable whose distribution is shown. required
order_by_mean bool If True, groups are ordered by descending group mean. False
group_on_y bool If True (default), violins are oriented horizontally (groups on the y-axis). True

Returns

Name Type Description
ByGroupViolinResult df (the complete-case [by_var, var] frame) and the Plotly fig.

Examples

Basic — distribution of a variable across groups:

import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def

df = ex.set_labels(load_kuznets(), load_kuznets_data_def(), set_panel=True)
ex.explore_violin_plot_by_group(df, "continent", "gini_regional").fig

Advanced — order groups by their mean and orient the violins vertically:

import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def

df = ex.set_labels(load_kuznets(), load_kuznets_data_def(), set_panel=True)
ex.explore_violin_plot_by_group(
    df, "continent", "gini_regional", order_by_mean=True, group_on_y=False
).fig