perda.plotting.subplots#

perda.plotting.subplots.data_instance_subplots(rows, timestamp_unit, title=None, row_y_labels=None, show_legend=True, layout_config=LayoutConfig(width=1200, height=700, margin={'l': 70, 'r': 50, 't': 90, 'b': 70}, plot_bgcolor='white', title_x=0.5, title_xanchor='center', title_yanchor='top', grid_width_per_col=400, grid_height_per_row=350, grid_horizontal_spacing=0.08, grid_vertical_spacing=0.12, max_display_resolution=50), font_config=FontConfig(large=20, medium=14, small=10))[source]#

Plot groups of DataInstances as stacked subplots on a shared time axis.

Each element of rows becomes one subplot row. Multiple DataInstances in the same row are overlaid on that row’s y-axis — useful for comparing signals that share the same units or scale.

Parameters:
  • rows (List[List[DataInstance]]) – Outer list defines subplot rows (top to bottom); inner list defines the DataInstances overlaid within that row.

  • timestamp_unit (Timescale) – Timestamp unit of the underlying DataInstances. Converted to seconds for x-axis display. Pass aly.data.timestamp_unit.

  • title (str | None, optional) – Figure-level title. Default is None (no title).

  • row_y_labels (List[str | None] | None, optional) – Y-axis label for each row. Must match the length of rows when provided. None entries fall back to auto-labelling from the DataInstance labels in that row. Default is None (all rows auto-label).

  • show_legend (bool, optional) – Whether to show the figure legend. Default is True.

  • layout_config (LayoutConfig, optional) – Dimensions, spacing, and style for the subplot grid.

  • font_config (FontConfig, optional) – Font sizes for title, axis labels, tick labels, and legend.

Returns:

Plotly figure containing the stacked subplot grid.

Return type:

go.Figure

Examples

>>> from perda.plotting import data_instance_subplots
>>> fig = data_instance_subplots(
...     rows=[[speed_di], [torque_di, motor_di]],
...     title="Run Overview",
...     row_y_labels=["Speed (mph)", "Torque / Motor"],
...     timestamp_unit=aly.data.timestamp_unit,
... )
perda.plotting.subplots.plot_multi_log_subplots(logs, var_names, timestamp_unit, row_y_labels=None, title=None, layout_config=LayoutConfig(width=1200, height=700, margin={'l': 70, 'r': 50, 't': 90, 'b': 70}, plot_bgcolor='white', title_x=0.5, title_xanchor='center', title_yanchor='top', grid_width_per_col=400, grid_height_per_row=350, grid_horizontal_spacing=0.08, grid_vertical_spacing=0.12, max_display_resolution=50), font_config=FontConfig(large=20, medium=14, small=10))[source]#

Plot the same set of variables across multiple logs as stacked subplots, with each variable on one subplot.

Parameters:
  • logs (List[SingleRunData])

  • var_names (List[str]) – Ordered list of variable names to plot, one per subplot row. Variables absent from log are silently skipped.

  • timestamp_unit (Timescale) – Timestamp unit of the underlying DataInstances. Pass aly.data.timestamp_unit.

  • row_y_labels (List[str | None] | None, optional) – Y-axis label for each row. Must match the length of var_names

  • title (str | None, optional) – Base figure title. When multiple figures are produced a (1/N) suffix is appended automatically.

  • layout_config (LayoutConfig, optional)

  • font_config (FontConfig, optional)

Returns:

The combined figure with all subplots.

Return type:

go.Figure

Examples

>>> from perda.plotting import plot_multi_log_subplots
>>> fig = plot_multi_log_subplots(
...     logs=[aly1.data, aly2.data],
...     var_names=["pcm.wheelSpeeds.frontLeft", "ludwig.steeringWheel.angle", "pcm.pedals.brakePressure.front"],
...     title="Speed Comparison",
...     timestamp_unit=aly1.data.timestamp_unit,
... )
perda.plotting.subplots.stride_downsample(timestamps_s, values, max_display_resolution)[source]#

Return stride-downsampled arrays capped at max_display_resolution.

Parameters:
  • timestamps_s (np.ndarray) – Time values in seconds.

  • values (np.ndarray) – Corresponding sample values.

  • max_display_resolution (float) – Target display sample rate.

Returns:

Downsampled (timestamps_s, values).

Return type:

Tuple[np.ndarray, np.ndarray]

Examples

>>> from perda.plotting import stride_downsample
>>> ts_small, values_small = stride_downsample(time_s, di.value_np, 1000.0)