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
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 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 | |
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
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 | |