Visualisation¶
Plotly-based plot helpers, theme registry, and time-series recorders.
Requires the [viz] extra.
Plot helpers¶
Every helper returns a plotly.graph_objects.Figure. Each accepts an
optional theme= and title=.
| Helper | Input |
|---|---|
plot_state_trajectories |
SimulationResult |
plot_phase_portrait |
SimulationResult with ≥2 state channels |
plot_queue_length |
QueueLengthRecorder |
plot_service_utilisation |
ServiceUtilisationRecorder |
plot_warehouse_stock |
WarehouseStockRecorder |
plot_mc_fan |
MCResult, ndarray, or (times, samples) |
plot_agent_path |
Agent (with optional graph=) |
Recorders¶
Recorders are Entity subclasses. Snapshot at registration and at
the end of every tick. Register them after the entity they observe:
Themes¶
Brand themes via register_theme:
sw.register_theme(
"edgeweave",
template="plotly_white",
palette=["#1c5d99", "#f49d37", "#0b132b", "#5fad56"],
layout_overrides={"font": {"family": "Inter, system-ui"}},
)
sw.set_default_theme("edgeweave")
EdgeWeave consumption¶
Every figure round-trips through JSON cleanly:
import json
fig = sw.plot_state_trajectories(res)
parsed = json.loads(fig.to_json())
assert "data" in parsed and "layout" in parsed
Gallery¶
Live output of every helper, regenerated on each docs build:
End-to-end demo¶
demos/14_viz_tour.py exercises every helper, writes one HTML per
figure under demos/viz_out/, and produces an index.html.
API¶
simweave.viz -- plotly-based visualisation helpers.
Every helper returns a plotly.graph_objects.Figure so JS frontends
(such as EdgeWeave) can consume the figure via fig.to_json() without
losing structure. Themes are applied via a small registry so users can
switch between light, dark and custom palettes without rebuilding plots.
Importing this module is cheap; plotly is only required when a plot helper is actually called. Install via the optional extra::
pip install simweave[viz]
Quick start::
from simweave.viz import (
plot_state_trajectories,
set_default_theme,
)
from simweave.continuous import simulate, MassSpringDamper
res = simulate(MassSpringDamper(), t_span=(0, 10), dt=0.01)
set_default_theme("dark")
fig = plot_state_trajectories(res)
fig.show() # or fig.write_html("msd.html"), or fig.to_json()
Theme
dataclass
¶
Theme(name: str, template: str, palette: tuple[str, ...] = tuple(), layout_overrides: dict[str, Any] = dict())
A named plotly styling bundle.
QueueLengthRecorder
¶
Bases: _Recorder
Sample len(queue) each tick.
Attributes:
| Name | Type | Description |
|---|---|---|
times |
list[float]
|
Simulation times of each sample. |
lengths |
list[int]
|
Queue length at each sample (matches |
Source code in src/simweave/viz/recorders.py
ServiceUtilisationRecorder
¶
Bases: _Recorder
Sample a Service's per-channel and aggregate utilisation each tick.
The simweave :class:~simweave.discrete.services.Service keeps a
monotonic busy_time per channel. We capture that snapshot and also
derive an aggregate running-mean utilisation
sum(busy_time) / (capacity * elapsed).
Attributes:
| Name | Type | Description |
|---|---|---|
times |
list[float]
|
Simulation times of each sample. |
busy_time |
list[ndarray]
|
|
utilisation |
list[float]
|
Running aggregate utilisation in |
instantaneous_busy |
list[ndarray]
|
|
Source code in src/simweave/viz/recorders.py
WarehouseStockRecorder
¶
Bases: _Recorder
Sample warehouse.inv.stock_level each tick.
Attributes:
| Name | Type | Description |
|---|---|---|
times |
list[float]
|
Simulation times of each sample. |
stock |
list[ndarray]
|
|
sku_names |
tuple[str, ...]
|
Names of the SKUs (snapshot at registration; stable thereafter). |
reorder_points |
ndarray
|
Reorder points snapshot at registration. |
Source code in src/simweave/viz/recorders.py
apply_theme
¶
Apply theme to fig in place and return fig.
Called by every plot helper. Safe to call again on a returned figure if the user wants to re-theme without rebuilding the data.
Source code in src/simweave/viz/themes.py
available_themes
¶
get_default_theme
¶
get_theme
¶
get_theme(name: str | None = None) -> Theme
Return the :class:Theme for name (or the current default).
Source code in src/simweave/viz/themes.py
register_theme
¶
register_theme(name: str, template: str, palette: tuple[str, ...] | list[str] | None = None, layout_overrides: dict[str, Any] | None = None, *, overwrite: bool = False) -> None
Register a new theme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Identifier used by |
required |
template
|
str
|
Name of a plotly built-in template ( |
required |
palette
|
tuple[str, ...] | list[str] | None
|
Optional sequence of hex/CSS colour strings used as the
|
None
|
layout_overrides
|
dict[str, Any] | None
|
Optional mapping merged into |
None
|
overwrite
|
bool
|
If False (default), raises |
False
|
Source code in src/simweave/viz/themes.py
set_default_theme
¶
Set the theme applied by every plot helper that omits theme=.
Source code in src/simweave/viz/themes.py
plot_agent_path
¶
plot_agent_path(agent: Any, graph: Any | None = None, *, show_graph: bool = True, theme: str | None = None, title: str | None = None) -> Any
Render an agent's traversal over a 2-D graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Any
|
A :class: |
required |
graph
|
Any | None
|
Optional graph to draw underneath the path. Defaults to
|
None
|
show_graph
|
bool
|
If True, draws faint lines for every edge of the graph. |
True
|
Source code in src/simweave/viz/plots.py
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 | |
plot_mc_fan
¶
plot_mc_fan(mc_or_array: Any, times: Sequence[float] | ndarray | None = None, percentiles: Sequence[float] = (5, 25, 50, 75, 95), *, time_axis: 'SimTimeAxis | None' = None, theme: str | None = None, title: str | None = None, show_mean: bool = True) -> Any
Percentile fan chart for a Monte Carlo trajectory ensemble.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mc_or_array
|
Any
|
|
required |
times
|
Sequence[float] | ndarray | None
|
Optional time axis. Ignored if |
None
|
percentiles
|
Sequence[float]
|
Percentiles to draw. The median (or 50th percentile if present) is rendered as a solid line; the rest form symmetric shaded bands from outside-in. |
(5, 25, 50, 75, 95)
|
show_mean
|
bool
|
If True, overlays the per-time mean as a thin dashed line. |
True
|
Source code in src/simweave/viz/plots.py
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 | |
plot_phase_portrait
¶
plot_phase_portrait(result: Any, x_idx: int = 0, y_idx: int = 1, *, theme: str | None = None, title: str | None = None) -> Any
Plot state[:, x_idx] vs state[:, y_idx] with a start marker.
Source code in src/simweave/viz/plots.py
plot_queue_length
¶
plot_queue_length(recorder: Any, *, time_axis: 'SimTimeAxis | None' = None, theme: str | None = None, title: str | None = None) -> Any
Step plot of queue length over time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recorder
|
Any
|
A :class: |
required |
time_axis
|
'SimTimeAxis | None'
|
Optional :class: |
None
|
Source code in src/simweave/viz/plots.py
plot_service_utilisation
¶
plot_service_utilisation(recorder: Any, *, time_axis: 'SimTimeAxis | None' = None, theme: str | None = None, title: str | None = None) -> Any
Aggregate utilisation line + per-channel busy-time lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recorder
|
Any
|
A :class: |
required |
time_axis
|
'SimTimeAxis | None'
|
Optional :class: |
None
|
Source code in src/simweave/viz/plots.py
plot_state_trajectories
¶
plot_state_trajectories(result: Any, channels: Sequence[int] | None = None, *, theme: str | None = None, title: str | None = None) -> Any
Line plot of each state channel vs result.time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Any
|
A :class: |
required |
channels
|
Sequence[int] | None
|
Optional indices of state channels to include. Default: all. |
None
|
theme
|
str | None
|
Theme name. Default: the global default (see
:func: |
None
|
title
|
str | None
|
Optional figure title. |
None
|
Source code in src/simweave/viz/plots.py
plot_warehouse_stock
¶
plot_warehouse_stock(recorder: Any, sku_indices: Sequence[int] | None = None, *, time_axis: 'SimTimeAxis | None' = None, theme: str | None = None, title: str | None = None, show_reorder_points: bool = True) -> Any
Per-SKU stock-level lines with optional reorder-point dashes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recorder
|
Any
|
A :class: |
required |
sku_indices
|
Sequence[int] | None
|
Optional iterable of SKU indices to include. Default: all. |
None
|
time_axis
|
'SimTimeAxis | None'
|
Optional :class: |
None
|
show_reorder_points
|
bool
|
If True, draws a horizontal dashed line at each SKU's reorder point in the same colour family as its stock trace. |
True
|
Source code in src/simweave/viz/plots.py
plot_pareto_sweep
¶
plot_pareto_sweep(warehouse: Warehouse, availability_range: ndarray | None = None, *, method: str = 'both', theme: str | None = None, title: str | None = None) -> Any
Plot cost vs availability with optional DE and Poisson curves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
warehouse
|
Warehouse
|
Warehouse instance to optimise. |
required |
availability_range
|
ndarray | None
|
Optional array of availability targets. |
None
|
method
|
str
|
"both" (default), "poisson", or "de". |
'both'
|
theme
|
str | None
|
Optional Plotly theme. |
None
|
title
|
str | None
|
Optional plot title. |
None
|
Source code in src/simweave/viz/plots.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 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 | |
plot_fleet_availability
¶
plot_fleet_availability(recorder: Any, *, normalize: bool = False, time_axis: 'SimTimeAxis | None' = None, theme: str | None = None, title: str | None = None) -> Any
Stacked area chart of fleet operational availability over time.
The three stacked layers are (bottom to top):
- awaiting part -- entities grounded waiting for spare stock (red).
- in repair -- parts obtained, repair in progress (amber).
- operational -- fully mission-capable (green).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recorder
|
Any
|
A :class: |
required |
normalize
|
bool
|
If |
False
|
theme
|
str | None
|
Theme name. |
None
|
title
|
str | None
|
Optional figure title. |
None
|
Source code in src/simweave/viz/plots.py
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 | |
plot_sensitivity_surface
¶
plot_sensitivity_surface(result: Any, *, chart_type: str = 'surface', show_std: bool = False, theme: str | None = None, title: str | None = None) -> Any
3-D surface or grouped bar chart for a 2-D sensitivity sweep result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Any
|
A :class: |
required |
chart_type
|
str
|
|
'surface'
|
show_std
|
bool
|
If |
False
|
theme
|
str | None
|
Theme name. |
None
|
title
|
str | None
|
Optional figure title. |
None
|
Source code in src/simweave/viz/plots.py
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 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 | |
plot_road_occupancy
¶
plot_road_occupancy(recorder: Any, *, time_axis: 'SimTimeAxis | None' = None, theme: str | None = None, title: str | None = None) -> Any
Line chart of in-transit vehicle counts for a set of roads over time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recorder
|
Any
|
A :class: |
required |
time_axis
|
'SimTimeAxis | None'
|
Optional :class: |
None
|
theme
|
str | None
|
Standard theme/title overrides. |
None
|
title
|
str | None
|
Standard theme/title overrides. |
None
|
Source code in src/simweave/viz/plots.py
plot_intersection_queues
¶
plot_intersection_queues(recorder: Any, *, time_axis: 'SimTimeAxis | None' = None, theme: str | None = None, title: str | None = None) -> Any
Line chart of approach-queue lengths at one intersection over time.
The total queue (solid line) and each per-approach breakdown (dashed lines) are plotted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recorder
|
Any
|
An :class: |
required |
time_axis
|
'SimTimeAxis | None'
|
Standard overrides. |
None
|
theme
|
'SimTimeAxis | None'
|
Standard overrides. |
None
|
title
|
'SimTimeAxis | None'
|
Standard overrides. |
None
|
Source code in src/simweave/viz/plots.py
plot_fault_signals
¶
plot_fault_signals(result: Any, injector: Any, channels: Sequence[int] | None = None, *, theme: str | None = None, title: str | None = None) -> Any
State trajectories with shaded regions for degraded and failed phases.
The plot overlays the simulated state channels with coloured background bands:
- green — healthy (health index = 1).
- amber — degrading (0 < health index < 1).
- red — failed (health index = 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Any
|
A :class: |
required |
injector
|
Any
|
The :class: |
required |
channels
|
Sequence[int] | None
|
State channel indices to plot. Default: all. |
None
|
theme
|
str | None
|
Standard overrides. |
None
|
title
|
str | None
|
Standard overrides. |
None
|
Source code in src/simweave/viz/plots.py
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 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 | |
plot_health_index
¶
plot_health_index(dataset: Any, *, show_rul: bool = True, theme: str | None = None, title: str | None = None) -> Any
Health index (and optionally RUL) over simulation time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
Any
|
A :class: |
required |
show_rul
|
bool
|
If |
True
|
theme
|
str | None
|
Standard overrides. |
None
|
title
|
str | None
|
Standard overrides. |
None
|
Source code in src/simweave/viz/plots.py
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 | |
plot_vehicle_metrics
¶
Plot vehicle metrics with adaptive layout and automatic units.
Source code in src/simweave/viz/vehicle_dynamics.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
have_plotly
¶
Cheap probe: does the current environment have plotly available?