Broken Timeline Plot
Broken timeline of data availability: horizontal bars per category over time.
Each bar spans periods with data; gaps mark missing periods. Values are aggregated per period (period D/W via agg_func) rather than plotted as raw rows; threshold filtering is supported.
plot(df, category_col, value_col, title=None, eyebrow=None, subtitle=None, x_label=None, y_label=None, ax=None, source_text=None, period='D', agg_func='sum', threshold_value=None, bar_height=0.8, figsize=None, **kwargs)
Plot data availability as horizontal bars per category, with gaps for missing periods.
value_col is aggregated with agg_func per category and period before plotting. The date
column is not a parameter; it is read from the column.transaction_date option and must be
present in df.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input frame; must include the |
required |
category_col
|
str
|
Column of categories, one bar row per category. |
required |
value_col
|
str
|
Column of values used to determine availability. |
required |
title
|
str
|
Plot title. |
None
|
eyebrow
|
str
|
Uppercase label rendered above the title. |
None
|
subtitle
|
str
|
Supporting copy rendered below the title. |
None
|
x_label
|
str
|
X-axis label; omitted means no label. |
None
|
y_label
|
str
|
Y-axis label; omitted means no label. |
None
|
ax
|
Axes
|
Axes to plot on. |
None
|
source_text
|
str
|
Source attribution rendered at the bottom. |
None
|
period
|
str
|
Aggregation period; "D"/"day" or "W"/"week" (case-insensitive). |
'D'
|
agg_func
|
str
|
Aggregation applied to value_col within each period. |
'sum'
|
threshold_value
|
float
|
Rows below this value are dropped before period aggregation. Bars always span whole periods, so a period left with no rows shows as a gap. |
None
|
bar_height
|
float
|
Bar thickness as a fraction of the available row space. |
0.8
|
figsize
|
tuple[int, int]
|
Figure size, used only when ax is None. |
None
|
**kwargs
|
Any
|
Forwarded to matplotlib broken_barh. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
SubplotBase |
SubplotBase
|
The matplotlib axes object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If df is empty, a required column is missing, or period is invalid. |
Source code in openretailscience/plots/broken_timeline.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |