-
-
Notifications
You must be signed in to change notification settings - Fork 39
Figures
Peter Corke edited this page May 25, 2026
·
3 revisions
This page summarizes bdsim graphics behavior for both users and developers.
bdsim graphics blocks (for example SCOPE, SCOPEXY, and VEHICLEPLOT) can:
- render live figures during simulation
- animate during
run(...)whenanimation=True - keep windows open at run end when
hold=True - save movie output for blocks configured with
movie=...(requiresffmpeg)
-
graphics: enables/disables graphics handling for graphics blocks -
animation: enables periodic frame refresh during simulation -
hold: blocks at run end for interactive GUI backends
In notebooks, figures are updated inline instead of relying on GUI event loops.
Graphics output is coordinated by display managers in
src/bdsim/display.py.
-
DisplayManager: base interface + factory (DisplayManager.create(...)) -
MatplotlibDisplayManager: GUI matplotlib behavior -
NotebookDisplayManager: inline notebook behavior (IPython.display)
The simulator creates one manager per run and calls three lifecycle methods:
-
show_initial()before frame callbacks start -
refresh()during animation frame callbacks -
finalize()at end-of-run
Notebook rendering has two important differences from desktop GUI backends:
- updates are done via
display_id+update_display - at finalize, bdsim performs one final refresh to include the terminal sample, then closes figures to avoid duplicate auto-rendered outputs at cell end
This ordering is intentional and avoids two common notebook issues:
- missing final point in animated plots
- duplicate final figure appended after simulation output
High-level control points are:
-
BDSim.run(...)insrc/bdsim/run_sim.py -
Runner.done(...)insrc/bdsim/components.py -
GraphicsBlock.step()/done()insrc/bdsim/block.py
During animated runs, the scheduler posts frame callbacks that call
display_manager.refresh().
At end-of-run:
- GUI backend: final behavior is controlled by
hold - notebook backend:
display_manager.finalize()handles the last refresh and duplicate-suppression policy
- Prefer backend-specific behavior in display manager subclasses, not spread across run-loop branches.
- Keep notebook and GUI lifecycle differences localized to
display.py. - If you change finalize ordering, regression-test for both:
- final point visibility
- duplicate notebook figure outputs
Copyright (c) Peter Corke 2020-
- Home
- Control Systems Magazine article
- FAQ
- Changes
- Adding blocks
- Block path
- Connecting blocks
- Subsystems
- Compiling
- Running
- Runtime options
- Discrete-time blocks
- Figures
- Notebook animation
- PID control
- Coding patterns
- Block methods and attributes
- Event handling
- Discrete-time dynamics
- Blocks, wires and plug
- Discrete-time blocks
- Evaluation
- Runtimes and simulator state
- Creating a new block
- Future & related work
Under development on feat/realtime branch