Skip to main content

Visualisation

6.4 Visualisation​

The SDK provides a declarative visualisation system with two backends: Matplotlib (static, publication-quality) and Plotly (interactive, browser-based). Both backends support all 15 chart types through a unified Chart / Dashboard API.

15 Chart Types​

Chart TypeDescriptionBest For
LINETime series line chartAccumulator dynamics, prices, populations
AREAStacked area chartComposition over time (SIR compartments)
BARBar chart (per-step or final)Agent type counts, final metrics
HISTOGRAMValue distributionReturn distributions, state distributions
SCATTER2D scatter plotPhase diagrams, agent-level relationships
NETWORKNetwork topology graphInterbank networks, social graphs
GRID_HEATMAP2D grid heatmapFire spread, cell states, density maps
PHASE_DIAGRAM2D phase space trajectorySystem dynamics, limit cycles
AGENT_TIMELINEPer-agent state over timeIndividual agent behaviour tracking
MC_ENVELOPEMean ± std envelope from MC runsMonte Carlo summary visualisation
ANIMATED_LINEFrame-by-frame animationDynamic process visualisation
BOX_PLOTBox-and-whisker plotMC distribution comparison
VIOLINViolin plot (distribution + density)Rich distribution visualisation
PARALLEL_COORDINATESHigh-dimensional parallel axesParameter sweep exploration
SANKEYFlow diagram with weighted edgesResource flows, market share flows

Usage​

from simudyne.engine.viz import Dashboard, Chart, ChartType, VizBackend

viz = Dashboard(
title="Gai-Kapadia Results",
charts=[
Chart("Cascade", ChartType.LINE, fields=["total_defaults", "solvent_count"]),
Chart("Default Distribution", ChartType.HISTOGRAM, field="total_defaults"),
],
backend=VizBackend.MATPLOTLIB,
)

# Record from model history
for step in model.history:
viz.record_step(model, tick=step["tick"])

viz.show() # Display in window
viz.save_png("output/", dpi=150) # Save as PNG files
viz.to_html("output/") # Export as interactive HTML (Plotly)

The ModelVisualizer factory class provides convenience constructors:

from simudyne.engine.viz import ModelVisualizer

# From a SimulationRecorder (auto-detect chart types from recorded fields)
viz = ModelVisualizer.from_recorder(recorder, title="Recorded Data")

# From an MCResult (MC envelope + distribution charts)
viz = ModelVisualizer.from_mc_result(mc_result, fields=["price", "volatility"])

# From a live model (current agent state)
viz = ModelVisualizer.from_model(model, agent_type="Bank")