Waterfall Plot
This module provides functionality to generate a waterfall chart.
A visualization commonly used to illustrate how different positive and negative values contribute to a cumulative total.Waterfall charts are effective in showing the incremental impact of individual components, making them particularly useful for financial analysis, performance tracking, and visualizing changes over time.
Features
- Waterfall Chart Creation: Displays how different positive and negative values affect a starting total.
- Data Label Formatting: Supports custom formatting for data labels, including absolute values, percentages, or both.
- Net Line and Bar Display: Optionally includes a net line and net bar to show the overall cumulative result.
- Customizable Plot Style: Options to customize chart titles, axis labels, and remove zero amounts for better clarity.
- Handling of Zero Amounts: Allows removal of zero amounts from the plot to avoid cluttering the chart.
- Interactive Elements: Supports custom annotations for the chart with source text.
Use Cases
- Financial Analysis: Show the breakdown of profits and losses over multiple periods, or how different cost categories affect overall margin.
- Revenue Tracking: Track how revenue or other key metrics change over time, and visualize the impact of individual contributing factors.
- Performance Visualization: Highlight how various business or product categories affect overall performance, such as sales, expenses, or growth metrics.
- Budget Breakdown: Visualize how different spending categories contribute to a total budget over a period.
Functionality Details
- plot(): Generates a waterfall chart from a list of amounts and labels. It supports additional customization for display settings, labels, and source text.
- format_data_labels(): A helper function used to format the data labels according to the specified format (absolute, percentage, both).
format_data_labels(amounts, total_change, label_format, decimals)
Format the data labels based on the specified format.
Source code in pyretailscience/plots/waterfall.py
plot(amounts, labels, title=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)
Generates a waterfall chart.
Waterfall plots are particularly good for showing how different things add or subtract from a starting number. For instance: - Changes in sales figures from one period to another - Breakdown of profit margins - Impact of different product categories on overall revenue
They are often used to identify key drivers of financial performance, highlight areas for improvement, and communicate complex data stories to stakeholders in an intuitive manner.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
amounts |
list[float]
|
The amounts to plot. |
required |
labels |
list[str]
|
The labels for the amounts. |
required |
title |
str
|
The title of the chart. Defaults to None. |
None
|
y_label |
str
|
The y-axis label. Defaults to None. |
None
|
x_label |
str
|
The x-axis label. Defaults to None. |
''
|
source_text |
str
|
The source text to add to the plot. Defaults to None. |
None
|
data_label_format |
Literal['absolute', 'percentage', 'both', 'none']
|
The format of the data labels. Defaults to "absolute". |
None
|
display_net_bar |
bool
|
Whether to display a net bar. Defaults to False. |
False
|
display_net_line |
bool
|
Whether to display a net line. Defaults to False. |
False
|
remove_zero_amounts |
bool
|
Whether to remove zero amounts from the plot. Defaults to True |
True
|
ax |
Axes
|
The matplotlib axes object to plot on. Defaults to None. |
None
|
**kwargs |
dict[str, any]
|
Additional keyword arguments to pass to the Pandas plot function. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Axes |
Axes
|
The matplotlib axes object. |
Source code in pyretailscience/plots/waterfall.py
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 155 156 157 158 159 160 161 162 163 164 165 166 |
|