vivainsights.create_bar_asis¶
Create a bar chart with customizable options and no pre-aggregation.
- vivainsights.create_bar_asis.create_bar_asis(data, group_var, bar_var, title=None, subtitle=None, caption=None, ylab=None, xlab=None, percent=False, bar_colour='default', rounding=1)[source]¶
Create a bar chart from pre-aggregated data.
Unlike
create_bar, this function does not perform any aggregation and plots the data as-is.- Parameters:
data (pandas.DataFrame) – Pre-aggregated data to plot.
group_var (str) – Column name for the x-axis categories.
bar_var (str) – Column name for the y-axis values.
title (str or None, default None) – Plot title.
subtitle (str or None, default None) – Plot subtitle.
caption (str or None, default None) – Plot caption.
ylab (str or None, default None) – Label for the y-axis.
xlab (str or None, default None) – Label for the x-axis.
percent (bool, default False) – Whether to format bar labels as percentages.
bar_colour (str, default "default") – Colour preset:
"default","alert", or"darkblue".rounding (int, default 1) – Number of decimal places for bar labels.
- Returns:
Displays the plot.
- Return type:
None
Examples
Basic bar chart from pre-aggregated data:
>>> import vivainsights as vi >>> import pandas as pd >>> df = pd.DataFrame({"Group": ["A", "B", "C"], "Value": [10, 20, 15]}) >>> vi.create_bar_asis(df, group_var="Group", bar_var="Value")
Customize title, subtitle, caption, and bar colour:
>>> vi.create_bar_asis( ... df, ... group_var="Group", ... bar_var="Value", ... title="Custom Title", ... subtitle="Breakdown by Group", ... caption="Source: sample data", ... bar_colour="alert", ... )
Display values as percentages with custom rounding:
>>> pct = pd.DataFrame({"Team": ["X", "Y"], "Rate": [0.75, 0.62]}) >>> vi.create_bar_asis(pct, group_var="Team", bar_var="Rate", percent=True, rounding=2)