Visualization#

Tools for visualizing simulation results and data in biosym.

biosym.visualization.stickfigure.plot_stick_figure(model, states, dt=0.01, frame=None, plot_markers=True, plot_expected=True, joint_markersize: float = 6.0, site_markersize: float = 4.0, expected_markersize: float = 4.0, **kwargs)#

Plot (or animate) a stick-figure of the model with optional markers & markers.

This refactored implementation splits the original monolithic logic into modular helpers to clarify the distinct phases: 1) FK data extraction (bodies, markers, expected markers) 2) Figure/axes setup (2D vs 3D) 3) Axis limit computation (standing vs animation) 4) Initial frame drawing 5) Optional animation update loop (multi-node trajectories)

Parameters:
  • model (BiosymModel) – The biomechanical model with compiled FK functions.

  • states (tuple) – Tuple (state_sequence, globals) where state_sequence is a list-like of per-node state wrappers (collocation solution) and globals may provide duration (dur) for timestep derivation.

  • dt (float, default 0.01) – Base timestep; if globals supplied, overridden by dur / nnodes.

  • frame (int or None) – Reserved for future single-frame extraction; currently unused.

  • plot_markers (bool, default True) – Whether to display simulated site positions (red).

  • plot_expected (bool, default True) – Whether to display experimental expected markers (green) when markers_exp kwarg is provided.

  • markers_exp (array-like, optional (via **kwargs)) – Experimental markers shaped (N, 3*n_markers). If not provided, this function will attempt to auto-discover them from a tracking markers objective if you pass either objective=prob.objective or problem=prob/prob=prob in **kwargs.

Notes

  • Standing (n_nodes == 1): still plots expected markers if provided.

  • Walking (n_nodes > 1): creates an interactive animation with pause & speed controls (space / up / down keys).

  • markers are not states; they are derived via FK_vis appended rows.

  • Function preserves previous external signature except for new optional flags enabling selective plotting.

Returns:

Animation object when multiple frames; otherwise None after showing.

Return type:

matplotlib.animation.FuncAnimation or None