Scatter Plot
Scatter and bubble plots from a DataFrame.
label_col is not supported when value_col is a list (ValueError), and size_col
must contain numeric, non-negative values.
plot(df, value_col, x_label=None, y_label=None, title=None, eyebrow=None, subtitle=None, x_col=None, group_col=None, size_col=None, size_scale=1.0, figsize=None, ax=None, source_text=None, legend_title=None, move_legend_outside=False, label_col=None, label_kwargs=None, **kwargs)
Plot a scatter chart for value_col over x_col (or the index), optionally grouped.
A value_col list and a group_col are mutually exclusive. When size_col is set and
s is also in kwargs, a UserWarning is raised and s is ignored. Alpha defaults to 0.7.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame or Series
|
Frame to plot; a Series is converted to a single-column frame. |
required |
value_col
|
str or list[str]
|
Column(s) to plot. |
required |
x_label
|
str
|
X-axis label; omitted means no label. |
None
|
y_label
|
str
|
Y-axis label; omitted means no label. |
None
|
title
|
str
|
Plot title. |
None
|
eyebrow
|
str
|
Uppercase label rendered above the title. |
None
|
subtitle
|
str
|
Supporting copy rendered below the title. |
None
|
x_col
|
str
|
Column used as the x-axis; if None, the index is used. |
None
|
group_col
|
str
|
Column used to split the data into separate series. |
None
|
size_col
|
str
|
Column with the values used for point sizes (bubble chart); when set with no group_col, the same sizes apply to every series. |
None
|
size_scale
|
float
|
Multiplier; actual size = size_col value * size_scale. |
1.0
|
figsize
|
tuple[int, int]
|
Figure size, used only when ax is None. |
None
|
ax
|
Axes
|
Axes to plot on. |
None
|
source_text
|
str
|
Source attribution rendered at the bottom. |
None
|
legend_title
|
str
|
Legend title. |
None
|
move_legend_outside
|
bool
|
Move the legend outside the plot. |
False
|
label_col
|
str
|
Column with a text label per point; not supported when value_col is a list. |
None
|
label_kwargs
|
dict
|
Extra args passed to textalloc.allocate (draw_lines defaults to False). |
None
|
**kwargs
|
Any
|
Forwarded to matplotlib scatter. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
KeyError
|
If |
ValueError
|
If |
Source code in openretailscience/plots/scatter.py
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 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |