Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python/plot] Fix various visual glitches and improve layout. #643

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,4 @@
policy_fn = build_policy_wrapper(
policy_map, clip_actions=False, explore=False)
for seed in (1, 1, 2):
env.evaluate(policy_fn, seed=seed)
env.evaluate(policy_fn, seed=seed, horizon=env._max_episode_steps)
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