1717from typing import TYPE_CHECKING , Any , Self , TypeAlias
1818
1919import defusedxml .ElementTree as ET
20- import matplotlib .pyplot as plt
21- import matplotlib .animation as animation
2220import imageio .v3 as iio
21+ import matplotlib .pyplot as plt
2322import mujoco
2423import mujoco .viewer
2524import numpy as np
2625import yaml
27- from IPython .display import clear_output , HTML
26+ from IPython .display import HTML , clear_output
27+ from matplotlib import animation
2828from tqdm .auto import tqdm
2929
3030from .builder import Builder
@@ -715,7 +715,7 @@ def is_jupyter() -> bool:
715715
716716 # Set up the figure and image once
717717 fig , ax = plt .subplots ()
718- im = ax .imshow (np .zeros ((self .resolution [1 ], self .resolution [0 ], 3 ), dtype = np .uint8 ), interpolation = ' nearest' )
718+ im = ax .imshow (np .zeros ((self .resolution [1 ], self .resolution [0 ], 3 ), dtype = np .uint8 ), interpolation = " nearest" )
719719 ax .set_axis_off ()
720720 ax .set_title (title )
721721 plt .subplots_adjust (left = 0 , right = 1 , top = 1 , bottom = 0 , wspace = 0 , hspace = 0 )
@@ -726,18 +726,17 @@ def is_jupyter() -> bool:
726726 lambda frame : (im .set_data (frame ), [im ])[1 ],
727727 frames = subset_frames ,
728728 interval = (1000 / self ._fps ),
729- blit = True
729+ blit = True ,
730730 )
731731 plt .close (fig )
732732 return HTML (ani .to_jshtml ())
733- else :
734- plt .ion ()
735- delay = 1.0 / self ._fps
736- for frame in subset_frames :
737- im .set_data (frame )
738- plt .pause (delay )
739- plt .ioff ()
740- plt .close (fig )
733+ plt .ion ()
734+ delay = 1.0 / self ._fps
735+ for frame in subset_frames :
736+ im .set_data (frame )
737+ plt .pause (delay )
738+ plt .ioff ()
739+ plt .close (fig )
741740 except Exception as e :
742741 msg = "Error while showing video subset."
743742 raise Exception (msg ) from e # noqa: TRY002
@@ -769,15 +768,15 @@ def save(
769768 if not hasattr (self , "_frames" ) or self ._frames is None or len (self ._frames ) == 0 :
770769 msg = "No frames captured to render. Re-run the simulation with render=True."
771770 raise ValueError (msg )
772-
771+
773772 # Extract frames
774773 subset_frames = self ._get_index (
775774 frame_idx = frame_idx ,
776775 time_idx = time_idx ,
777776 )
778777
779778 title_path = Path (title )
780-
779+
781780 try :
782781 # Save the video
783782 iio .imwrite (
0 commit comments