
    h                       S SK r S SKrS SKrS SKJrJr  S SKrS SKrS SKJ	r	  S SK
r
S SKrS SKrS SKJr  S SKrS SKrS SKrS SKJr  S SKrS SKJrJrJrJr  S SKJrJr  S SKJr   \RB                  " \"5      r#\RH                  S:X  a  \RJ                  OS r&S	 r' " S
 S5      r(\(" 5       r) " S S\ RT                  5      r+ " S S\+5      r, " S S\,5      r-\)R]                  S5       " S S\+5      5       r/ " S S5      r0\)R]                  S5       " S S\0\,5      5       r1\)R]                  S5       " S S\0\-5      5       r2 " S S5      r3\)R]                  S5       " S  S!\3\,5      5       r4\)R]                  S"5       " S# S$\3\-5      5       r5S% r6S& r7\)R]                  S'5       " S( S)\-5      5       r8 " S* S+5      r9 " S, S-\95      r: " S. S/\:5      r; " S0 S1\:5      r<S2 r=g)3    N)BytesIOTextIOWrapper)Path)TemporaryDirectory)Image)DISPLAY_TEMPLATEINCLUDED_FRAMES
JS_INCLUDESTYLE_INCLUDE)_apicbookwin32c                     S n[        X-  U-  5      U-  U-  n[        X-  U-  5      U-  U-  nU" XRU5      U" XbU5      4$ )z
Compute figure size so that pixels are a multiple of n.

Parameters
----------
w, h : float
    Size in inches.

dpi : float
    The dpi.

n : int
    The target multiple.

Returns
-------
wnew, hnew : float
    The new figure size in inches.
c                    [        X-  5      U-  S:w  a  [        [        R                  " U [        R                  5      U-  5      U-  S:X  a'  [        R                  " U [        R                  5      n U $ [        [        R                  " U [        R                  * 5      U-  5      U-  S:X  a&  [        R                  " U [        R                  * 5      n U $ )Nr   )intnp	nextafterinf)xdpins      F/var/www/html/env/lib/python3.13/site-packages/matplotlib/animation.pycorrect_roundoff*adjusted_figsize.<locals>.correct_roundoff7   s    qu:>Q2<<266*3./!3q8LLBFF+  R\\!bffW-c12Q6!;LLRVVG,    )r   )whr   r   r   wnewhnews          r   adjusted_figsizer        sW    . qw{a#%Dqw{a#%DDq)+;Dq+IIIr   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)MovieWriterRegistryD   z<Registry of available writer classes by human readable name.c                 "    [        5       U l        g N)dict_registeredselfs    r   __init__MovieWriterRegistry.__init__G   s    6r   c                    ^ ^ UU 4S jnU$ )zz
Decorator for registering a class under a name.

Example use::

    @registry.register(name)
    class Foo:
        pass
c                 &   > U TR                   T'   U $ r%   r'   )
writer_clsnamer)   s    r   wrapper-MovieWriterRegistry.register.<locals>.wrapperT   s    %/DT"r    )r)   r0   r1   s   `` r   registerMovieWriterRegistry.registerJ   s    	 r   c                 b     U R                   U   nUR                  5       $ ! [         a     gf = f)ze
Check if given writer is available by name.

Parameters
----------
name : str

Returns
-------
bool
F)r'   KeyErrorisAvailable)r)   r0   clss      r   is_available MovieWriterRegistry.is_availableY   s:    	""4(C     		s   ! 
..c              #   j   #    U R                    H  nU R                  U5      (       d  M  Uv   M!     g7f)z-Iterate over names of available writer class.N)r'   r:   r)   r0   s     r   __iter__MovieWriterRegistry.__iter__k   s+     $$D  &&
 %s   $3	3c                 
    / U Q$ )z%Get a list of available MovieWriters.r3   r(   s    r   listMovieWriterRegistry.listq   s    wr   c                 j    U R                  U5      (       a  U R                  U   $ [        SU S35      e)z,Get an available writer class from its name.zRequested MovieWriter (z) not available)r:   r'   RuntimeErrorr=   s     r   __getitem__MovieWriterRegistry.__getitem__u   s9    T""##D))4TF/JKKr   r.   N)__name__
__module____qualname____firstlineno____doc__r*   r4   r:   r>   rA   rE   __static_attributes__r3   r   r   r"   r"   D   s$    F"!$Lr   r"   c                       \ rS rSrSrSS jr\R                  SS j5       r\	S 5       r
S r\R                  S 5       r\R                  S	 5       r\R                  S
 5       rSrg)AbstractMovieWriter   al  
Abstract base class for writing movies, providing a way to grab frames by
calling `~AbstractMovieWriter.grab_frame`.

`setup` is called to start the process and `finish` is called afterwards.
`saving` is provided as a context manager to facilitate this process as ::

    with moviewriter.saving(fig, outfile='myfile.mp4', dpi=100):
        # Iterate over frames
        moviewriter.grab_frame(**savefig_kwargs)

The use of the context manager ensures that `setup` and `finish` are
performed as necessary.

An instance of a concrete subclass of this class can be given as the
``writer`` argument of `Animation.save()`.
Nc                     Xl         Ub  UO0 U l        [        R                  " US5      U l        [        R                  " US5      U l        g )Nzanimation.codecanimation.bitrate)fpsmetadatampl
_val_or_rccodecbitrate)r)   rR   rS   rV   rW   s        r   r*   AbstractMovieWriter.__init__   s;    $,$8b^^E+<=
~~g/BCr   c                     [        U5      R                  R                  SS9  X l        Xl        Uc  U R                  R
                  nX0l        g)ag  
Setup for writing the movie file.

Parameters
----------
fig : `~matplotlib.figure.Figure`
    The figure object that contains the information for frames.
outfile : str
    The filename of the resulting movie file.
dpi : float, default: ``fig.dpi``
    The DPI (or resolution) for the file.  This controls the size
    in pixels of the resulting movie file.
TstrictN)r   parentresolveoutfilefigr   )r)   r_   r^   r   s       r   setupAbstractMovieWriter.setup   s@      	W$$D$1;((,,Cr   c                     U R                   R                  5       u  p[        XR                  -  5      [        X R                  -  5      4$ )z7A tuple ``(width, height)`` in pixels of a movie frame.)r_   get_size_inchesr   r   )r)   r   r   s      r   
frame_sizeAbstractMovieWriter.frame_size   s9     xx'')1xx< #a((l"333r   c                     g)zz
Whether this writer supports transparency.

Writers may consult output file type and codec to determine this at runtime.
Fr3   r(   s    r   _supports_transparency*AbstractMovieWriter._supports_transparency   s     r   c                     g)a  
Grab the image information from the figure and save as a movie frame.

All keyword arguments in *savefig_kwargs* are passed on to the
`~.Figure.savefig` call that saves the figure.  However, several
keyword arguments that are supported by `~.Figure.savefig` may not be
passed as they are controlled by the MovieWriter:

- *dpi*, *bbox_inches*:  These may not be passed because each frame of the
   animation much be exactly the same size in pixels.
- *format*: This is controlled by the MovieWriter.
Nr3   r)   savefig_kwargss     r   
grab_frameAbstractMovieWriter.grab_frame       r   c                     g),Finish any processing for writing the movie.Nr3   r(   s    r   finishAbstractMovieWriter.finish   rn   r   c              /   L  #    [         R                  S   S:X  a  [        R                  S5        U R                  " XU/UQ70 UD6  [         R
                  " SS05          U v   U R                  5          SSS5        g! U R                  5         f = f! , (       d  f       g= f7f)z}
Context manager to facilitate writing the movie file.

``*args, **kw`` are any parameters that should be passed to `setup`.
savefig.bboxtightzkDisabling savefig.bbox = 'tight', as it may cause frame size to vary, which is inappropriate for animation.N)rT   rcParams_loginfor`   
rc_contextrq   )r)   r_   r^   r   argskwargss         r   savingAbstractMovieWriter.saving   s      <<'72II # $
 	

36t6v6^^^T23
	 43 	 43s6   AB$B A>$B5	B$>BB
B!B$)rW   rV   r   r_   rR   rS   r^   )   NNNr%   )rG   rH   rI   rJ   rK   r*   abcabstractmethodr`   propertyrd   rg   rl   rq   
contextlibcontextmanagerr|   rL   r3   r   r   rN   rN      s    $D 	 , 4 4
 	  	; ;  r   rN   c                      ^  \ rS rSrSrS/r  SU 4S jjrS rSU 4S jjrS r	S r
S	 rS
 r\S 5       r\S 5       rSrU =r$ )MovieWriter   a  
Base class for writing movies.

This is a base class for MovieWriter subclasses that write a movie frame
data to a pipe. You cannot instantiate this class directly.
See examples for how to use its subclasses.

Attributes
----------
frame_format : str
    The format used in writing frame data, defaults to 'rgba'.
fig : `~matplotlib.figure.Figure`
    The figure to capture data from.
    This must be provided by the subclasses.
rgbac                    > [        U 5      [        L a  [        S5      e[        TU ]  XUUS9  U R
                  S   U l        X@l        g)a  
Parameters
----------
fps : int, default: 5
    Movie frame rate (per second).
codec : str or None, default: :rc:`animation.codec`
    The codec to use.
bitrate : int, default: :rc:`animation.bitrate`
    The bitrate of the movie, in kilobits per second.  Higher values
    means higher quality movies, but increase the file size.  A value
    of -1 lets the underlying movie encoder select the bitrate.
extra_args : list of str or None, optional
    Extra command-line arguments passed to the underlying movie encoder. These
    arguments are passed last to the encoder, just before the filename. The
    default, None, means to use :rc:`animation.[name-of-encoder]_args` for the
    builtin writers.
metadata : dict[str, str], default: {}
    A dictionary of keys and values for metadata to include in the
    output file. Some keys that may be of use include:
    title, artist, genre, subject, copyright, srcform, comment.
zNMovieWriter cannot be instantiated directly. Please use one of its subclasses.)rR   rS   rV   rW   r   N)typer   	TypeErrorsuperr*   supported_formatsframe_format
extra_args)r)   rR   rV   rW   r   rS   	__class__s         r   r*   MovieWriter.__init__   sX    . :$
 %& & 	S5!( 	 	* 2215$r   c                    U R                   S:X  ao  U R                  R                  5       u  p[        XU R                  S5      u  p4X4X44:w  a1  U R                  R                  X4SS9  [        R                  SXX45        OU R                  R                  5       u  p4[        R                  " S/U R                  Q76   X44$ )Nh264   T)forwardz?figure size in inches has been adjusted from %s x %s to %s x %szframe size in pixels is %s x %s)
rV   r_   rc   r    r   set_size_inchesrw   rx   debugrd   )r)   wohor   r   s        r   _adjust_frame_sizeMovieWriter._adjust_frame_size%  s    ::XX--/FB#BDHHa8DAxA6!((t(<		 457QC 88++-DA

4GtGtr   c                 |   > [         TU ]  XUS9  U R                  5       u  U l        U l        U R                  5         g N)r   )r   r`   r   _w_h_runr)   r_   r^   r   r   s       r   r`   MovieWriter.setup2  s5    c,224 			r   c                     U R                  5       n[        R                  S[        R                  " U5      5        [
        R                  n[
        R                  " XX"[        S9U l	        g )Nz%MovieWriter._run: running command: %s)stdinstdoutstderrcreationflags)
_argsrw   rx   r   _pformat_subprocess
subprocessPIPEPopensubprocess_creation_flags_proc)r)   commandr   s      r   r   MovieWriter._run:  sO     **,		9++G4	6%%35
r   c                    U R                   R                  5       u  p[        [        U5      5      R	                  5       n[        [        U5      5      R	                  5       nU(       aP  [
        R                  U R                   R                  (       a  [        R                  O[        R                  SU5        U(       aP  [
        R                  U R                   R                  (       a  [        R                  O[        R                  SU5        U R                   R                  (       a@  [        R                  " U R                   R                  U R                   R                  X5      eg)rp   zMovieWriter stdout:
%szMovieWriter stderr:
%sN)r   communicater   r   readrw   log
returncodeloggingWARNINGDEBUGr   CalledProcessErrorrz   )r)   outerrs      r   rq   MovieWriter.finishF  s    ::))+GCL)..0GCL)..0HH#'::#8#8gmm)30 HH#'::#8#8gmm)30 ::  //

%%tzzB B !r   c                 4   [        U5        [        R                  S5        U R                  R	                  U R
                  U R                  5        U R                  R                  " U R                  R                  4U R                  U R                  S.UD6  g )Nz'MovieWriter.grab_frame: Grabbing frame.formatr   )_validate_grabframe_kwargsrw   r   r_   r   r   r   savefigr   r   r   r   rj   s     r   rl   MovieWriter.grab_frameX  so    ">2

<= 	  $''2)) 	9$2C2C!XX	9)7	9r   c                     [        S5      $ )z9Assemble list of encoder-specific command-line arguments.z)args needs to be implemented by subclass.NotImplementedErrorr(   s    r   r   MovieWriter._argsc  s    "#NOOr   c                 N    [        [        R                  U R                     5      $ )z
Return the binary path to the commandline tool used by a specific
subclass. This is a class method so that the tool can be looked for
before making a particular MovieWriter subclass available.
)strrT   rv   	_exec_keyr9   s    r   bin_pathMovieWriter.bin_pathg  s     3<<.//r   c                 N    [         R                  " U R                  5       5      SL$ )z<Return whether a MovieWriter subclass is actually available.N)shutilwhichr   r   s    r   r8   MovieWriter.isAvailablep  s     ||CLLN+477r   )r   r   r   r   r   )r~   NNNNr%   )rG   rH   rI   rJ   rK   r   r*   r   r`   r   rq   rl   r   classmethodr   r8   rL   __classcell__r   s   @r   r   r      sf    0  CG#%J
5B$	9P 0 0 8 8r   r   c                      ^  \ rS rSrSrU 4S jrSS jrS r\S 5       r	\	R                  S 5       r	S rS	 rU 4S
 jrSrU =r$ )FileMovieWriteriv  zq
`MovieWriter` for writing to individual files and stitching at the end.

This must be sub-classed to be useful.
c                 V   > [         TU ]  " U0 UD6  [        R                  S   U l        g )Nzanimation.frame_format)r   r*   rT   rv   r   )r)   rz   r{   r   s      r   r*   FileMovieWriter.__init__|  s'    $)&)LL)ABr   c                    [        U5      R                  R                  SS9  Xl        X l        Uc  U R                  R
                  nX0l        U R                  5         Uc>  [        5       U l        [        [        U R                  R                  S5      5      U l        OSU l        X@l        SU l        [        5       U l        SU l        g)aS  
Setup for writing the movie file.

Parameters
----------
fig : `~matplotlib.figure.Figure`
    The figure to grab the rendered frames from.
outfile : str
    The filename of the resulting movie file.
dpi : float, default: ``fig.dpi``
    The dpi of the output file. This, with the figure size,
    controls the size in pixels of the resulting movie file.
frame_prefix : str, optional
    The filename prefix to use for temporary files.  If *None* (the
    default), files are written to a temporary directory which is
    deleted by `finish`; if not *None*, no temporary files are
    deleted.
TrZ   Ntmpr   z
%s%%07d.%s)r   r\   r]   r_   r^   r   r   r   _tmpdirr   r0   temp_prefix_frame_counterrA   _temp_pathsfname_format_str)r)   r_   r^   r   frame_prefixs        r   r`   FileMovieWriter.setup  s    ( 	W$$D$1;((,,C!-/DL"4(9(95#ABDDL+6 ,r   c                     [        U S5      (       a-  U R                  (       a  U R                  R                  5         g g g )Nr   )hasattrr   cleanupr(   s    r   __del__FileMovieWriter.__del__  s-    4##LL  " )5#r   c                     U R                   $ )zk
Format (png, jpeg, etc.) to use for saving the frames, which can be
decided by the individual subclasses.
)_frame_formatr(   s    r   r   FileMovieWriter.frame_format  s     !!!r   c           	          XR                   ;   a  Xl        g [        R                  " SU< S[	        U 5      R
                   SU R                   S    S35        U R                   S   U l        g )NzIgnoring file format z which is not supported by z; using r   z	 instead.)r   r   r   warn_externalr   rG   )r)   r   s     r   r   r     sn    111!-''7 8  $T
 3 34H))!,-Y89 "&!7!7!:Dr   c                 L    U R                   U R                  U R                  4-  $ r%   )r   r   r   r(   s    r   _base_temp_nameFileMovieWriter._base_temp_name  s&     $$(8(8$:K:K'LLLr   c                    [        U5        [        U R                  5       U R                  -  5      nU R                  R                  U5        U =R                  S-  sl        [        R                  SU R                  U5        [        US5       nU R                  R                  " U4U R                  U R                  S.UD6  S S S 5        g ! , (       d  f       g = f)N   z8FileMovieWriter.grab_frame: Grabbing frame %d to path=%swbr   )r   r   r   r   r   appendrw   r   openr_   r   r   r   )r)   rk   pathsinks       r   rl   FileMovieWriter.grab_frame  s     	#>2D((*T-@-@@A%q 

M&&	.$HHT /$*;*; /-/ s   5C
Cc                 ~  >  U R                  5         [        TU ]	  5         U R                  (       a;  [        R                  SU R                  5        U R                  R                  5         g g ! U R                  (       a;  [        R                  SU R                  5        U R                  R                  5         f f = f)N'MovieWriter: clearing temporary path=%s)r   r   rq   r   rw   r   r   )r)   r   s    r   rq   FileMovieWriter.finish  s    	'IIKGN||

=t|| $$&	 t||

=t|| $$&	 s   A. .AB<)
r   r   r   r   r   r_   r   r   r^   r   NN)rG   rH   rI   rJ   rK   r*   r`   r   r   r   setterr   rl   rq   rL   r   r   s   @r   r   r   v  s\    
C$-L# " " ; ;M
/' 'r   r   pillowc                   N   ^  \ rS rSrS r\S 5       rSU 4S jjrS rS r	Sr
U =r$ )	PillowWriteri  c                     gNTr3   r(   s    r   rg   #PillowWriter._supports_transparency  s    r   c                     gr   r3   r   s    r   r8   PillowWriter.isAvailable      r   c                 0   > [         TU ]  XUS9  / U l        g r   )r   r`   _framesr   s       r   r`   PillowWriter.setup  s    c,r   c           	         [        U5        [        5       nU R                  R                  " U40 0 UESU R                  S.ED6  [
        R                  " SU R                  UR                  5       SSSS5      nUR                  5       S   S   S:  a  U R                  R                  U5        g U R                  R                  UR                  S	5      5        g )
Nr   r   RGBArawr   r         RGB)r   r   r_   r   r   r   
frombufferrd   	getbuffer
getextremar  r   convert)r)   rk   bufims       r   rl   PillowWriter.grab_frame  s    ">2i	JHnHtxxH	JDOOS]]_eVQK==?1a 3&LL# LL

5 12r   c           	          U R                   S   R                  U R                  SU R                   SS  [        SU R                  -  5      SS9  g )Nr   Tr     )save_allappend_imagesdurationloop)r  saver^   r   rR   r(   s    r   rq   PillowWriter.finish  sE    QLL4t||AB7G) 	 	3r   )r  r%   )rG   rH   rI   rJ   rg   r   r8   r`   rl   rq   rL   r   r   s   @r   r   r     s0      33 3r   r   c                   6    \ rS rSrSrSrSrS r\S 5       r	Sr
g)	
FFMpegBasei  zv
Mixin class for FFMpeg output.

This is a base class for the concrete `FFMpegWriter` and `FFMpegFileWriter`
classes.
zanimation.ffmpeg_pathzanimation.ffmpeg_argsc                 l    [        U R                  5      R                  nUS;   a  gU R                  S;   $ )N   .gif.apng.avif.webm.webpT>   bmpdpxgifpngapngavrpcfhdffv1tiffv408ljpegqtrletargaproresffvhuffhuffyuvutvideojpeg2000rawvideo	prores_aw	prores_ks)r   r^   suffixrV   r)   r9  s     r   rg   !FFMpegBase._supports_transparency  s:    dll#**AA zz > > 	>r   c                     / n[        U R                  5      R                  nUS;   a  USS  U l        OUR	                  SU R                  /5        U R
                  b  U R
                  O[        R                  U R                     nU R                  S:X  a  SU;  a  UR	                  SS/5        OSU R                  S:X  a  SU;  a  UR	                  SS	/5        O)U R                  S
:X  a  SU;  a  UR	                  / SQ5        U R                  S:  a   UR	                  SSU R                  -  /5        U R                  R                  5        H  u  pEUR	                  SU SU 3/5        M     UR	                  U5        USU R                  /-   $ )Nr  r   -vcodecr   -pix_fmtyuv420pr&  -filter_complexz1split [a][b];[a] palettegen [p];[b][p] paletteuseavif)r@  z.split [rgb][rgba]; [rgba] alphaextract [alpha]-mapz[rgb]rB  z[alpha]r   z-bz%dkz	-metadata=z-y)r   r^   r9  rV   extendr   rT   rv   	_args_keyrW   rS   items)r)   rz   r9  r   kvs         r   output_argsFFMpegBase.output_args  sc   dll#**AADJKKDJJ/0)-)Ddoo<<7 	 ::Jj$@KKY/0 ZZ5 %6j%HKK*LN O ZZ6!&7z&IKK = > <<!KKut||345MM'')DAKK1QCj12 *JtT\\***r   )rV   N)rG   rH   rI   rJ   rK   r   rE  rg   r   rI  rL   r3   r   r   r  r    s,     (I'I>  +  +r   r  ffmpegc                       \ rS rSrSrS rSrg)FFMpegWriteri?  a\  
Pipe-based ffmpeg writer.

Frames are streamed directly to ffmpeg via a pipe and written in a single pass.

This effectively works as a slideshow input to ffmpeg with the fps passed as
``-framerate``, so see also `their notes on frame rates`_ for further details.

.. _their notes on frame rates: https://trac.ffmpeg.org/wiki/Slideshow#Framerates
c                    U R                  5       SSSSSSU R                  -  SU R                  S[        U R                  5      /n[
        R                  5       [        R                  :  a  USS	/-  nUS
S/U R                  -   -  nU$ )N-fr6  r=  z-s%dx%dr>  
-framerate	-loglevelerror-izpipe:)
r   rd   r   r   rR   rw   getEffectiveLevelr   r   rI  r)   rz   s     r   r   FFMpegWriter._argsK  s     z9jg/T=N=Nc$((m- !!#gmm3['**Dw$"2"222r   r3   N)rG   rH   rI   rJ   rK   r   rL   r3   r   r   rM  rM  ?  s    	r   rM  ffmpeg_filec                   &    \ rS rSrSr/ SQrS rSrg)FFMpegFileWriteri[  aa  
File-based ffmpeg writer.

Frames are written to temporary files on disk and then stitched together at the end.

This effectively works as a slideshow input to ffmpeg with the fps passed as
``-framerate``, so see also `their notes on frame rates`_ for further details.

.. _their notes on frame rates: https://trac.ffmpeg.org/wiki/Slideshow#Framerates
r'  jpegr,  r  r   c           	         / nU R                   S;   a  USSSSSSU R                  -  SS	/-  nUS
[        U R                  5      SU R	                  5       /-  nU R
                  (       d  US[        U R                  5      /-  n[        R                  5       [        R                  :  a  USS/-  nU R                  5       /UQU R                  Q$ )N>   r  r   rO  image2r=  r6  z-video_sizerP  z-pixel_formatr   rQ  rT  z	-frames:vrR  rS  )r   rd   r   rR   r   r   r   rw   rU  r   r   r   rI  rV  s     r   r   FFMpegFileWriter._argsi  s     /h	:w8 D
 	s488}dD4H4H4JKK||[#d&9&9":;;D !!#gmm3['**D:$:)9)9::r   r3   N)rG   rH   rI   rJ   rK   r   r   rL   r3   r   r   rZ  rZ  [  s    	 ?;r   rZ  c                   `   ^  \ rS rSrSrSrSrS rS r\	U 4S j5       r
\	U 4S j5       rS	rU =r$ )
ImageMagickBasei  z
Mixin class for ImageMagick output.

This is a base class for the concrete `ImageMagickWriter` and
`ImageMagickFileWriter` classes, which define an ``input_names`` attribute
(or property) specifying the input names passed to ImageMagick.
zanimation.convert_pathzanimation.convert_argsc                 J    [        U R                  5      R                  nUS;   $ )Nr  )r   r^   r9  r:  s     r   rg   &ImageMagickBase._supports_transparency  s"    dll#**EEEr   c                 ^   U R                   S:X  a  SOU R                   nU R                  b  U R                  O[        R                  U R                     nU R                  5       SSU R                  -  SSS[        SU R                  -  5      S	S
U SU R                   3/
UQU R                  P$ )Nr  r   z-sizez%ix%iz-depth8z-delayd   z-loop0:)r   r   rT   rv   rE  r   rd   r   rR   input_namesr^   )r)   fmtr   s      r   r   ImageMagickBase._args  s    ))U2f8I8I)-)Ddoo<<7 	 MMOWt.cc#.)Se1T%%&'	
 	
 LL	
 		
r   c                 p   > [         TU ]  5       nUS:X  a   [        R                  " S5      R                  nU$ )Nr  magick)r   r   rT   _get_executable_info
executable)r9   binpathr   s     r   r   ImageMagickBase.bin_path  s3    '"$i..x8CCGr   c                    >  [         TU ]  5       $ ! [        R                   a   n[        R                  SU5         S nAgS nAff = f)Nz"ImageMagick unavailable due to: %sF)r   r8   rT   ExecutableNotFoundErrorrw   r   )r9   _enfr   s     r   r8   ImageMagickBase.isAvailable  s>    	7&((** 	JJ;TB	s    AA  Ar3   )rG   rH   rI   rJ   rK   r   rE  rg   r   r   r   r8   rL   r   r   s   @r   ra  ra    sG     )I(IF
     r   ra  imagemagickc                       \ rS rSrSrSrSrg)ImageMagickWriteri  zw
Pipe-based animated gif writer.

Frames are streamed directly to ImageMagick via a pipe and written
in a single pass.
-r3   N)rG   rH   rI   rJ   rK   ri  rL   r3   r   r   rx  rx    s     Kr   rx  imagemagick_filec                   2    \ rS rSrSr/ SQr\" S 5      rSrg)ImageMagickFileWriteri  zw
File-based animated gif writer.

Frames are written to temporary files on disk and then stitched
together at the end.
r[  c                 8    U R                    SU R                   3$ )Nz*.)r   r   r(   s    r   <lambda>ImageMagickFileWriter.<lambda>  s    (()D,=,=+>?r   r3   N)	rG   rH   rI   rJ   rK   r   r   ri  rL   r3   r   r   r|  r|    s     ??AKr   r|  c                 .    [         R                  " U UUS9$ )N)Nframes	frame_dirr   )r	   r   )frame_countr   r  s      r   _included_framesr    s    !!+,5/;= =r   c                 j   ^^ TS:X  a  SmSmSSR                  UU4S j[        U 5       5       5      -   $ )z7frame_list should be a list of base64-encoded png filessvgzsvg+xmlz,  frames[{0}] = "data:image/{1};base64,{2}"

 c           	   3   n   >#    U  H*  u  pTR                  UTUR                  S S5      5      v   M,     g7f)r  z\
N)r   replace).0i
frame_datar   templates      r   	<genexpr>#_embedded_frames.<locals>.<genexpr>  s7      42MA 	<););D&)IJJ2s   25)join	enumerate)
frame_listr   r  s    `@r   _embedded_framesr    s?    u >H"'' 4&z24 4 4 4r   htmlc                   p   ^  \ rS rSrSr/ SQr\S 5       r   S
U 4S jjrSU 4S jjr	U 4S jr
S rS	rU =r$ )
HTMLWriteri  z(Writer for JavaScript-based HTML movies.)r'  r\  r,  r  c                     gr   r3   r   s    r   r8   HTMLWriter.isAvailable  r  r   c	                 >  > U(       a  [         R                  S5        SnX`l        UR                  5       U l        [
        R                  " / SQU R                  S9  [        R                  " US5      U l	        U =R                  S-  sl	        [        T	U ]-  XX4U5        g )NzHTMLWriter ignores 'extra_args'r3   )r  oncereflect)default_modeanimation.embed_limit   )rw   warningembed_frameslowerr  r   check_in_listrT   rU   _bytes_limitr   r*   )
r)   rR   rV   rW   r   rS   r  r  embed_limitr   s
            r   r*   HTMLWriter.__init__  s     LL:;
((..06(,(9(9	;  NN;8OP[(W(Cr   c                 J  > [        U5      n[        R                  " SS/UR                  S9  / U l        SU l        SU l        U R                  (       d7  Uc  UR                  UR                  S-   5      nUR                  SSS9  US	-  nOS n[        TU ]1  XX55        SU l        g )
Nz.htmlz.htm)outfile_extensionr   Fr  T)parentsexist_okframe)r   r   r  r9  _saved_frames_total_bytes
_hit_limitr  	with_namestemmkdirr   r`   _clear_temp)r)   r_   r^   r   r  r   r   s         r   r`   HTMLWriter.setup  s    w-GV,O   #--gllY.FG	OOD4O8$w.LLcC6 r   c                 r  > [        U5        U R                  (       Ga
  U R                  (       a  g [        5       nU R                  R
                  " U4U R                  U R                  S.UD6  [        R                  " UR                  5       5      R                  S5      nU =R                  [        U5      -  sl        U R                  U R                  :  a3  [        R!                  SU R                  U R                  5        SU l        g U R"                  R%                  U5        g [&        TU ]P  " S0 UD6$ )Nr   asciizAnimation size has reached %s bytes, exceeding the limit of %s. If you're sure you want a larger animation embedded, set the animation.embed_limit rc parameter to a larger value (in MB). This and further frames will be dropped.Tr3   )r   r  r  r   r_   r   r   r   base64encodebytesgetvaluedecoder  lenr  rw   r  r  r   r   rl   )r)   rk   f	imgdata64r   s       r   rl   HTMLWriter.grab_frame  s    ">2	AHHQ =t'8'8!%=-;=**1::<8??HIY/  D$5$55 !% 1 143D3DF #'"")))47%777r   c                 p   U R                   (       a6  [        U R                  U R                  5      n[	        U R                  5      nOe[	        U R
                  5      n[        X R                  U R
                  S   R                  R                  U R                  R                  5      5      n[        SSSS9nSX0R                  S-   '   SU R                  -  n[        U R                  S5       nUR                  [        [         -   5        UR                  ["        R$                  " S
[&        R(                  " 5       R*                  UUUS.UD65        S S S 5        U R,                  (       a;  [.        R1                  S	U R,                  5        U R,                  R3                  5         g g ! , (       d  f       N[= f)Nr   r  )once_checkedloop_checkedreflect_checkedchecked_checkedr  r   )idr  fill_framesintervalr   r3   )r  r  r  r   r  r   r  r\   relative_tor^   r&   r  rR   r   writer
   r   r   r   uuiduuid4hexr   rw   r   r   )r)   r  r  	mode_dictr  ofs         r   rq   HTMLWriter.finish(  s\   *4+=+=+/+<+<>Kd001K d../K*..  #**66t||7J7JKMK b&()+-	 5>	##j01488#$,,$HHZ-/0HH%,, :

0@0@5@9D6>: 09	: ; % <<JJ@$,,OLL  "  %$s   .A$F''
F5)r  r  r  r  r  r  r  )   NNNNFr  Nr   )rG   rH   rI   rJ   rK   r   r   r8   r*   r`   rl   rq   rL   r   r   s   @r   r  r    sE    26  EIAG!D&!&80"# "#r   r  c                       \ rS rSrSrSS jrS rS rS r   SSS.S	 jjr	S
 r
S rS rS rS rS rS rS rS rS rS rS rS rSS jrS S jrS rS rS rSrg)!	AnimationiM  a~  
A base class for Animations.

This class is not usable as is, and should be subclassed to provide needed
behavior.

.. note::

    You must store the created Animation in a variable that lives as long
    as the animation should run. Otherwise, the Animation object will be
    garbage-collected and the animation stops.

Parameters
----------
fig : `~matplotlib.figure.Figure`
    The figure object used to get needed events, such as draw or resize.

event_source : object, optional
    A class that can run a callback when desired events
    are generated, as well as be stopped and started.

    Examples include timers (see `TimedAnimation`) and file
    system notifications.

blit : bool, default: False
    Whether blitting is used to optimize drawing.  If the backend does not
    support blitting, then this parameter has no effect.

See Also
--------
FuncAnimation,  ArtistAnimation
Nc                    SU l         Xl        U=(       a    UR                  R                  U l        U R                  5       U l        X l        UR                  R                  SU R                  5      U l
        U R                  R                  R                  SU R                  5      U l        U R                  (       a  U R                  5         g g )NF
draw_eventclose_event)_draw_was_started_figcanvassupports_blit_blitnew_frame_seq	frame_seqevent_sourcempl_connect_start_first_draw_id_stop	_close_id_setup_blit)r)   r_   r  blits       r   r*   Animation.__init__o  s    !&	 6cjj66
 ++-( "jj44\4;;O ))55m6:jjB:: r   c                 V    [        U SS5      (       d  [        R                  " S5        g g )Nr  TzAnimation was deleted without rendering anything. This is most likely not intended. To prevent deletion, assign the Animation to a variable, e.g. `anim`, that exists until you output the Animation using `plt.show()` or `anim.save()`.)getattrwarningswarnr(   s    r   r   Animation.__del__  s(    t0$77MM! 8r   c                 T   U R                   R                  R                  5       (       a  gU R                   R                  R                  U R                  5        U R                  5         U R                  R                  U R                  5        U R                  R                  5         g)zs
Starts interactive animation. Adds the draw frame command to the GUI
handler, calls show to start the event loop.
N)
r  r  	is_savingmpl_disconnectr  
_init_drawr  add_callback_stepstartrV  s     r   r  Animation._start  sv     99%%''		''(;(;< 	 	&&tzz2!r   c                 :   U R                   (       a/  U R                  R                  R                  U R                  5        U R                  R                  R                  U R
                  5        U R                  R                  U R                  5        S U l        g r%   )	r  r  r  r  
_resize_idr  r  remove_callbackr  rV  s     r   r  Animation._stop  sa    ::II++DOO<		''7))$**5 r   )progress_callbackc          
        ^  T /nU	b  UR                  U 4S jU	 5       5        U H
  nSUl        M     Uc  [        R                  S   nO:[	        U[
        5      (       d%  [        S X5XgU4 5       5      (       a  [        S5      eU
c  0 n
O[        U
5      n
Uc   [        T S5      (       a  ST R                  -  n[        R                  " US	5      nUS
:X  a  T R                  R                  n0 nUb  X^S'   Ub  XnS'   Ub  X~S'   Ub  XS'   [	        U[
        5      (       a   [        U   nU" U40 UD6n[         R%                  S['        U5      5        SU
;   a&  [         R#                  S5        U
R)                  S5        S nUR+                  T R                  X5         [,        R.                  " T R                  R0                  SSS9   UR3                  5       (       dS  U
R5                  S[        R                  S   5      nUS:X  a  T R                  R7                  5       nU" U5      U
S'   SU
S'   U H  nUR9                  5         M     SnU Vs/ s H  n[;        USS5      PM     nnSU;   a  SnO[=        U5      n[?        U Vs/ s H  nURA                  5       PM     sn6  HN  n[?        UU5       H)  u  nnURC                  USS9  Uc  M  U" UU5        US-  nM+     URD                  " S0 U
D6  MP     SSS5        SSS5        g! [         a     [        n[         R#                  SU5         GNf = fs  snf s  snf ! , (       d  f       NN= f! , (       d  f       g= f)a4  
Save the animation as a movie file by drawing every frame.

Parameters
----------
filename : str
    The output filename, e.g., :file:`mymovie.mp4`.

writer : `MovieWriter` or str, default: :rc:`animation.writer`
    A `MovieWriter` instance to use or a key that identifies a
    class to use, such as 'ffmpeg'.

fps : int, optional
    Movie frame rate (per second).  If not set, the frame rate from the
    animation's frame interval.

dpi : float, default: :rc:`savefig.dpi`
    Controls the dots per inch for the movie frames.  Together with
    the figure's size in inches, this controls the size of the movie.

codec : str, default: :rc:`animation.codec`.
    The video codec to use.  Not all codecs are supported by a given
    `MovieWriter`.

bitrate : int, default: :rc:`animation.bitrate`
    The bitrate of the movie, in kilobits per second.  Higher values
    means higher quality movies, but increase the file size.  A value
    of -1 lets the underlying movie encoder select the bitrate.

extra_args : list of str or None, optional
    Extra command-line arguments passed to the underlying movie encoder. These
    arguments are passed last to the encoder, just before the output filename.
    The default, None, means to use :rc:`animation.[name-of-encoder]_args` for
    the builtin writers.

metadata : dict[str, str], default: {}
    Dictionary of keys and values for metadata to include in
    the output file. Some keys that may be of use include:
    title, artist, genre, subject, copyright, srcform, comment.

extra_anim : list, default: []
    Additional `Animation` objects that should be included
    in the saved movie file. These need to be from the same
    `.Figure` instance. Also, animation frames will
    just be simply combined, so there should be a 1:1 correspondence
    between the frames from the different animations.

savefig_kwargs : dict, default: {}
    Keyword arguments passed to each `~.Figure.savefig` call used to
    save the individual frames.

progress_callback : function, optional
    A callback function that will be called for every frame to notify
    the saving progress. It must have the signature ::

        def func(current_frame: int, total_frames: int) -> Any

    where *current_frame* is the current frame number and *total_frames* is the
    total number of frames to be saved. *total_frames* is set to None, if the
    total number of frames cannot be determined. Return values may exist but are
    ignored.

    Example code to write the progress to stdout::

        progress_callback = lambda i, n: print(f'Saving frame {i}/{n}')

Notes
-----
*fps*, *codec*, *bitrate*, *extra_args* and *metadata* are used to
construct a `.MovieWriter` instance and can only be passed if
*writer* is a string.  If they are passed as non-*None* and *writer*
is a `.MovieWriter`, a `RuntimeError` will be raised.
Nc              3   ^   >#    U  H"  nUR                   TR                   L d  M  Uv   M$     g 7fr%   )r  )r  animr)   s     r   r  !Animation.save.<locals>.<genexpr>  s(      7ZT#yyDII5 !DZs   -	-Tanimation.writerc              3   *   #    U  H	  nUS Lv   M     g 7fr%   r3   )r  args     r   r  r    s      JHc T/Hs   zPassing in values for arguments fps, codec, bitrate, extra_args, or metadata is not supported when writer is an existing MovieWriter instance. These should instead be passed as arguments when creating the MovieWriter instance.	_interval     @@zsavefig.dpifigurerV   rW   r   rS   z1MovieWriter %s unavailable; using Pillow instead.zAnimation.save using %sbbox_incheszWarning: discarding the 'bbox_inches' argument in 'savefig_kwargs' as it may cause frame size to vary, which is inappropriate for animation.c                 v    [         R                  " U 5      u  pp4U[        R                  " XU/5      -  S-   U-
  $ )Nr   )mcolorsto_rgbar   array)colorrgbas        r   _pre_composite_to_white/Animation.save.<locals>._pre_composite_to_whiteC  s6     /JA!rxxq	**Q.22r   )
_is_savingmanager	facecolorzsavefig.facecolorautoFtransparentr   _save_count)r  r   r3   )#rD  r  rT   rv   
isinstancer   anyrD   r&   r   r  rU   r  r   writersr   rw   r  rx   r   popr|   r   _setattr_cmr  rg   getget_facecolorr  r  sumzipnew_saved_frame_seq_draw_next_framerl   )r)   filenamewriterrR   r   rV   rW   r   rS   
extra_animrk   r  all_animr  writer_kwargsr/   r  r  frame_numberr
  save_count_listtotal_framesdatads   `                       r   r  Animation.save  se   Z 6!OO 7Z 7 7 D%)D"  >\\"45FVS)) J!'xHJ J J  7 8 8 !N ".1N;7455$..(C nnS-0(?))--C%*'"'.)$!*4,'(0*% fc""1$V_

  5}5F		+T&\:N*LL J K }-	3 mmDIIx5		 0 0T4P0022*..{/2||<O/PR	& $		 7 7 9I.Ei.P{+05}- ! !L )12(01  'q->(0  2&#"?3xHx!a335xHI"8T2GD!))!%)8(4),E$)  3 !!3N3 J) Q 657   1)
 ()/11T2 I) QP 65s[   	L +MBL<L2%L<L7*L<(L<4M&L/.L/2
L<<
M
	M
Mc                      [        U R                  5      nU R                  X R                  5        g! [         a     gf = f)zq
Handler for getting events. By default, gets the next frame in the
sequence and hands the data off to be drawn.
TF)nextr  r  r  StopIteration)r)   rz   	framedatas      r   r  Animation._steph  s<    	T^^,I!!)ZZ8 		s   03 
A A c                 ,    [        U R                  5      $ )z+Return a new sequence of frame information.)iter
_framedatar(   s    r   r  Animation.new_frame_seqw  s     DOO$$r   c                 "    U R                  5       $ )z8Return a new sequence of saved/cached frame information.)r  r(   s    r   r  Animation.new_saved_frame_seq|  s     !!##r   c                 j    U R                  X5        U R                  U5        U R                  X5        g r%   )	_pre_draw_draw_frame
_post_drawr)   r,  r  s      r   r  Animation._draw_next_frame  s*     	y'#	(r   c                     SU l         g r   )r  r(   s    r   r  Animation._init_draw  s     "&r   c                 J    U(       a  U R                  U R                  5        g g r%   )_blit_clear_drawn_artistsr8  s      r   r5  Animation._pre_draw  s      T001 r   c                     [        S5      e)NzDNeeds to be implemented by subclasses to actually make an animation.r   )r)   r,  s     r   r6  Animation._draw_frame  s    ! #A B 	Br   c                     U(       a-  U R                   (       a  U R                  U R                   5        g U R                  R                  R	                  5         g r%   )r>  
_blit_drawr  r  	draw_idler8  s      r   r7  Animation._post_draw  s7     D''OOD//0II&&(r   c                    U Vs1 s H  o"R                   iM     nnU H  nUR                  5       nU R                  R                  U[	        5       S 45      u  pgXV:w  d  MB  XTR
                  R                  R                  UR                  5      4U R                  U'   M     U H  nUR                   R                  U5        M      U H2  nUR
                  R                  R                  UR                  5        M4     g s  snf r%   )axes	_get_view_blit_cacher  objectr   r  copy_from_bboxbboxdraw_artistr  )r)   artistsr
  
updated_axaxcur_viewviewbgs           r   rC  Animation._blit_draw  s     '..gffg
. B ||~H''++B40@AHDii..==bggF(H  $  AFFq!  BII!!"''* ! /s   C>c                 H   U Vs1 s H  o"R                   iM     nnU Hk  n U R                  U   u  pVUR                  5       U:X  a'  UR                  R
                  R                  U5        MP  U R                  R                  U5        Mm     g s  snf ! [         a     M  f = fr%   )rG  rI  r7   rH  r   r  restore_regionr  )r)   rN  r
  rG  rP  rR  rS  s          r   r=  Animation._blit_clear  s     !((1(B++B/ ||~%		  //3  $$R(  )  s   BB
B! B!c                     [        5       U l        / U l        U R                  S U R                  5        U R                  5         U R                  R                  R                  SU R                  5      U l
        g )Nresize_event)r&   rI  r>  r7  r  r  r  r  r  
_on_resizer  r(   s    r   r  Animation._setup_blit  sX    6 djj)
 	))**66~7;Hr   c                 T   U R                   R                  R                  U R                  5        U R                  R                  5         U R                  R                  5         U R                  5         U R                   R                  R                  SU R                  5      U l        g )Nr  )r  r  r  r  r  stoprI  clearr  r  _end_redrawr)   events     r   rZ  Animation._on_resize  sv    
 			''8  ))**66|7;7G7GIr   c                 $   U R                  S S5        U R                  R                  5         U R                  R                  R                  U R                  5        U R                  R                  R                  SU R                  5      U l        g )NFrY  )	r7  r  r  r  r  r  r  r  rZ  r`  s     r   r_  Animation._end_redraw  sf     	e$!		''8))**66~7;Hr   c                 L   Sn[        U S5      (       Gd  [        R                  " US5      nUS-  n[        5        n[	        US5      n[
        [        R                  S      nU" S[        R                  S   S	U R                  -  S
9nU R                  [        U5      US9  [        R                  " UR                  5       5      nSSS5        [        W5      nX:  a  [        R                  SX5        O4UR!                  S5      U l        SR$                  " WR&                  6 U l        [        U S5      (       a[  SS/n	[+        U SS5      (       a  U	R-                  S5        UR%                  U R"                  U R(                  SR/                  U	5      S9$ g! , (       d  f       N= f)a  
Convert the animation to an HTML5 ``<video>`` tag.

This saves the animation as an h264 video, encoded in base64
directly into the HTML5 video tag. This respects :rc:`animation.writer`
and :rc:`animation.bitrate`. This also makes use of the
*interval* to control the speed, and uses the *repeat*
parameter to decide whether to loop.

Parameters
----------
embed_limit : float, optional
    Limit, in MB, of the returned animation. No animation is created
    if the limit is exceeded.
    Defaults to :rc:`animation.embed_limit` = 20.0.

Returns
-------
str
    An HTML5 video tag with the animation embedded as base64 encoded
    h264 video.
    If the *embed_limit* is exceeded, this returns the string
    "Video too large to embed."
z<video {size} {options}>
  <source type="video/mp4" src="data:video/mp4;base64,{video}">
  Your browser does not support the video tag.
</video>_base64_videor  r  ztemp.m4vr  r   rQ   r  )rV   rW   rR   r  NzAnimation movie is %s bytes, exceeding the limit of %s. If you're sure you want a large animation embedded, set the animation.embed_limit rc parameter to a larger value (in MB).r  zwidth="{}" height="{}"controlsautoplay_repeatFr   )videosizeoptionszVideo too large to embed.)r   rT   rU   r   r   r  rv   r  r  r   r  r  
read_bytesr  rw   r  r  rf  r   rd   _video_sizer  r   r  )
r)   r  	VIDEO_TAGtmpdirr   Writerr  vid64vid_lenrn  s
             r   to_html5_videoAnimation.to_html5_video  s   2	
 t_--..6MNK ;&K $%FJ/ !.@!ABf(+5H(I$)DNN$:< 		#d)F	3**4??+<= & %jG% !(	6 &+\\'%:"#;#B#B**$,  4))!:.G tY..v&##$*<*<)-)9)9,/HHW,= $ ? ? /K &%s   B
F
F#c                    Uc   [        U S5      (       a  SU R                  -  nUc  [        U SS5      (       a  SOSn[        U S5      (       dd  [        5        n[	        US	5      n[        UUUS
9nU R                  [        U5      US9  UR                  5       U l	        SSS5        U R                  $ U R                  $ ! , (       d  f       U R                  $ = f)a.  
Generate HTML representation of the animation.

Parameters
----------
fps : int, optional
    Movie frame rate (per second). If not set, the frame rate from
    the animation's frame interval.
embed_frames : bool, optional
default_mode : str, optional
    What to do when the animation ends. Must be one of ``{'loop',
    'once', 'reflect'}``. Defaults to ``'loop'`` if the *repeat*
    parameter is True, otherwise ``'once'``.

Returns
-------
str
    An HTML representation of the animation embedded as a js object as
    produced with the `.HTMLWriter`.
Nr  r  rj  Fr  r  _html_representationz	temp.html)rR   r  r  rg  )
r   r  r  r   r   r  r  r   	read_textry  )r)   rR   r  r  rr  r   r  s          r   	to_jshtmlAnimation.to_jshtml9  s    * ;7455'C %,T9-2&4 &469?  t344 $%FK0#1=1=? 		#d)F	3,0NN,<) & (((t((( &% (((s   AB>>
Cc                     [         R                  S   nUS:X  a  U R                  5       $ US:X  a  U R                  5       $ g)z#IPython display hook for rendering.zanimation.htmlhtml5jshtmlN)rT   rv   rv  r{  )r)   rj  s     r   _repr_html_Animation._repr_html_e  s@    ll+,'>&&((H_>>## r   c                     U R                   R                  5         U R                  (       a%  U R                   H  nUR	                  S5        M     gg)zPause the animation.FN)r  r]  r  r>  set_animatedr)   artists     r   pauseAnimation.pausem  s>     ::--##E* . r   c                     U R                   R                  5         U R                  (       a%  U R                   H  nUR	                  S5        M     gg)zResume the animation.TN)r  r  r  r>  r  r  s     r   resumeAnimation.resumet  s>    !::--##D) . r   )rf  r  rI  r  r  r>  r  r  ry  r  rp  r  r  NF)	NNNNNNNNNr%   )NTN)rG   rH   rI   rJ   rK   r*   r   r  r  r  r  r  r  r  r  r5  r6  r7  rC  r=  r  rZ  r_  rv  r{  r  r  r  rL   r3   r   r   r  r  M  s    B6"&! EIFJ w47;w4r%
$
)&
2B
)+,)H
IHL/\*)X$+*r   r  c                   @   ^  \ rS rSrSr  SU 4S jjrU 4S jrSrU =r$ )TimedAnimationi|  a-  
`Animation` subclass for time-based animation.

A new frame is drawn every *interval* milliseconds.

.. note::

    You must store the created Animation in a variable that lives as long
    as the animation should run. Otherwise, the Animation object will be
    garbage-collected and the animation stops.

Parameters
----------
fig : `~matplotlib.figure.Figure`
    The figure object used to get needed events, such as draw or resize.
interval : int, default: 200
    Delay between frames in milliseconds.
repeat_delay : int, default: 0
    The delay in milliseconds between consecutive animation runs, if
    *repeat* is True.
repeat : bool, default: True
    Whether the animation repeats when the sequence of frames is completed.
blit : bool, default: False
    Whether blitting is used to optimize drawing.
c                    > X l         Ub  UOSU l        X@l        Uc#  UR                  R	                  U R                   S9n[
        TU ]  " U/UQ7SU0UD6  g )Nr   )r  r  )r  _repeat_delayrj  r  	new_timerr   r*   )	r)   r_   r  repeat_delayrepeatr  rz   r{   r   s	           r   r*   TimedAnimation.__init__  s[    !-9-E\1 ::///HLI$I<I&Ir   c                   > [         TU ]  " U6 nU(       d  U R                  (       aA  U R                  5         U R	                  5       U l        U R                  U R                  l        gU R                  5         U R                  (       a/  U R                  R                  R                  U R                  5        U R                  R                  R                  U R                  5        SU l        gU R                   U R                  l        g)zHandler for getting events.TNF)r   r  rj  r  r  r  r  r  r  r  r  r  r  r  r  r  r  )r)   rz   still_goingr   s      r   r  TimedAnimation._step  s     gmT*||!!%!3!3!5-1-?-?!!* 

::II$$33DOOD		  //?$(!%)^^"r   )r  rj  r  r  r  )   r   TN)	rG   rH   rI   rJ   rK   r*   r  rL   r   r   s   @r   r  r  |  s"    2 BF"
J r   r  c                   D   ^  \ rS rSrSrU 4S jrU 4S jrS rS rSr	U =r
$ )ArtistAnimationi  a,  
`TimedAnimation` subclass that creates an animation by using a fixed
set of `.Artist` objects.

Before creating an instance, all plotting should have taken place
and the relevant artists saved.

.. note::

    You must store the created Animation in a variable that lives as long
    as the animation should run. Otherwise, the Animation object will be
    garbage-collected and the animation stops.

Parameters
----------
fig : `~matplotlib.figure.Figure`
    The figure object used to get needed events, such as draw or resize.
artists : list
    Each list entry is a collection of `.Artist` objects that are made
    visible on the corresponding frame.  Other artists are made invisible.
interval : int, default: 200
    Delay between frames in milliseconds.
repeat_delay : int, default: 0
    The delay in milliseconds between consecutive animation runs, if
    *repeat* is True.
repeat : bool, default: True
    Whether the animation repeats when the sequence of frames is completed.
blit : bool, default: False
    Whether blitting is used to optimize drawing.
c                 H   > / U l         X l        [        TU ]  " U/UQ70 UD6  g r%   )r>  r0  r   r*   )r)   r_   rN  rz   r{   r   s        r   r*   ArtistAnimation.__init__  s)      ".t.v.r   c                 ~  > [         TU ]  5         [        5       nU R                  5        Hm  nU Hd  nUR	                  S5        UR                  U R                  5        UR                  5       U;  d  ME  UR                  UR                  5       5        Mf     Mo     U H  nUR                  R                  5         M     g r  )r   r  setr  set_visibler  r  
get_figureaddr  rD  )r)   figsr  r  r_   r   s        r   r  ArtistAnimation._init_draw  s    u##%A""5)##DJJ/$$&d2HHV..01  & CJJ  " r   c                     U(       a  U R                  U R                  5        gU R                   H  nUR                  S5        M     g)z#Clears artists from the last frame.FN)r=  r>  r  )r)   r,  r  r  s       r   r5  ArtistAnimation._pre_draw  s9    T001 --""5) .r   c                 D    Xl         U H  nUR                  S5        M     g r   )r>  r  )r)   rN  r  s      r   r6  ArtistAnimation._draw_frame  s$     & Ft$ r   )r>  r0  )rG   rH   rI   rJ   rK   r*   r  r5  r6  rL   r   r   s   @r   r  r    s!    >/# *% %r   r  c                   Z   ^  \ rS rSrSr  SSS.U 4S jjjrS rS rU 4S jrS	 r	S
r
U =r$ )FuncAnimationi  a  
`TimedAnimation` subclass that makes an animation by repeatedly calling
a function *func*.

.. note::

    You must store the created Animation in a variable that lives as long
    as the animation should run. Otherwise, the Animation object will be
    garbage-collected and the animation stops.

Parameters
----------
fig : `~matplotlib.figure.Figure`
    The figure object used to get needed events, such as draw or resize.

func : callable
    The function to call at each frame.  The first argument will
    be the next value in *frames*.   Any additional positional
    arguments can be supplied using `functools.partial` or via the *fargs*
    parameter.

    The required signature is::

        def func(frame, *fargs) -> iterable_of_artists

    It is often more convenient to provide the arguments using
    `functools.partial`. In this way it is also possible to pass keyword
    arguments. To pass a function with both positional and keyword
    arguments, set all arguments as keyword arguments, just leaving the
    *frame* argument unset::

        def func(frame, art, *, y=None):
            ...

        ani = FuncAnimation(fig, partial(func, art=ln, y='foo'))

    If ``blit == True``, *func* must return an iterable of all artists
    that were modified or created. This information is used by the blitting
    algorithm to determine which parts of the figure have to be updated.
    The return value is unused if ``blit == False`` and may be omitted in
    that case.

frames : iterable, int, generator function, or None, optional
    Source of data to pass *func* and each frame of the animation

    - If an iterable, then simply use the values provided.  If the
      iterable has a length, it will override the *save_count* kwarg.

    - If an integer, then equivalent to passing ``range(frames)``

    - If a generator function, then must have the signature::

         def gen_function() -> obj

    - If *None*, then equivalent to passing ``itertools.count``.

    In all of these cases, the values in *frames* is simply passed through
    to the user-supplied *func* and thus can be of any type.

init_func : callable, optional
    A function used to draw a clear frame. If not given, the results of
    drawing from the first item in the frames sequence will be used. This
    function will be called once before the first frame.

    The required signature is::

        def init_func() -> iterable_of_artists

    If ``blit == True``, *init_func* must return an iterable of artists
    to be re-drawn. This information is used by the blitting algorithm to
    determine which parts of the figure have to be updated.  The return
    value is unused if ``blit == False`` and may be omitted in that case.

fargs : tuple or None, optional
    Additional arguments to pass to each call to *func*. Note: the use of
    `functools.partial` is preferred over *fargs*. See *func* for details.

save_count : int, optional
    Fallback for the number of values from *frames* to cache. This is
    only used if the number of frames cannot be inferred from *frames*,
    i.e. when it's an iterator without length or a generator.

interval : int, default: 200
    Delay between frames in milliseconds.

repeat_delay : int, default: 0
    The delay in milliseconds between consecutive animation runs, if
    *repeat* is True.

repeat : bool, default: True
    Whether the animation repeats when the sequence of frames is completed.

blit : bool, default: False
    Whether blitting is used to optimize drawing.  Note: when using
    blitting, any animated artists will be drawn according to their zorder;
    however, they will be drawn on top of any previous artists, regardless
    of their zorder.

cache_frame_data : bool, default: True
    Whether frame data is cached.  Disabling cache might be helpful when
    frames contain large objects.
T)cache_frame_datac                $  >^ ^ U(       a  UT l         OST l         UT l        UT l        UT l        Tc  [        R
                  T l        O[        T5      (       a  TT l        O[        R                  " T5      (       a  UR                  SS5      (       a  TT l        T4U 4S jjn	U	T l        OU4S jT l        [        TS5      (       a;  [        T5      T l        Ub(  [        R                  " SU< S[        T5      < S	35        O4U4S
 jT l        TT l        Ub  [        R                  " SU< ST< S	35        T R                  c(  U(       a!  [        R                  " ST< SU< S35        SnUT l        / T l        [$        T
T ]L  " U40 UD6  / T l        g )Nr3   r  Tc              3   x   >#    [         R                  " TR                  S5      u  nTl        U S h  vN   g  N7f)Nr   )	itertoolstee	_tee_from)framesthisr)   s     r   iter_frames+FuncAnimation.__init__.<locals>.iter_frames  s(     +4==+K(D$.#OOs   /:8:c                     > [        T 5      $ r%   )r/  r  s   r   r~  (FuncAnimation.__init__.<locals>.<lambda>  s	    fr   __len__z%You passed in an explicit save_count=z0 which is being ignored in favor of len(frames)=.c                  ,   > [        [        T 5      5      $ r%   )r/  ranger  s   r   r~  r    s    T%-%8r   z+ which is being ignored in favor of frames=zframes=ze which we can infer the length of, did not pass an explicit *save_count* and passed cache_frame_data=z.  To avoid a possibly unbounded cache, frame data caching has been disabled. To suppress this warning either pass `cache_frame_data=False` or `save_count=MAX_FRAMES`.F)r   _func
_init_funcr  r  count	_iter_gencallabler   iterabler  r  r   r  r   r   _cache_frame_data	_save_seqr   r*   )r)   r_   funcr  	init_funcfargs
save_countr  r{   r  r   s   `  `      r   r*   FuncAnimation.__init__u  s   DJDJ
#
 & >&__DNf#DN[[  zz(D))!''- $ "-!5vy))#&v; )&&@ZM B(v;.+ 9DN%D%""< >3+1)16 #(86+ 0.0 1GG  %!1 '' r   c                 "    U R                  5       $ r%   )r  r(   s    r   r  FuncAnimation.new_frame_seq  s    ~~r   c                 6  ^ U R                   (       a/  [        U R                   5      U l        [        U R                  5      $ U R                  c  U R                  5       mU4S jnU" 5       $ [        R                  " U R                  5       U R                  5      $ )Nc               3   N   >#      [        T 5      v   M  ! [         a     g f = f7fr%   )r*  r+  )r  s   r   gen.FuncAnimation.new_saved_frame_seq.<locals>.gen  s.     ""&y/1 #( s   % 
"%"%)r  rA   _old_saved_seqr/  r  r  r  islice)r)   r  r  s     @r   r  !FuncAnimation.new_saved_frame_seq  sz     >> #'t~~"6D++,,' ..0	 u ''(:(:(<d>N>NOOr   c                   > [         TU ]  5         U R                  c,   [        U R	                  5       5      nU R                  U5        OlU R                  5       U l	        U R                  (       aF  U R                  c  [        S5      eU R                   H  nUR                  U R                  5        M      / U l        g ! [
         a    [        R                  " S5         g f = f)NzCan not start iterating the frames for the initial draw. This can be caused by passing in a 0 length sequence for *frames*.

If you passed *frames* as a generator it may be exhausted due to a previous display or save.z7The init_func must return a sequence of Artist objects.)r   r  r  r*  r  r+  r  r  r6  r>  r  rD   r  r  )r)   r  r
  r   s      r   r  FuncAnimation._init_draw  s    
 ??"!$"4"4"67
 Z("&//"3Dzz&&.& (E F F,,ANN4::. -+ !  M s   B= = C C c                 r   U R                   (       a:  U R                  R                  U5        U R                  U R                  * S  U l        U R                  " U/U R
                  Q76 U l        U R                  (       a  [        S5      n [        U R                  5        U R                   H.  n[        U[        R                  R                  5      (       a  M.  Ue   [        U R                  S S9U l        U R                   H  nUR!                  U R                  5        M      g g ! [         a    US ef = f)Nz@The animation function must return a sequence of Artist objects.c                 "    U R                  5       $ r%   )
get_zorder)r   s    r   r~  +FuncAnimation._draw_frame.<locals>.<lambda>  s
    q||~r   )key)r  r  r   r  r  r   r>  r  rD   r/  r   r  rT   r  Artistsortedr  )r)   r,  r   r  r
  s        r   r6  FuncAnimation._draw_frame  s   !!NN!!),!^^T-=-=,=,>?DN #jj@TZZ@::  4 5C$T(()
 ((!!SZZ%6%677I ) #))<)<-E#GD ((tzz* )%   $t#$s   D( (D6)
r   r  r>  r  r  r  r  r  r  r  )NNNN)rG   rH   rI   rJ   rK   r*   r  r  r  r6  rL   r   r   s   @r   r  r    sE    eL FJ C6:C CJ P.@+ +r   r  c                     [         R                  S   S:X  a!  [        S[         R                  S   < S35      eS H  nX;   d  M
  [        SU< 35      e   g )Nrt   ru   zmpl.rcParams['savefig.bbox']=z^ must not be 'tight' as it may cause frame size to vary, which is inappropriate for animation.)r   r  r   z.grab_frame got an unexpected keyword argument )rT   rv   
ValueErrorr   )rk   rG  s     r   r   r     sf    
||N#w.,s||N+- .R R
 	
 .@F  .r   )>r   r  r   ior   r   r  r   pathlibr   r   r   systempfiler   r  r  numpyr   PILr   
matplotlibrT   matplotlib._animation_datar   r	   r
   r   r   r   matplotlib.colorscolorsr  	getLoggerrG   rw   platformCREATE_NO_WINDOWr   r    r"   r  ABCrN   r   r   r4   r   r  rM  rZ  ra  rx  r|  r  r  r  r  r  r  r  r   r3   r   r   <module>r     s   
   %      
 '     B B " #"
 $'<<7#:J !JH5L 5Lp 
c#'' cLN8% N8bd'k d'N 	(3& 3 3F:+ :+| 	(:{  6 	-  ;z?  ; ! ;H. .d 	-   ! 	$%
AO_ 
A &
A=4 	&i# i# i#Xl* l*^BY BJJ%n J%ZD+N D+N
r   