prepare_by_group_violin_graph

prepare_by_group_violin_graph(
    df,
    by_var,
    var,
    *,
    order_by_mean=False,
    group_on_y=True,
)

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
plotly.graph_objects.Figure The violin figure.

Examples

Basic — distribution of a variable across groups (this function returns a Plotly figure directly, so there is no .fig attribute):

import expdpy as ex
from expdpy.data import load_kuznets

df = load_kuznets()
ex.prepare_by_group_violin_graph(df, "continent", "gini_regional")

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

ex.prepare_by_group_violin_graph(
    df, "continent", "gini_regional", order_by_mean=True, group_on_y=False
)