Price Plot
This module provides functionality for creating bubble chart visualizations that display price distribution analysis across different categories.
The bubble chart shows price distribution as vertical layers (price bands) with bubble sizes representing the percentage of products in each price range for different categories like retailers, countries, etc.
Core Features
- Price Band Analysis: Automatically bins price data into ranges using pandas.cut()
- Categorical Grouping: Groups data by categorical columns (retailers, countries, etc.)
- Bubble Sizing: Bubble sizes represent percentage of products in each price band per group
- Flexible Binning: Supports both integer (equal-width bins) and array (custom boundaries) inputs
- Grid Layout: X-axis shows categories, Y-axis shows price bands
Use Cases
- Retailer Price Comparison: Compare price distributions across different retailers
- Regional Price Analysis: Analyze price positioning by country/region
- Competitive Pricing: Identify pricing gaps and opportunities
- Price Architecture Visualization: Visualize competitive pricing landscapes
Limitations
- Pandas DataFrame Only: No Ibis table support
- Pre-aggregated Data: Data should be at product level (one row per product)
- Numeric Price Column: Requires numeric price/value column for binning
plot(df, value_col, group_col, bins, title=None, x_label=None, y_label=None, legend_title=None, ax=None, source_text=None, move_legend_outside=False, **kwargs)
Creates a bubble chart visualization showing price distribution analysis across categories.
The chart displays price bands as vertical layers with bubble sizes representing the percentage of products in each price range for different groups (retailers, countries, etc.).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Input DataFrame containing product-level data. |
required |
value_col |
str
|
Column containing the price/value data (e.g., "unit_price"). |
required |
group_col |
str
|
Column containing the categorical grouping (e.g., "retailer"). |
required |
bins |
int | list[float]
|
Either number of equal-width bins (int) or custom bin boundaries (list). |
required |
title |
str
|
The title of the plot. Defaults to None. |
None
|
x_label |
str
|
The label for the x-axis. Defaults to None. |
None
|
y_label |
str
|
The label for the y-axis. Defaults to None. |
None
|
legend_title |
str
|
The title for the legend. Defaults to None. |
None
|
ax |
Axes
|
The Matplotlib Axes object to plot on. Defaults to None. |
None
|
source_text |
str
|
Text to be displayed as a source at the bottom of the plot. Defaults to None. |
None
|
move_legend_outside |
bool
|
Whether to move the legend outside the plot area. Defaults to False. |
False
|
**kwargs |
dict[str, Any]
|
Additional keyword arguments for the scatter plot function. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
SubplotBase |
SubplotBase
|
The Matplotlib Axes object with the generated bubble chart. |
Raises:
Type | Description |
---|---|
ValueError
|
If DataFrame is empty, columns don't exist, or bins parameter is invalid. |
KeyError
|
If specified columns are not found in DataFrame. |
TypeError
|
If bins parameter has invalid type. |
Source code in pyretailscience/plots/price.py
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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|