Waterfall Plot
Waterfall chart from amounts and labels lists (not DataFrame-based).
Each amount is rendered as a bar stacked on the running total, colored by sign.
format_data_labels(amounts, total_change, label_format, decimals)
Format the bar data labels for a waterfall chart.
label_format is "absolute", "percentage", or "both"; percentages are a share of total_change (not of the displayed sum). When total_change is 0 a UserWarning is raised and the percentage is omitted ("both" falls back to absolute).
Source code in openretailscience/plots/waterfall.py
plot(amounts, labels, title=None, eyebrow=None, subtitle=None, y_label=None, x_label='', source_text=None, data_label_format=None, display_net_bar=False, display_net_line=False, remove_zero_amounts=True, ax=None, **kwargs)
Generate a waterfall chart from parallel amounts and labels lists.
"percentage" labels are each bar's share of the net total, so they can exceed 100% or be negative when bars have mixed signs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amounts
|
list[float]
|
The amounts to plot. |
required |
labels
|
list[str]
|
The labels, one per amount. |
required |
title
|
str
|
Chart title. |
None
|
eyebrow
|
str
|
Uppercase label rendered above the title. |
None
|
subtitle
|
str
|
Supporting copy rendered below the title. |
None
|
y_label
|
str
|
Y-axis label; omitted means no label. |
None
|
x_label
|
str
|
X-axis label; omitted means no label. |
''
|
source_text
|
str
|
Source attribution rendered at the bottom. |
None
|
data_label_format
|
(absolute, percentage, both)
|
Format for the bar data labels; None draws no labels. |
None
|
display_net_bar
|
bool
|
Append a "Net" bar for the total. |
False
|
display_net_line
|
bool
|
Draw a dashed line at the net total. |
False
|
remove_zero_amounts
|
bool
|
Hide zero-amount bars and their labels. |
True
|
ax
|
Axes
|
Axes to plot on. |
None
|
**kwargs
|
Any
|
Forwarded to pandas' |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Axes |
Axes
|
The matplotlib axes object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If len(amounts) != len(labels), or data_label_format is not one of "absolute", "percentage", "both". |
Source code in openretailscience/plots/waterfall.py
25 26 27 28 29 30 31 32 33 34 35 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 | |