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 in turn so the next
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.
The placement is stored as a resize-invariant recipe and re-derived on every
draw by _ChromeLayoutEngine, so resizing the figure after this call (e.g.
fig.set_size_inches) re-wraps and re-flows the chrome to the new size.
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
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 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 | |
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
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 | |