Styling Helpers
Module-level helpers that apply styling using the options system.
apply_base_styling(ax, grid_axis='both', hide_spines=False)
Apply base plot styling (spines, grid, background) using options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax |
Axes
|
The axes to style. |
required |
grid_axis |
GridAxis
|
Which axis grid lines to draw. |
'both'
|
hide_spines |
bool
|
If True, hide all four axis spines regardless of the per-spine style options. Use for plots where cell colours or shapes already define the boundaries (heatmap, cohort) and spines would only repeat that information. |
False
|
Source code in openretailscience/plots/styles/styling_helpers.py
apply_chart_chrome(ax, *, eyebrow=None, title=None, subtitle=None, source_text=None, warn_stacklevel=4)
Place the figure-level chrome (eyebrow, tab, title, subtitle, source) and reflow the axes.
Sequential layout: each header element is placed and drawn in turn so
the next element starts directly below the previous one's measured
bbox. Wrapped titles therefore push subsequent elements down by their
actual rendered height, never their estimated height. After the header
and source are placed, tight_layout reflows the axes (with their
tick and axis labels) into the remaining vertical band.
Each absent element collapses its slot, so a chart with only a title takes only the vertical space the title needs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax |
Axes
|
The plot axes (used to get the figure handle). |
required |
eyebrow |
str | None
|
Small uppercase label above the title. |
None
|
title |
str | None
|
Main headline. Wraps if it would exceed the figure width. |
None
|
subtitle |
str | None
|
Supporting copy below the title. Wraps. |
None
|
source_text |
str | None
|
Footer text (rendered italic, muted). |
None
|
warn_stacklevel |
int
|
Stacklevel for the multi-axes chrome warning. Defaults to 4
so the warning points at user code when reached via
|
4
|
The small green tab mark above the title block is controlled by the
plot.style.show_tab option (default True). Set the option to False to
suppress it project-wide; use option_context to scope the change.
Source code in openretailscience/plots/styles/styling_helpers.py
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 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
apply_label(ax, label, axis, pad=None)
Apply axis label styling using options.
Source code in openretailscience/plots/styles/styling_helpers.py
apply_legend(ax, title=None, outside=False, *, reverse=False, custom_labels=None)
Apply legend styling using options.
Handles are read from ax via get_legend_handles_labels() so the legend
can be rebuilt with reversed order (stacked-area / stacked-bar visual stack)
or substituted labels (e.g. column ids → human-readable names) in a single
build. Calling this once from standard_graph_styles rather than after it
ensures chrome's tight_layout reserves the slot matching the final legend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax |
Axes
|
The axes whose labelled artists drive the legend. |
required |
title |
str | None
|
Legend title; |
None
|
outside |
bool
|
Anchor the legend outside the axes when |
False
|
reverse |
bool
|
Reverse the handle and label order before rebuilding. |
False
|
custom_labels |
list[str] | None
|
Override the labels read off |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in openretailscience/plots/styles/styling_helpers.py
apply_ticks(ax)
Apply tick styling using options.
Source code in openretailscience/plots/styles/styling_helpers.py
standard_graph_styles(ax, title=None, x_label=None, y_label=None, x_label_pad=None, y_label_pad=None, legend_title=None, move_legend_outside=False, show_legend=True, legend_style=None, legend_reverse=False, legend_labels=None, eyebrow=None, subtitle=None, source_text=None, grid_axis='both', x_margin=None, hide_spines=False)
Apply standard styles to a Matplotlib graph using styling helpers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax |
Axes
|
The graph to apply the styles to. |
required |
title |
str
|
The title of the graph. Defaults to None. |
None
|
x_label |
str
|
The x-axis label. Defaults to None. |
None
|
y_label |
str
|
The y-axis label. Defaults to None. |
None
|
x_label_pad |
int
|
The padding below the x-axis label. Defaults to styling context default. |
None
|
y_label_pad |
int
|
The padding to the left of the y-axis label. Defaults to styling context default. |
None
|
legend_title |
str
|
The title of the legend. If None, no legend title is applied. Defaults to None. |
None
|
move_legend_outside |
bool
|
Whether to move the legend outside the plot. Defaults to False. |
False
|
show_legend |
bool
|
Whether to display the legend or not. |
True
|
legend_style |
Literal['box', 'end_of_line']
|
When |
None
|
legend_reverse |
bool
|
Reverse handle and label order before building the legend. Used by stacked area/bar plots where the column-order legend doesn't match the visual stack (bottom-up). Defaults to False. |
False
|
legend_labels |
list[str] | None
|
Override the labels read from labelled artists
(e.g. swap column ids for human-readable names). Applied after |
None
|
eyebrow |
str
|
Small uppercase label rendered above the title. Defaults to None. |
None
|
subtitle |
str
|
Supporting copy rendered below the title. Defaults to None. |
None
|
source_text |
str
|
Footer text rendered italic and muted at the bottom-left of the figure. The chrome layout engine reserves room for it. |
None
|
grid_axis |
Literal['both', 'x', 'y', 'none']
|
Which axis to draw gridlines on.
Defaults to |
'both'
|
x_margin |
float
|
If set, override matplotlib's default x-margin. Editorial line/area/time
charts pass |
None
|
hide_spines |
bool
|
If True, hide all four axis spines. Use for plots whose cell colours or shapes already define their boundaries (heatmap, cohort). Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Axes |
Axes
|
The graph with the styles applied. |
Source code in openretailscience/plots/styles/styling_helpers.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |