@@ -168,8 +168,8 @@ def run(
168
168
:type nframes: int
169
169
:param interval: number of milliseconds between frames [default 50]
170
170
:type interval: int
171
- :param movie: name of file to write MP4 movie into
172
- :type movie: str
171
+ :param movie: name of file to write MP4 movie into, or True
172
+ :type movie: str, bool
173
173
:param wait: wait until animation is complete, default False
174
174
:type wait: bool
175
175
@@ -180,6 +180,8 @@ def run(
180
180
181
181
- the ``movie`` option requires the ffmpeg package to be installed:
182
182
``conda install -c conda-forge ffmpeg``
183
+ - if ``movie=True`` then return an HTML5 video which can be displayed in a notebook
184
+ using ``HTML()``
183
185
- invokes the draw() method of every object in the display list
184
186
"""
185
187
@@ -208,9 +210,6 @@ def update(frame, animation):
208
210
209
211
return animation .artists ()
210
212
211
- global _ani
212
-
213
- # blit leaves a trail and first frame
214
213
if movie is not None :
215
214
repeat = False
216
215
@@ -223,17 +222,22 @@ def update(frame, animation):
223
222
else :
224
223
frames = iter (np .linspace (0 , 1 , nframes ))
225
224
225
+ global _ani
226
+ fig = plt .gcf ()
226
227
_ani = animation .FuncAnimation (
227
- fig = plt . gcf () ,
228
+ fig = fig ,
228
229
func = update ,
229
230
frames = frames ,
230
231
fargs = (self ,),
231
- blit = False ,
232
+ blit = False , # blit leaves a trail and first frame, set to False
232
233
interval = interval ,
233
234
repeat = repeat ,
234
235
)
235
236
236
- if movie is not None :
237
+ if movie is True :
238
+ plt .close (fig )
239
+ return _ani .to_html5_video ()
240
+ elif isinstance (movie , str ):
237
241
# Set up formatting for the movie files
238
242
if os .path .exists (movie ):
239
243
print ("overwriting movie" , movie )
@@ -251,6 +255,8 @@ def update(frame, animation):
251
255
plt .pause (0.25 )
252
256
if _ani .event_source is None or len (_ani .event_source .callbacks ) == 0 :
253
257
break
258
+ return _ani
259
+
254
260
255
261
def __repr__ (self ):
256
262
"""
@@ -570,8 +576,10 @@ def run(
570
576
:type repeat: bool
571
577
:param interval: number of milliseconds between frames [default 50]
572
578
:type interval: int
573
- :param movie: name of file to write MP4 movie into
574
- :type movie: str
579
+ :param movie: name of file to write MP4 movie into or True
580
+ :type movie: str, bool
581
+ :returns: Matplotlib animation object
582
+ :rtype: Matplotlib animation object
575
583
576
584
Animates a 3D coordinate frame moving from the world frame to a frame
577
585
represented by the SO(3) or SE(3) matrix to the current axes.
@@ -580,6 +588,8 @@ def run(
580
588
581
589
- the ``movie`` option requires the ffmpeg package to be installed:
582
590
``conda install -c conda-forge ffmpeg``
591
+ - if ``movie=True`` then return an HTML5 video which can be displayed in a notebook
592
+ using ``HTML()``
583
593
- invokes the draw() method of every object in the display list
584
594
"""
585
595
@@ -601,8 +611,11 @@ def update(frame, a):
601
611
self .done = False
602
612
if self .trajectory is not None :
603
613
nframes = len (self .trajectory )
604
- ani = animation .FuncAnimation (
605
- fig = plt .gcf (),
614
+
615
+ global _ani
616
+ fig = plt .gcf ()
617
+ _ani = animation .FuncAnimation (
618
+ fig = fig ,
606
619
func = update ,
607
620
frames = range (0 , nframes ),
608
621
fargs = (self ,),
@@ -611,17 +624,19 @@ def update(frame, a):
611
624
repeat = repeat ,
612
625
)
613
626
614
- if movie is None :
615
- while repeat or not self . done :
616
- plt . pause ( 1 )
617
- else :
627
+ if movie is True :
628
+ plt . close ( fig )
629
+ return _ani . to_html5_video ( )
630
+ elif isinstance ( movie , str ) :
618
631
# Set up formatting for the movie files
619
632
if os .path .exists (movie ):
620
633
print ("overwriting movie" , movie )
621
634
else :
622
635
print ("creating movie" , movie )
623
636
FFwriter = animation .FFMpegWriter (fps = 10 , extra_args = ["-vcodec" , "libx264" ])
624
- ani .save (movie , writer = FFwriter )
637
+ _ani .save (movie , writer = FFwriter )
638
+
639
+ return _ani
625
640
626
641
def __repr__ (self ):
627
642
"""
0 commit comments