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.
Resets any pre-existing (pandas) grid before applying the styled one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
The axes to style. |
required |
grid_axis
|
GridAxis
|
|
'both'
|
hide_spines
|
bool
|
Hide all four spines, for plots whose cells define the boundaries (heatmap, cohort). |
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)
Add the header (tab, eyebrow, title, subtitle) above the axes and the source below it.
The axes shrink to make room; an omitted element takes no space. The layout survives a
later figure resize, and calling this again on the same axes replaces its chrome. The tab
mark follows the plot.style.show_tab option (default True).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
The plot axes; the chrome is drawn on its figure. |
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; 4 points at user
code via |
4
|
Source code in openretailscience/plots/styles/styling_helpers.py
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.
Call it before apply_chart_chrome (standard_graph_styles does) so the chrome
leaves room for the 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. |
False
|
reverse
|
bool
|
Reverse the legend entry order. |
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 (spines, grid, ticks, legend, chrome) to a Matplotlib graph.
With legend_style="end_of_line" the box legend is suppressed and inline labels are
drawn at each line's right endpoint; legend_title and
move_legend_outside are ignored under it (UserWarning if set).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
The graph to apply the styles to. |
required |
title
|
str | None
|
Chart title. |
None
|
x_label
|
str | None
|
X-axis label; when omitted, any existing label (e.g. pandas' column name) is cleared. |
None
|
y_label
|
str | None
|
Y-axis label; when omitted, any existing label (e.g. pandas' column name) is cleared. |
None
|
x_label_pad
|
int | None
|
Padding below the x-axis label. |
None
|
y_label_pad
|
int | None
|
Padding to the left of the y-axis label. |
None
|
legend_title
|
str | None
|
Legend title. |
None
|
move_legend_outside
|
bool
|
Anchor the legend outside the plot. |
False
|
show_legend
|
bool
|
Whether to display the legend. |
True
|
legend_style
|
Literal['box', 'end_of_line'] | None
|
|
None
|
legend_reverse
|
bool
|
Reverse the legend entry order; used by stacked area/bar plots where column order does not match the visual stack. |
False
|
legend_labels
|
list[str] | None
|
Override the legend labels, given in final on-screen order (after
|
None
|
eyebrow
|
str | None
|
Small uppercase label rendered above the title. |
None
|
subtitle
|
str | None
|
Supporting copy rendered below the title. |
None
|
source_text
|
str | None
|
Footer text rendered italic and muted at the bottom-left of the figure. |
None
|
grid_axis
|
GridAxis
|
Which axis to draw gridlines on. |
'both'
|
x_margin
|
float | None
|
Override matplotlib's default x-margin; line/area/time/histogram/
period_on_period pass |
None
|
hide_spines
|
bool
|
Hide all four spines, for plots whose cells define the boundaries (heatmap, cohort). |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Axes |
Axes
|
The graph with the styles applied. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in openretailscience/plots/styles/styling_helpers.py
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 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 | |