o
    û›h¾F  ã                   @   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   úMc:\Users\shubh\Videos\agent\nova\Lib\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 )z»Set 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 )	zÖformat 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 )z÷matplotlib-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 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                    s   g | ]}|  ˆ d ¡‘qS )N)Úpop©r!   r*   r_   r   r   r#     s    z)select_figure_formats.<locals>.<listcomp>)r	   r   r   r   >   r   Úpng2xr1   ÚjpegÚjpgr   r/   z%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   rc   rA   re   rd   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 )	zÊPopulate 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
!