maui.visualizations.polar_bar_plot

maui.visualizations.polar_bar_plot(df, date_time_col, categories_col, percent=False, show_plot=True, **kwargs)[source]

Generate a polar bar plot to visualize category occurrences over the year. It will group data by day of the year, keep this in mind if you have more than one year of data.

Return type:

Figure

Parameters:
dfpandas.DataFrame

The input dataframe containing the data to plot.

date_time_colstr

The name of the column in df containing date or datetime values.

categories_colstr

The name of the column in df representing the categorical variable.

percentbool, optional, default: False

If True, the plot will display the data as percentages of total occurrences for each day. If False, raw counts will be used.

show_plotbool, optional, default: True

If True, the plot will be displayed. If False, the plot will be returned without displaying it.

**kwargsdict, optional

Additional keyword arguments passed to the plot layout, such as height and width for figure dimensions.

Returns:
plotly.graph_objects.Figure

The generated polar bar plot figure.

Raises:
AssertionError

If date_time_col or categories_col is not in df.

AttributeError

If categories_col contains continuous data instead of discrete categories.

Warns:
UserWarning

If date_time_col contains invalid date values, a warning is issued, and those rows are ignored in the plot.

Notes

  • The date_time_col is converted to the day of the year (1 to 366, to account for leap years).

  • If percent=True, the data is normalized by day to represent the proportion of occurrences.

Examples

>>> df = pd.DataFrame({
>>>     'date': pd.date_range(start='2023-01-01', periods=366, freq='D'),
>>>     'category': ['A', 'B', 'C'] * 122
>>> })
>>> fig = polar_bar_plot(df, 'date', 'category', percent=True)
>>> fig.show()