Skip to content

Commit

Permalink
[python/plot] Fix various visual glitches and improve layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Duburcq committed Sep 18, 2023
1 parent 3a53f5b commit 7d6579e
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 104 deletions.
19 changes: 11 additions & 8 deletions python/gym_jiminy/common/gym_jiminy/common/envs/env_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
ImuSensor as imu)
from jiminy_py.dynamics import compute_freeflyer_state_from_fixed_body
from jiminy_py.log import extract_variables_from_log
from jiminy_py.simulator import Simulator
from jiminy_py.simulator import Simulator, TabbedFigure
from jiminy_py.viewer.viewer import (DEFAULT_CAMERA_XYZRPY_REL,
interactive_mode,
get_default_backend,
Expand Down Expand Up @@ -941,7 +941,7 @@ def render(self) -> Optional[Union[RenderFrame, List[RenderFrame]]]:
return self.simulator.render( # type: ignore[return-value]
return_rgb_array=self.render_mode == 'rgb_array')

def plot(self, **kwargs: Any) -> None:
def plot(self, **kwargs: Any) -> TabbedFigure:
"""Display common simulation data and action over time.
.. Note:
Expand All @@ -950,7 +950,7 @@ def plot(self, **kwargs: Any) -> None:
:param kwargs: Extra keyword arguments to forward to `simulator.plot`.
"""
# Call base implementation
self.simulator.plot(**kwargs)
figure = self.simulator.plot(**kwargs)

# Extract log data
log_vars = self.simulator.log_data.get("variables", {})
Expand All @@ -969,25 +969,28 @@ def plot(self, **kwargs: Any) -> None:
if action_fieldnames is None:
# It was impossible to register the action to the telemetry, likely
# because of incompatible dtype. Early return without adding tab.
return
return figure
if isinstance(action_fieldnames, dict):
for group, fieldnames in action_fieldnames.items():
if not isinstance(fieldnames, list):
LOGGER.error(
"Action space not supported by this method.")
return
return figure
tab_data[group] = {
".".join(key.split(".")[1:]): value
key.split(".", 2)[2]: value
for key, value in extract_variables_from_log(
log_vars, fieldnames, as_dict=True).items()}
elif isinstance(action_fieldnames, list):
tab_data.update({
".".join(key.split(".")[1:]): value
key.split(".", 2)[2]: value
for key, value in extract_variables_from_log(
log_vars, action_fieldnames, as_dict=True).items()})

# Add action tab
self.simulator.figure.add_tab("Action", t, tab_data)
figure.add_tab(" ".join(("Env", "Action")), t, tab_data)

# Return figure for convenience and consistency with Matplotlib
return figure

def replay(self, **kwargs: Any) -> None:
"""Replay the current episode until now.
Expand Down
3 changes: 2 additions & 1 deletion python/jiminy_py/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def finalize_options(self) -> None:
extras_require={
"plot": [
# Standard library to generate figures.
"matplotlib>=3.5.0"
# - 3.7.0: introduces 'outside' keyword for legend location
"matplotlib>=3.7.0"
],
"meshcat": [
# Web-based mesh visualizer used as Viewer's backend.
Expand Down
Loading

0 comments on commit 7d6579e

Please sign in to comment.