dymad.utils.plot

Functions

animate(fig_func, filename[, fps, n_frames, ...])

Create an animation by calling a figure-generating function for each frame.

compare_contour(x_true, x_pred[, x, y, ...])

Compare two contours with error contours.

plot_contour(arrays[, x, y, vmin, vmax, ...])

Plot a grid of contour plots for a list of 2D arrays.

plot_cv_results(cv_file[, keys, ifclose, ...])

Plot cross-validation results.

plot_hist(hist, crit, crit_name, model_name)

plot_multi_trajs(traj, ts, model_name[, us, ...])

Multi-trajectory version of plot_trajectory - comparison of batches of trajectories.

plot_one_summary(npz[, label, index, ifscl, ...])

Plot training losses and prediction criterion from a summary file.

plot_one_trajectory(traj, ts[, idx, us, ...])

Used by plot_trajectory to plot a single trajectory.

plot_summary(npz_files[, labels, ifscl, ...])

Plot training losses and prediction criterion for multiple summary files on the same figure.

plot_trajectory(traj, ts[, model_name, us, ...])

Plot trajectories with optional control inputs and save the figure.

dymad.utils.plot.animate(fig_func, filename, fps=10, n_frames=None, writer_args=None, fig_args=None)

Create an animation by calling a figure-generating function for each frame.

Parameters:
  • fig_func (function) – Function that generates a figure for a given frame index. It should accept the frame index as its first argument, and return a matplotlib figure and axes.

  • filename (str) – Output filename for the output file.

  • fps (int) – Frames per second for the animation.

  • n_frames (int) – Total number of frames in the animation.

  • writer_args (dict) – Additional keyword arguments to pass to imageio.get_writer.

  • fig_args (dict) – Additional keyword arguments to pass to fig_func.

dymad.utils.plot.compare_contour(x_true, x_pred, x=None, y=None, vmin=None, vmax=None, levels=20, figsize=(12, 4), colorbar=True, axes=None, label=None, mode='contourf', **kwargs)

Compare two contours with error contours.

dymad.utils.plot.plot_contour(arrays, x=None, y=None, vmin=None, vmax=None, levels=20, figsize=(12, 4), colorbar=True, axes=None, label=None, grid=None, mode='contourf', **kwargs)

Plot a grid of contour plots for a list of 2D arrays.

Parameters:
  • arrays (list of np.ndarray) – List of 2D arrays to plot.

  • titles (list of str) – Titles for each subplot.

  • x (np.ndarray) – Optional meshgrid for axes.

  • y (np.ndarray) – Optional meshgrid for axes.

  • vmin (float) – Color limits.

  • vmax (float) – Color limits.

  • levels (int or array) – Contour levels.

  • figsize (tuple) – Figure size.

  • colorbar (bool) – Whether to add a colorbar.

  • axes – Existing figure/axes tuple.

  • label (list) – Titles for each subplot.

  • grid (tuple) – Grid layout (n_rows, n_cols).

  • mode (str) – ‘contour’, ‘contourf’, or ‘tricontourf’.

  • **kwargs – Additional arguments for contourf.

Returns:

Matplotlib figure and axes.

Return type:

fig, axes

dymad.utils.plot.plot_cv_results(cv_file, keys=None, ifclose=True, prefix='.', value_scale='log')

Plot cross-validation results.

Parameters:
  • cv_results (list) – List of CVResult objects.

  • metric_name (str) – Name of the metric to plot.

  • ifclose (bool) – Whether to close the plot after saving.

  • prefix (str) – Directory prefix for saving the plot.

dymad.utils.plot.plot_hist(hist, crit, crit_name, model_name, ifclose=True, prefix='.')
dymad.utils.plot.plot_multi_trajs(traj, ts, model_name, us=None, labels=None, ifclose=True, prefix='.', xidx=None, uidx=None, grid=None, xscl=None, uscl=None)

Multi-trajectory version of plot_trajectory - comparison of batches of trajectories.

dymad.utils.plot.plot_one_summary(npz, label='', index=0, ifscl=True, axes=None)

Plot training losses and prediction criterion from a summary file.

Parameters:
  • npz (dict) – Dictionary from the NPZ file.

  • label (str) – Label for the plot legend.

  • index (int) – Index to select color from the PALETTE.

  • ifscl (bool) – If True, scale the loss by the first epoch loss.

  • axes (list, optional) – List of axes to plot on. If None, creates new subplots.

dymad.utils.plot.plot_one_trajectory(traj, ts, idx=0, us=None, axes=None, label=None, xidx=None, uidx=None, grid=None, xscl=None, uscl=None)

Used by plot_trajectory to plot a single trajectory.

dymad.utils.plot.plot_summary(npz_files, labels=None, ifscl=True, ifclose=True, prefix='.', output_path=None)

Plot training losses and prediction criterion for multiple summary files on the same figure.

Parameters:
  • npz_files (list) – List of NPZ file paths containing summary data.

  • labels (list) – List of labels for each run (optional).

  • ifscl (bool) – If True, scale the loss by the first epoch loss.

  • ifclose (bool) – Whether to close the plot after saving.

  • prefix (str) – Directory prefix used when output_path is not an absolute path.

  • output_path (str, optional) – If provided, save the figure to this path. By default the plot is not written to disk.

dymad.utils.plot.plot_trajectory(traj, ts, model_name=None, us=None, axes=None, labels=None, ifclose=True, prefix='.', xidx=None, uidx=None, grid=None, xscl=None, uscl=None, cmp_err=True)

Plot trajectories with optional control inputs and save the figure.

Parameters:
  • traj (np.ndarray) – Trajectory data, shape (n_steps, n_features) or (n_traj, n_steps, n_features)

  • ts (np.ndarray) – Time points corresponding to the trajectory data, shape (n_steps,)

  • model_name (str, optional) – Name of the model for the plot title and filename

  • us (np.ndarray, optional) – Control inputs, shape (n_steps, n_controls)

  • axes (list, optional) – List of axes to plot on. If None, creates new subplots

  • labels (list, optional) – Labels for each trajectory, length must match number of trajectories

  • ifclose (bool) – Whether to close the plot after saving

  • prefix (str) – Directory prefix for saving the plot

  • xidx (list, optional) – Indices of state features to plot

  • uidx (list, optional) – Indices of control inputs to plot

  • grid (tuple, optional) – Tuple (n_rows, n_cols) for subplot layout

  • xscl (str, optional) – Scaling mode for state features (‘01’, ‘-11’, ‘std’, or ‘none’)

  • uscl (str, optional) – Scaling mode for control inputs (‘01’, ‘-11’, ‘std’, or ‘none’)

  • cmp_err (bool) – Whether to compute and display RMSE between trajectories

Returns:

List of axes used for plotting

Return type:

axes (list)