plot

This modules provides a set of tools to visualize telemetry log data in a convenient and portable way. These tools are designed to work on any platform without root permission, including in local Jupyter notebook, VS Code, and Google Colaboratory. No graphical server is required for offscreen rendering.

class jiminy_py.plot.TabData[source]

Bases: TypedDict

Internal data stored for each tab if TabbedFigure.

class jiminy_py.plot.TabbedFigure(sync_tabs=False, window_title='jiminy', offscreen=False, **kwargs)[source]

Bases: object

A windows with several tabs holding matplotlib subplots. It enables adding, modifying and removing tabs sequentially and conveniently.

Note

It has been designed to be cross-platform, and supported by any Matplotlib backend. So it can be used on-the-spot right after fresh install of Python and jiminy_py, without requiring elevated privilege to install Qt4/5 or Tkinter.

Warning

It only supports plotting time series, the time corresponding to the horizontal axis of every subplot.

Create empty tabbed figure.

Note

It will show-up on display automatically only adding the first tab.

Parameters:
  • sync_tabs (bool) – Synchronize time window on every tabs (horizontal axis), rather than independently for every tabs.

  • window_title (str) – Desired indow title. Optional: “jiminy” by default.

  • offscreen (bool) – Whether to enable display on screen of figure. Optional: False by default.

  • kwargs (Any) – Unused extra keyword arguments to enable forwarding.

close()[source]

Close figure.

Return type:

None

adjust_layout(event=None, *, refresh_canvas=False)[source]

Optimize buttons width and grid subplot arrangement of the active tab for readability based on the current window size. Then, adjust margins to maximize plot sizes.

Parameters:
  • event (Event | None) – Event spent by figure mpl_connect ‘resize_event’.

  • refresh_canvas (bool) – Force redrawing figure canvas.

Return type:

None

refresh()[source]

Refresh canvas drawing.

Return type:

None

add_tab(tab_name, time, data, plot_method=None, *, refresh_canvas=True, **kwargs)[source]

Create a new tab holding the provided data.

Each tab holds exactly one grid of subplots. There is one subplot for each time series that has been provided, and all of them having to be associated with the exact same time sequence. The layout is dynamically optimized for readability.

The added tab will only be selected as the active one automatically if there were no tab beforehand.

Parameters:
  • tab_name (str) – Name of the tab to be added. It must be a unique identifier not already used for another tab. It will be displayed as label for the buttons used to select the active tab.

  • time (ndarray) – Unique time sequence associated with the provided time series. It does not have to be evenly spaced but must be monotonically increasing.

  • data (ndarray | Dict[str, Dict[str, ndarray] | ndarray]) – Set of time series to plot. If a simple array is provided, then there will be only one subplot, with one (unlabeled) line if the array is 1D, one per column otherwise. If a dictionary of arrays is provided, there is one subplot per item, the key being used as label and the value is treated as simple array. Finally, in case of a nested dictionary, each sub-value must be a 1D array and sub-keys will be used to label individual lines.

  • plot_method (Callable[[...], Any] | str | None) – Callable method taking axis object, time, and data array in argument, or string instance method of matplotlib.axes.Axes. Optional: step(…, where=’post’) by default.

  • refresh_canvas (bool) – Whether to refresh the figure. This step can be skipped if other tabs are going to be added or deleted soon, to avoid useless computation and figure flickering. Optional: True by default.

  • kwargs (Any)

Return type:

None

select_active_tab(tab_name)[source]

Select the active tab.

A single tab is considered active at a time.

Parameters:

tab_name (str) – Name of the tab to select. It must be to one of the names that has been specified when calling add_tab previously.

Return type:

None

remove_tab(tab_name, *, refresh_canvas=True)[source]

Remove a given tab.

If the removed tab was the active one, the first tab that has been added while be made active from now on.

Parameters:
  • tab_name (str) – Name of the tab to remove. It must be to one of the names that has been specified when calling add_tab previously.

  • refresh_canvas (bool) – Whether to refresh the figure. This step can be skipped if other tabs are going to be added or deleted soon, to avoid useless computation and figure flickering. Optional: True by default.

Return type:

None

clear()[source]

Remove all tabs at once.

Return type:

None

save_tab(pdf_path)[source]

Export the active tab in a single-page PDF file, excluding tab buttons. Lines are stored as vector instead of being rasterized.

Parameters:

pdf_path (str) – Desired location for generated pdf file.

Return type:

None

save_all_tabs(pdf_path)[source]

Export the whole figure in a single PDF file containing one page per tab and excluding systematically the tab buttons.

See also

See save_tab documentation for details.

Parameters:

pdf_path (str) – Desired location for generated pdf file.

Return type:

None

classmethod plot(time, tabs_data, pdf_path=None, **kwargs)[source]

Create a new tabbed figure along with multiple tabs holding the provided data, then eventually export it as PDF.

Parameters:
  • time (ndarray) – Unique time sequence associated with the provided time series. It does not have to be evenly spaced but must be monotonically increasing.

  • tabs_data (Dict[str, ndarray | Dict[str, Dict[str, ndarray] | ndarray]]) – Set of time series to plot in multiple tabs, as a nested dictionary. There will be one tab per item, the key and value being the name and the data of the tab, respectively. See add_tab documentation about how the data are displayed based on their structure.

  • pdf_path (str | None) – If specified, the whole figure will be exported in a PDF file at the desired location without rendering on screen. See save_all_tabs documentation for details. Optional: None by default.

  • kwargs (Any) – Extra keyword arguments to forward to add_tab method.

Return type:

TabbedFigure

jiminy_py.plot.plot_log(log_data, robot=None, enable_flexiblity_data=False, block=None, **kwargs)[source]

Display standard simulation data over time.

The figure features several tabs:

  • Subplots with robot configuration

  • Subplots with robot velocity

  • Subplots with robot acceleration

  • Subplots with motors torques

  • Subplots with raw sensor data (one tab for each type of sensor)

Parameters:
  • log_data (Dict[str, Any]) – Logged data (constants and variables) as a dictionary.

  • robot (Model | None) – Jiminy robot associated with the logged trajectory. Optional: None by default. If None, then it will be reconstructed from ‘log_data’ using build_robot_from_log.

  • enable_flexiblity_data (bool) – Enable display of flexibility joints in robot’s configuration, velocity and acceleration subplots. Optional: False by default.

  • block (bool | None) – Whether to wait for the figure to be closed before returning. Non-op for offscreen rendering and notebooks. Optional: False in interactive mode, True otherwise.

  • kwargs (Any) – Extra keyword arguments to forward to TabbedFigure.

Return type:

TabbedFigure