pylinkage.visualizer package

Submodules

pylinkage.visualizer.animated module

pylinkage.visualizer.core module

Core features for visualization.

This module provides shared utilities used by all visualization backends (matplotlib, plotly, drawsvg). It contains linkage introspection helpers that work with both the legacy pylinkage.linkage.Linkage (joints API) and the modern pylinkage.simulation.Linkage (components API).

For symbol definitions see symbols.

pylinkage.visualizer.core.build_connections(linkage: Any, components: list[Any]) list[tuple[int, int]]

Return (parent_idx, child_idx) pairs for every bar to draw.

Three cases:

  • Mechanism (has .links): iterate each link and emit all pairwise combinations of its joint indices. A ternary link with three joints yields three bars (the full triangle); a simple binary link yields one.

  • Legacy Linkage / modern SimLinkage (joint-/component-centric): fall back to per-component get_parent_pairs().

pylinkage.visualizer.core.get_components(linkage: Any) list[Any]

Return the ordered list of joints/components from either API.

Works with both legacy Linkage.joints and modern SimLinkage.components.

pylinkage.visualizer.core.get_parent_pairs(component: Any) list[Any]

Return the parent components that should draw links to component.

Works with both legacy joints (joint0, joint1) and modern components (anchor, anchor1, anchor2).

pylinkage.visualizer.core.is_prismatic_like(component: Any) bool

True if the component is a slider (legacy Prismatic or RRPDyad).

pylinkage.visualizer.core.is_revolute_like(component: Any) bool

True if the component draws as a pin joint with two anchored parents.

Matches legacy Revolute/Pivot/Fixed and modern RRRDyad/FixedDyad.

pylinkage.visualizer.core.is_static_like(component: Any) bool

True if the component is a fixed-frame joint (Static/Ground).

pylinkage.visualizer.core.resolve_component(parent: Any, components: list[Any]) int | None

Resolve a parent reference to its index in the component list.

Handles direct membership, _AnchorProxy._parent, and legacy joint0/joint1 references.

Returns:

Index into components, or None if not found.

pylinkage.visualizer.static module

Static (non-animated) linkage visualization.

Supports both legacy pylinkage.linkage.Linkage (joints API) and modern pylinkage.simulation.Linkage (components API).

pylinkage.visualizer.static.plot_static_linkage(linkage: Any, axis: Axes, loci: Iterable[tuple[Coord, ...]], locus_highlights: list[list[Coord]] | None = None, show_legend: bool = False, *, show_labels: bool = True, show_loci: bool = True, n_ghosts: int = 0, title: str | None = None) None

Plot a linkage at one position with joint trajectories.

Draws the mechanism bars at the initial position (bold, colored), joint trajectory paths (faded), ground pivot markers, and joint labels. Optionally draws “ghost” mechanism outlines at evenly spaced frames through the cycle.

Works with both the legacy Linkage (joints) and the modern SimLinkage (components) APIs.

Args:

linkage: The linkage to draw (legacy or modern). axis: Matplotlib axes to draw on. loci: Sequence of frames, each frame a tuple of (x, y) per joint. locus_highlights: Optional list of coordinate lists to scatter. show_legend: Add a legend with joint names. show_labels: Annotate each joint with its name. show_loci: Draw joint trajectory paths. n_ghosts: Number of ghost mechanism outlines to draw through

the cycle (0 = none).

title: Optional axes title.

Module contents

Linkage visualization features.

Backends:
  • matplotlib (default): plot_static_linkage, plot_kinematic_linkage, show_linkage

  • plotly: plot_linkage_plotly, animate_linkage_plotly (interactive HTML)

  • drawsvg: plot_linkage_svg, save_linkage_svg (publication-quality SVG)

  • dxf: plot_linkage_dxf, save_linkage_dxf (CAD/CNC export)

  • step: build_linkage_3d, save_linkage_step (3D CAD interchange)