plotting

Matplotlib and Plotly visualizations for results and walkers.

Visualization and reporting for walking mechanism analysis.

Provides matplotlib-based plotting functions for: - Pareto front scatter plots (2D and 3D) - Gait phase / timing diagrams - Stability time series (tip-over margin, ZMP, body angle) - Center-of-mass trajectory overlays - Foot trajectory shape analysis - Combined dashboard views

All functions return matplotlib.figure.Figure so callers can further customize or save to file.

Example:

from leggedsnake.plotting import (
    plot_pareto_front,
    plot_gait_diagram,
    plot_stability_timeseries,
)

fig = plot_pareto_front(nsga_result)
fig.savefig("pareto.png")

fig = plot_gait_diagram(gait_result)
fig = plot_stability_timeseries(stability_series)
leggedsnake.plotting.plot_com_trajectory(series: StabilityTimeSeries, figsize: tuple[float, float] = (10, 4)) matplotlib.figure.Figure

2D plot of center-of-mass trajectory with support polygon snapshots.

Parameters:
  • series (StabilityTimeSeries) – Stability recording with CoM and support polygon data.

  • figsize (tuple[float, float]) – Figure size in inches.

Return type:

matplotlib.figure.Figure

leggedsnake.plotting.plot_foot_trajectories(gait: GaitAnalysisResult, figsize: tuple[float, float] = (10, 6)) matplotlib.figure.Figure

Foot trajectory shape plot for each tracked foot.

Each foot trajectory is drawn with contact regions highlighted.

Parameters:
  • gait (GaitAnalysisResult) – Gait analysis with foot trajectory data.

  • figsize (tuple[float, float]) – Figure size in inches.

Return type:

matplotlib.figure.Figure

leggedsnake.plotting.plot_gait_diagram(gait: GaitAnalysisResult, figsize: tuple[float, float] = (10, 4)) matplotlib.figure.Figure

Gait timing diagram showing stance/swing phases per foot.

Each foot gets a horizontal bar: dark = stance, light = swing.

Parameters:
  • gait (GaitAnalysisResult) – Output of analyze_gait.

  • figsize (tuple[float, float]) – Figure size in inches.

Return type:

matplotlib.figure.Figure

leggedsnake.plotting.plot_optimization_dashboard(result: NsgaWalkingResult, solution_index: int = 0, figsize: tuple[float, float] = (16, 10)) matplotlib.figure.Figure

Combined dashboard for a single Pareto-front solution.

Shows Pareto front (top-left), gait diagram (top-right), stability series (bottom-left), and foot trajectories (bottom-right).

Parameters:
  • result (NsgaWalkingResult) – Full NSGA optimization result with gait and stability data.

  • solution_index (int) – Index of the Pareto solution to detail.

  • figsize (tuple[float, float]) – Figure size in inches.

Return type:

matplotlib.figure.Figure

leggedsnake.plotting.plot_pareto_front(result: NsgaWalkingResult, objective_indices: tuple[int, int] | tuple[int, int, int] = (0, 1), highlight_best: bool = True, figsize: tuple[float, float] = (8, 6)) matplotlib.figure.Figure

Scatter plot of the Pareto front.

Supports 2D (two objectives) and 3D (three objectives).

Parameters:
  • result (NsgaWalkingResult) – Output of nsga_walking_optimization.

  • objective_indices (tuple of int) – Which objectives to plot (indices into scores tuple).

  • highlight_best (bool) – If True, mark the best-compromise solution.

  • figsize (tuple[float, float]) – Figure size in inches.

Return type:

matplotlib.figure.Figure

leggedsnake.plotting.plot_stability_timeseries(series: StabilityTimeSeries, figsize: tuple[float, float] = (12, 8)) matplotlib.figure.Figure

Multi-panel stability time series plot.

Four subplots: tip-over margin, ZMP x-coordinate, body angle, and CoM height.

Parameters:
  • series (StabilityTimeSeries) – Output of stability recording.

  • figsize (tuple[float, float]) – Figure size in inches.

Return type:

matplotlib.figure.Figure

leggedsnake.plotting.plot_walker_plotly(walker: Any, iterations: int | None = None, skip_unbuildable: bool = True, *, title: str | None = None, show_loci: bool = True, show_labels: bool = True, width: int = 800, height: int = 600) Any

Interactive Plotly diagram of a Walker’s kinematic trajectory.

Delegates to pylinkage.visualizer.plot_linkage_plotly() with a pre-computed locus from Walker.step(). Useful for inspecting optimization-run outputs in notebooks or dashboards.

Parameters:
  • walker (Walker) – Mechanism to render.

  • iterations (int | None) – Simulation steps. Defaults to one full rotation period.

  • skip_unbuildable (bool) – Forwarded to Walker.step. Dead-zone frames are drawn with their (None, None) positions, which pylinkage’s plotly renderer tolerates gracefully.

  • title – Forwarded to plot_linkage_plotly.

  • show_loci – Forwarded to plot_linkage_plotly.

  • show_labels – Forwarded to plot_linkage_plotly.

  • width – Forwarded to plot_linkage_plotly.

  • height – Forwarded to plot_linkage_plotly.

Return type:

plotly.graph_objects.Figure

leggedsnake.plotting.save_walker_svg(walker: Any, path: str, iterations: int | None = None, skip_unbuildable: bool = True, **kwargs: Any) None

Save a Walker’s kinematic trajectory as an SVG file.

Delegates to pylinkage.visualizer.save_linkage_svg() with a pre-computed locus. Useful for embedding optimizer outputs in papers or reports.

Parameters:
  • walker (Walker) – Mechanism to render.

  • path (str) – Output SVG file path.

  • iterations (int | None) – Simulation steps. Defaults to one full rotation period.

  • skip_unbuildable (bool) – Forwarded to Walker.step.

  • **kwargs – Forwarded to save_linkage_svg (show_loci, width, height, etc.).