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_bar_plot(df, "continent").figexplore_bar_plot
explore_bar_plot(
df,
var,
*,
order_by_count=False,
color=None,
title=None,
subtitle=None,
)Bar chart of category counts for a (typically categorical) variable.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| df | pd.DataFrame | Data frame containing var. |
required |
| var | str | Column whose value counts are charted. | required |
| order_by_count | bool | If True, bars are ordered by descending count; otherwise by category. |
False |
| color | str | None | Bar fill color. Defaults to the primary theme color. | None |
Returns
| Name | Type | Description |
|---|---|---|
| BarChartResult | df (columns var and count) and the Plotly fig. |
Examples
Basic — category counts of a (typically categorical) variable, with readable labels from the data dictionary:
Advanced — order bars by descending count and set a custom color:
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_bar_plot(df, "continent", order_by_count=True, color="red").fig