o
    ZhF                     @   s  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
 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-d. Zd/d0 Zd1d2 ZdTd6d7ZdUd8d9Zd:d; Zd<d= Zd>d? ZdVd@dAZdBdC ZdWdEdFZdGdH ZdaedB e dI< dJefdKdLZ!dJe"e# fdMdNZ$dOe#dB dJe#dB fdPdQZ%dOe#dB dJe#dB fdRdSZ&dS )Xz%Pylab (matplotlib) support utilities.    )BytesIO)
b2a_base64)partialN)_pngxy)
flag_callsZtkZTkAggZgtkZGTKAggZgtk3ZGTK3AggZgtk4ZGTK4AggZwxZWXAggZqt4ZQt4AggZqt5ZQt5AggZqt6ZQtAggqtosxZMacOSXnbaggZnbAggZwebaggZWebAggnotebookaggsvgpdfZpsz)module://matplotlib_inline.backend_inlinemodule://ipympl.backend_nbagg)inlineipymplwidgetZGTKZGTKCairoZ	GTK3CairoZ	GTK4CairoZWXZCocoaAggc                 C   s>   | dv rt |  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.Z_deprecated_zmodule z has no attribute )warningswarnDeprecationWarningglobalsAttributeError__name__)name r   N/var/www/html/lang_env/lib/python3.10/site-packages/IPython/core/pylabtools.py__getattr__K   s   r   c                  G   sh   ddl m} | s| }dd |D S g }| D ]}|j|}|du r*td|  q||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                 S   s   g | ]}|j jqS r   )canvasfigure).0fmr   r   r   
<listcomp>j       zgetfigs.<locals>.<listcomp>Nz!Warning: figure %s not available.)	Zmatplotlib._pylab_helpersr   Zget_all_fig_managersfigsgetprintappendr   r    )Zfig_numsr   Zfig_managersr%   numfr   r   r   getfigs[   s   r+   c                 C   s   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)ZsizexZsizeyr,   r   r   r   figsizev   s   r.   pngtightFc           
      K   s   | j s| jsdS | j}|dkr|d }d}||  |  ||d}|| t }| jdu r8ddlm	} ||  | jj
|fi | | }	|dkrQ|	d	}	|	S |r\t|	d
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   r/   )formatZ	facecolorZ	edgecolordpibbox_inchesr   )FigureCanvasBaser   zutf-8Fnewlineascii)Zaxeslinesr4   Zget_facecolorZget_edgecolorupdater   r   Zmatplotlib.backend_basesr6   print_figuregetvaluedecoder   )
figfmtr5   base64kwargsr4   kwZbytes_ior6   datar   r   r   r<      s2   


r<   c                 K   s^   t | fddd|}|du rdS t|\}}|d |d d}|r+t|d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
    r1   Fr@   rA   Nr2   )widthheightr7   r9   )r<   r   r   r>   )r?   rA   rB   Zpngdatawhmetadatar   r   r   retina_figure   s   	rK   c                    s    fd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                    s   ddl }ddlm} |ddi  | g|R i | W d   n1 s'w   Y  | r4|  |jjr@|  d|j_z|j	}W n
 t
yO   Y dS w |  dS )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)r,   Zmatplotlib.pyplotpyplotZ
rc_contextis_interactiveshowdraw_if_interactivecalledZdrawZdraw_allr   )fnamewhererC   r,   pltdasafe_execfiler   r   mpl_execfile   s    

z mpl_runner.<locals>.mpl_execfiler   )rW   rX   r   rV   r   
mpl_runner   s    rY   c              
   C   s:   z| j jj}W n ty } zt |d}~ww |  dS )zreshow an nbagg figureN)r   managerreshowr   NotImplementedError)r?   r[   er   r   r   _reshow_nbagg_figure   s   
r^   c                    s  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d	| jj D  |	 
 }|d
v rO| jj}	|	 t h d}
||
}|rzdddd	 |D  }dddd	 |
D  }td||f d|v r| ttfddd| d|v sd|v r| ttfddi| d|v sd|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                    s   g | ]}|  d qS )N)popr!   r*   r_   r   r   r#     s    z)select_figure_formats.<locals>.<listcomp>)r	   r   r   r   >   jpegr   r/   r   jpgr1   png2xz%s,c                 S      g | ]}t |qS r   reprrb   r   r   r   r#   '  r$   c                 S   rg   r   rh   rb   r   r   r   r#   (  r$   z supported formats are: %s not %sr/   TrE   r1   re   rA   rd   rc   r   r@   r   )r,   Zmatplotlib.figurer`   display_formatter
formatters
isinstancestrsetvaluesget_backendlowerZipython_display_formatterZfor_typer^   
differencejoin
ValueErrorr   r<   rK   )shellformatsrB   r,   Zsvg_formatterZpng_formatterZjpg_formatterZpdf_formatterZ
mplbackend	formatter	supportedbadbsgsr   r_   r   select_figure_formats  sJ   

r|   c           
      C   s  ddl }t r0|jjj}| dv r|jd }||\}} nt| } || \}} t	| } | |fS t
|dd}|dk}ddlm} t|}|sJd	|d
< | r[| dkr[||  }| dkrZd} n|jd }ddlm}	 |	|d} |rx| |krx|} ||  }| 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   Zqt5aggr   r}   r   )r   r   )r,   _matplotlib_manages_backendsr   registrybackend_registryZrcParamsOrigZresolve_backend_convert_gui_to_matplotlibresolve_gui_or_backend_convert_gui_from_matplotlibgetattrZIPython.core.pylabtoolsdictr   r&   )
guiZ
gui_selectr,   r   r~   Zmpl_version_infoZhas_unified_qt_backendr   Z	backends_r   r   r   r   find_gui_and_backendA  s<   


r   c                 C   sJ   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~   )rM   F)	r,   rL   r-   rM   Zswitch_backendrO   Z	_needmainr   rP   )r~   r,   rT   r   r   r   activate_matplotlib  s   


r   Tc                 C   sH   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 *
r.   r   )displayr   r+   N)execr.   IPython.displayr   r+   )Zuser_nsZ
import_allsr   r   r   r   import_pylab  s   

r   c                 C   s*   t jdtdd ddlm} || | dS )a
  
    .. deprecated:: 7.23

        use `matplotlib_inline.backend_inline.configure_inline_support()`

    Configure an IPython shell object for matplotlib use.

    Parameters
    ----------
    shell : InteractiveShell instance
    backend : matplotlib backend
    z`configure_inline_support` is deprecated since IPython 7.23, directly use `matplotlib_inline.backend_inline.configure_inline_support()`r2   )
stacklevelr   )configure_inline_supportN)r   r   r   Z matplotlib_inline.backend_inliner   )ru   r~   Zconfigure_inline_support_origr   r   r   r     s   r   "_matplotlib_manages_backends_valuereturnc                  C   sB   t du rzddlm}  t| da W t S  ty   da Y t S 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   r   r   r   r     s   r   c                  C   sV   t  rddlm}  |  dd |  D  }nddlm} t|j	 }t
dg| S )z}Return list of all Matplotlib backends and GUI event loops.

    This is the list returned by
        %matplotlib --list
    r   r   c                 S   rg   r   )r   )r!   r   r   r   r   r#     s    z;_list_matplotlib_backends_and_gui_loops.<locals>.<listcomp>)
pylabtoolsr}   )r   r   r   Zlist_allZlist_gui_frameworksZIPython.corer   listr   keyssorted)r   retr   r   r   r   '_list_matplotlib_backends_and_gui_loops  s   
r   r   c                 C      | r
|   dkr
dS | S )Nr   macosxrq   r   r   r   r   r        r   c                 C   r   )Nr   r   r   r   r   r   r   r     r   r   )r/   r0   F)F)NN)T)'__doc__ior   binasciir   	functoolsr   r   ZIPython.core.displayr   ZIPython.utils.decoratorsr   Z_deprecated_backendsr   zipro   r   Z_deprecated_backend2guir   r+   r.   r<   rK   rY   r^   r|   r   r   r   r   r   bool__annotations__r   r   rm   r   r   r   r   r   r   r   <module>   s   	


12

<I
!