Skip to main content
Version: 0.2.7

Visualization — Overview

synapsys.viz provides two visualization tiers for control experiments:

CartPole2DViewCartPoleView / PendulumView / MassSpringDamperView
Rendering2D matplotlib3D PyVista + matplotlib telemetry
Dependenciesmatplotlib onlypyside6, pyvistaqt, matplotlib
Works headlessYes (Agg backend)No — requires a display
Entry pointrun() / simulate() / animate()run()
SystemCart-Pole onlyCart-Pole, Pendulum, MSD

2D View — CartPole2DView

Lightweight option: no Qt, no PyVista — runs anywhere matplotlib runs.

CartPole 2D animation

from synapsys.viz import CartPole2DView

# Auto-LQR, interactive window
CartPole2DView().run()

# Headless: returns history dict (no window)
hist = CartPole2DView(duration=5.0).simulate()
print(hist["angle"][-1]) # final pole angle (rad)

# Save to GIF
CartPole2DView().animate(save="cartpole.gif")

Use CartPole2DView when:

  • You're on a server / CI / notebook without a Qt display
  • You only need the cart-pole system
  • You want to export an animation or run batch simulations

3D Views — SimView

Full real-time window combining PyVista 3D animation and matplotlib telemetry panels.

Cart-Pole — real-time 3D simulation

from synapsys.viz import CartPoleView
CartPoleView().run()

A complete window with:

  • 3D panel — real-time physics animation (PyVista + VTK)
  • Telemetry panel — 4 synchronized matplotlib charts (position, angle, control, phase portrait)
  • Control bar — hold-to-apply perturbation buttons, magnitude slider, pause/reset
  • Automatic LQR — if no controller is provided, the lib linearizes the simulator and designs an LQR internally
  • Global keyboard capture — A/D (perturbation), R (reset), Space (pause), Q (close)

Available 3D simulators

ClassPhysical systemStateInputPerturbation
CartPoleViewCart + inverted pendulum[x, ẋ, θ, θ̇]Horizontal force on cart (N)◀/▶ horizontal force
PendulumViewSingle-link inverted pendulum[θ, θ̇]Joint torque (N·m)↺/↻ angular torque
MassSpringDamperViewMass-spring-damper[q, q̇]External force (N)◀/▶ force + setpoints 1/2/3

Architecture

SimulatorBase          ← synapsys.simulators
│ dynamics(), step(), linearize()

├── CartPoleSim ──→ CartPole2DView (matplotlib 2D, no Qt)

SimViewBase ← synapsys.viz.simview._base (QMainWindow)
│ • creates Qt window (3D + matplotlib splitter)
│ • QTimer loop → _on_tick()
│ • auto-LQR via linearize() + lqr()
│ • keyboard, perturbations, pause, reset
│ • _build_all() called in run()

├── CartPoleView ← state: [x, ẋ, θ, θ̇]
├── PendulumView ← state: [θ, θ̇]
└── MassSpringDamperView ← state: [q, q̇] + setpoint tracking

Standalone vs. library module

ApproachLines of codeRequires Qt knowledge?
Standalone file viz3d_cartpole_qt.py~470 linesYes — layout, QTimer, splitter, canvas
CartPoleView().run()1 lineNo
CartPoleView(controller=my_net).run()1 line + your functionNo
CartPole2DView().simulate()1 lineNo — pure matplotlib

Dependencies

# Minimal — CartPole2DView only
pip install synapsys

# Full 3D support
pip install synapsys[viz]
# or individually:
pip install pyside6 pyvistaqt matplotlib numpy

Note: pyvistaqt requires a VTK installation compatible with Qt. In headless environments (servers without a display), use CartPole2DView instead.


Next steps