
    MhC                     v   U d Z ddlmZ ddlmZ ddlmZ ddlZddlm	Z	 ddl
mZ i dd	d
dddddddddddddddddddddddd d d!d!d"d"d#d#d$d%d%d&Z e ee                                e                                                    Zd
xed'<   ed(<   ded)<   ded*<   ded+<   ded,<   ded<   ded<   ded<   ed= ed = ed!= ed"= ed#= ed$= ed%= d- Zd. Zd/ ZdCd3ZdDd4Zd5 Zd6 Zd7 ZdEd8Zd9 ZdFd;Zdaedz  ed<<   d=efd>Z d=e!e"         fd?Z#d@e"dz  d=e"dz  fdAZ$d@e"dz  d=e"dz  fdBZ%dS )Gz%Pylab (matplotlib) support utilities.    )BytesIO)
b2a_base64)partialN)_pngxy)
flag_callstkTkAgggtkGTKAgggtk3GTK3Agggtk4GTK4AggwxWXAggqt4Qt4Aggqt5Qt5Aggqt6QtAggqtosxMacOSXnbaggnbAggwebaggWebAggnotebookaggsvgpdfpsz)module://matplotlib_inline.backend_inlinemodule://ipympl.backend_nbagg)inlineipymplwidgetGTKGTKCairo	GTK3Cairo	GTK4CairoWXCocoaAggc                     | dv r4t          j        |  dt                     t                      d|           S t	          dt
          d|           )N)backendsbackend2guizg is deprecated since IPython 8.24, backends are managed in matplotlib and can be externally registered._deprecated_zmodule z has no attribute )warningswarnDeprecationWarningglobalsAttributeError__name__)names    W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/core/pylabtools.py__getattr__r:   K   sp    *** > > >	
 	
 	

 yy...//
I8IIII
J
JJ    c                      ddl m} | s |                                }d |D             S g }| D ]P}|j                            |          }|t          d|z             1|                    |j        j                   Q|S )a  Get a list of matplotlib figures by figure numbers.

    If no arguments are given, all available figures are returned.  If the
    argument list contains references to invalid figures, a warning is printed
    but the function continues pasting further figures.

    Parameters
    ----------
    figs : tuple
        A tuple of ints giving the figure numbers of the figures to return.
    r   )Gcfc                 &    g | ]}|j         j        S  )canvasfigure).0fms     r9   
<listcomp>zgetfigs.<locals>.<listcomp>j   s    888R	 888r;   Nz!Warning: figure %s not available.)	matplotlib._pylab_helpersr=   get_all_fig_managersfigsgetprintappendr@   rA   )fig_numsr=   fig_managersrG   numfs         r9   getfigsrO   [   s     .----- //1188<8888 	- 	-CS!!Ay9C?@@@@AHO,,,,r;   c                 &    ddl }| |g|j        d<   dS )zSet the default figure size to be [sizex, sizey].

    This is just an easy to remember, convenience wrapper that sets::

      matplotlib.rcParams['figure.figsize'] = [sizex, sizey]
    r   Nzfigure.figsize)
matplotlibrcParams)sizexsizeyrQ   s      r9   figsizerU   v   s(     -2ENJ()))r;   pngtightFc                    | j         s	| j        sdS | j        }|dk    r|dz  }d}||                                 |                                 ||d}|                    |           t                      }| j        ddlm	}  ||             | j        j
        |fi | |                                }	|dk    r|	                    d	          }	n&|r$t          |	d
                              d          }	|	S )a  Print a figure to an image, and return the resulting file data

    Returned data will be bytes unless ``fmt='svg'``,
    in which case it will be unicode.

    Any keyword args are passed to fig.canvas.print_figure,
    such as ``quality`` or ``bbox_inches``.

    If `base64` is True, return base64-encoded str instead of raw bytes
    for binary-encoded image formats

    .. versionadded:: 7.29
        base64 argument
    Nretina   rV   )format	facecolor	edgecolordpibbox_inchesr   )FigureCanvasBaser!   zutf-8Fnewlineascii)axeslinesr^   get_facecolorget_edgecolorupdater   r@   matplotlib.backend_basesr`   print_figuregetvaluedecoder   )
figfmtr_   base64kwargsr^   kwbytes_ior`   datas
             r9   rj   rj      s.   " 8 CI 
'C
hAg %%''%%''!
 
B IIfyyH
z======CJH+++++D
e||{{7##	 ?$...55g>>Kr;   c                     t          | fddd|}|dS t          |          \  }}|dz  |dz  d}|r$t          |d                              d          }||fS )	zformat a figure as a pixel-doubled (retina) PNG

    If `base64` is True, return base64-encoded str instead of raw bytes
    for binary-encoded image formats

    .. versionadded:: 7.29
        base64 argument
    rY   Frn   ro   NrZ   )widthheightra   rc   )rj   r   r   rl   )rm   ro   rp   pngdatawhmetadatas          r9   retina_figurer|      s     3EHUEEfEEG '??DAqA1--H EWe444;;GDDHr;   c                       fd}|S )a\  Factory to return a matplotlib-enabled runner for %run.

    Parameters
    ----------
    safe_execfile : function
        This must be a function with the same interface as the
        :meth:`safe_execfile` method of IPython.

    Returns
    -------
    A function suitable for use as the ``runner`` argument of the %run magic
    function.
    c                    ddl }ddlm} |                    ddi          5   | g|R i | ddd           n# 1 swxY w Y   |                                r|                                 |j        j        r |                                 d|j        _        	 |j	        } |             dS # t          $ r Y dS w xY w)zmatplotlib-aware wrapper around safe_execfile.

        Its interface is identical to that of the :func:`execfile` builtin.

        This is ultimately a call to execfile(), but wrapped in safeties to
        properly handle interactive rendering.r   NinteractiveF)rQ   matplotlib.pyplotpyplot
rc_contextis_interactiveshowdraw_if_interactivecalleddrawdraw_allr6   )fnamewhererq   rQ   pltdasafe_execfiles         r9   mpl_execfilez mpl_runner.<locals>.mpl_execfile   s?    	'''''' ""M5#9:: 	/ 	/M%.%...2...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ $$&& 	HHJJJ ") 	3HHJJJ-2C#*	B BDDDDD  	 	 	DD	s!   <A A B/ /
B=<B=r?   )r   r   s   ` r9   
mpl_runnerr      s%        @ r;   c                     	 | j         j        j        } |             dS # t          $ r}t	                      |d}~ww xY w)zreshow an nbagg figureN)r@   managerreshowr6   NotImplementedError)rm   r   es      r9   _reshow_nbagg_figurer      sT    #* 	  + + +!##*+s    
=8=c           	         ddl }ddlm | j        j        d         }| j        j        d         }| j        j        d         }| j        j        d         }t          |t                    r|h}t          |          }fd| j        j                                        D              |	                                
                                }|d	v r'| j        j        }	|	                    t                     h d
}
|                    |
          }|rYdd                    d |D                       z  }dd                    d |
D                       z  }t!          d|d|          d|v r)|                    t#          t$          fddd|           d|v sd|v r(|                    t#          t&          fddi|           d|v sd|v r)|                    t#          t$          fddd|           d|v r(|                    t#          t$          fddi|           d|v r+|                    t#          t$          fddd|           dS dS )a_  Select figure formats for the inline backend.

    Parameters
    ----------
    shell : InteractiveShell
        The main IPython instance.
    formats : str or set
        One or a set of figure formats to enable: 'png', 'retina', 'jpeg', 'svg', 'pdf'.
    **kwargs : any
        Extra keyword arguments to be passed to fig.canvas.print_figure.
    r   N)Figurezimage/svg+xmlz	image/pngz
image/jpegzapplication/pdfc                 <    g | ]}|                     d           S )N)pop)rB   rN   r   s     r9   rD   z)select_figure_formats.<locals>.<listcomp>  s'    PPPaaeeFDPPPr;   )r   r&   r'   r$   >   jpgr"   rV   r!   jpegpng2xrY   z%s,c                 ,    g | ]}t          |          S r?   reprrB   rN   s     r9   rD   z)select_figure_formats.<locals>.<listcomp>'  s    333!d1gg333r;   c                 ,    g | ]}t          |          S r?   r   r   s     r9   rD   z)select_figure_formats.<locals>.<listcomp>(  s    999!d1gg999r;   zsupported formats are: z not rV   Tru   rY   r   ro   r   r   r!   rn   r"   )rQ   matplotlib.figurer   display_formatter
formatters
isinstancestrsetvaluesget_backendloweripython_display_formatterfor_typer   
differencejoin
ValueErrorr   rj   r|   )shellformatsrp   rQ   svg_formatterpng_formatterjpg_formatterpdf_formatter
mplbackend	formatter	supportedbadbsgsr   s                 @r9   select_figure_formatsr     s    ((((((+6GM+6{CM+6|DM+67HIM'3 )'llGPPPP5#:#E#L#L#N#NPPPP''))//11JSSS+E	6#7888GGGI


Y
'
'C
 HCHH33s333444CHH99y999:::jrrr22FGGGGLKeDKKFKK	
 	
 	
 7g00vw}'T'TT'TV'T'TUUU6W,,GLKeDKKFKK	
 	
 	
 vw|'Q'Q'Q&'Q'QRRRGLKeDKKFKK	
 	
 	
 	
 	
 r;   c                 6   ddl }t                      ru|j        j        j        }| dv r&|j        d         }|                    |          \  }} n't          |           } |                    |           \  }} t          |           } | |fS t          |dd          }|dk    }ddlm} t          |          }|sd	|d
<   | r| dk    r||          }| dk    rd} n;|j        d         }ddlm}	 |	                    |d          } |r| |k    r
|} ||          }| dk    rd} | |fS )a  Given a gui string return the gui and mpl backend.

    Parameters
    ----------
    gui : str
        Can be one of ('tk','gtk','wx','qt','qt4','inline','agg').
    gui_select : str
        Can be one of ('tk','gtk','wx','qt','qt4','inline').
        This is any gui already selected by the shell.

    Returns
    -------
    A tuple of (gui, backend) where backend is one of ('TkAgg','GTKAgg',
    'WXAgg','Qt4Agg','module://matplotlib_inline.backend_inline','agg').
    r   N)autoNbackend__version_info__)r   r   )      )r/   qt5aggr   r   r    )r0   r%   )rQ   _matplotlib_manages_backendsr/   registrybackend_registryrcParamsOrigresolve_backend_convert_gui_to_matplotlibresolve_gui_or_backend_convert_gui_from_matplotlibgetattrIPython.core.pylabtoolsdictr0   rH   )
gui
gui_selectrQ   r   r   mpl_version_infohas_unified_qt_backendr/   	backends_r0   s
             r9   find_gui_and_backendr   A  s   " #%% %.7H .   -i8G+;;GDDLGSS,S11C+BB3GGLGS*3//G| z+=vFF-7000000XI! #"	$
 %sf}}C.%<<C ))4 	877777oogt,,  	%#++CnG h<r;   c                     ddl }|                    d           | |j        d<   ddl m} |                    |            d|j        _        t          |j                  |_        dS )z7Activate the given backend and set interactive to True.r   NTr   )r   F)	rQ   r   rR   r   switch_backendr   	_needmainr   r   )r   rQ   r   s      r9   activate_matplotlibr     s     4   
 &-J	"
 )(((((wCH ))@AACr;   Tc                     d}t          ||            |rd}t          ||            t          | d<   ddlm} || d<   t          | d<   dS )	zPopulate the namespace with pylab-related values.

    Imports matplotlib, pylab, numpy, and everything from pylab and numpy.

    Also imports a few names from IPython (figsize, display, getfigs)

    zbimport numpy
import matplotlib
from matplotlib import pylab, mlab, pyplot
np = numpy
plt = pyplot
z3from matplotlib.pylab import *
from numpy import *
rU   r   )displayr   rO   N)execrU   IPython.displayr   rO   )user_ns
import_allsr   s       r9   import_pylabr     sr    
A 	G %Q !GI'''''' GI GIr;   "_matplotlib_manages_backends_valuereturnc                  r    t           *	 ddlm}  t          | d          a n# t          $ r da Y nw xY wt           S )a  Return True if Matplotlib manages backends, False otherwise.

    If it returns True, the caller can be sure that
    matplotlib.backends.registry.backend_registry is available along with
    member functions resolve_gui_or_backend, resolve_backend, list_all, and
    list_gui_frameworks.

    This function can be removed as it will always return True when Python
    3.12, the latest version supported by Matplotlib < 3.9, reaches
    end-of-life in late 2028.
    Nr   r   r   F)r   matplotlib.backends.registryr   hasattrImportErrorr   s    r9   r   r     sk     *1	7EEEEEE18 ":2 2..  	7 	7 	716...	7 .-s     //c                     t                      r:ddlm}  |                                 d |                                 D             z   }n,ddlm} t          |j        	                                          }t          dg|z             S )z}Return list of all Matplotlib backends and GUI event loops.

    This is the list returned by
        %matplotlib --list
    r   r   c                 ,    g | ]}t          |          S r?   )r   )rB   r   s     r9   rD   z;_list_matplotlib_backends_and_gui_loops.<locals>.<listcomp>  s0     -
 -
 -
 )---
 -
 -
r;   )
pylabtoolsr   )r   r   r   list_alllist_gui_frameworksIPython.corer   listr/   keyssorted)r   retr   s      r9   '_list_matplotlib_backends_and_gui_loopsr     s     $%% 
/AAAAAA'')) -
 -
';;==-
 -
 -
 

 	,+++++:&++--..6(S.!!!r;   r   c                 >    | r|                                  dk    rdS | S )Nr   macosxr   r   s    r9   r   r     s&    
 syy{{e##xJr;   c                 >    | r|                                  dk    rdS | S )Nr   r   r   r   s    r9   r   r      s&    
 syy{{h&&uJr;   )rV   rW   F)F)NN)T)&__doc__ior   binasciir   	functoolsr   r2   IPython.core.displayr   IPython.utils.decoratorsr   _deprecated_backendsr   zipr   r   _deprecated_backend2guir:   rO   rU   rj   r|   r   r   r   r   r   r   r   bool__annotations__r   r   r   r   r   r   r?   r;   r9   <module>r     s   + + +
                    ' ' ' ' ' ' / / / / / /'	8 I I	
 	' 
8 
8 
7 	' 
8 W h  
5 
5  
5!" 	$#$ :--)   6 $C##%%';'@'@'B'BCC  
 HM L  !8!D'-  $'-  $ $  &+ 
 # $(   $)  !$)  ! G$E"E"E"D!GH;<K K K   6; ; ;/ / / /b   ./ / /d  5
 5
 5
xF F F FRB B B0! ! ! !F 37 "D4K 6 6 6.d . . . .4"c " " " "0C$J 3:    cDj S4Z      r;   