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
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 | |
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
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 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 | |
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_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
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 | |
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
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 825 826 827 828 829 830 831 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 | |
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
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 | |
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
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 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 | |
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?