o
    ĎiF                     @   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_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                 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._deprecated_zmodule z has no attribute )warningswarnDeprecationWarningglobalsAttributeError__name__)name r7   S/home/jeff/fluffinator/venv/lib/python3.10/site-packages/IPython/core/pylabtools.py__getattr__K   s   r9   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 r7   )canvasfigure).0fmr7   r7   r8   
<listcomp>j       zgetfigs.<locals>.<listcomp>Nz!Warning: figure %s not available.)	matplotlib._pylab_helpersr:   get_all_fig_managersfigsgetprintappendr;   r<   )fig_numsr:   fig_managersrC   numfr7   r7   r8   getfigs[   s   rK   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)sizexsizeyrL   r7   r7   r8   figsizev   s   rP   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   rQ   )format	facecolor	edgecolordpibbox_inchesr   )FigureCanvasBaser    zutf-8Fnewlineascii)axeslinesrX   get_facecolorget_edgecolorupdater   r;   matplotlib.backend_basesrZ   print_figuregetvaluedecoder   )
figfmtrY   base64kwargsrX   kwbytes_iorZ   datar7   r7   r8   rd      s2   


rd   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
    rS   Frh   ri   NrT   )widthheightr[   r]   )rd   r   r   rf   )rg   ri   rj   pngdatawhmetadatar7   r7   r8   retina_figure   s   	ru   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)rL   matplotlib.pyplotpyplot
rc_contextis_interactiveshowdraw_if_interactivecalleddrawdraw_allr4   )fnamewhererk   rL   pltdasafe_execfiler7   r8   mpl_execfile   s    

z mpl_runner.<locals>.mpl_execfiler7   )r   r   r7   r   r8   
mpl_runner   s    r   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reshowr4   NotImplementedError)rg   r   er7   r7   r8   _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=   rJ   r   r7   r8   r?     s    z)select_figure_formats.<locals>.<listcomp>)r   r%   r&   r#   >   jpgr!   rQ   r    jpegpng2xrS   z%s,c                 S      g | ]}t |qS r7   reprr   r7   r7   r8   r?   '  r@   c                 S   r   r7   r   r   r7   r7   r8   r?   (  r@   z supported formats are: %s not %srQ   Trn   rS   r   ri   r   r   r    rh   r!   )rL   matplotlib.figurer   display_formatter
formatters
isinstancestrsetvaluesget_backendloweripython_display_formatterfor_typer   
differencejoin
ValueErrorr   rd   ru   )shellformatsrj   rL   svg_formatterpng_formatterjpg_formatterpdf_formatter
mplbackend	formatter	supportedbadbsgsr7   r   r8   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-   qt5aggr   r   r   )r.   r$   )rL   _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dictr.   rD   )
gui
gui_selectrL   r   r   mpl_version_infohas_unified_qt_backendr-   	backends_r.   r7   r7   r8   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   )rx   F)	rL   rv   rM   rx   switch_backendr{   	_needmainr   r|   )r   rL   r   r7   r7   r8   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 *
rP   r   )displayr   rK   N)execrP   IPython.displayr   rK   )user_ns
import_allsr   r7   r7   r8   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()`rT   )
stacklevelr   )configure_inline_supportN)r0   r1   r2    matplotlib_inline.backend_inliner   )r   r   configure_inline_support_origr7   r7   r8   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   r7   r7   r8   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   r   r7   )r   )r=   r   r7   r7   r8   r?     s    z;_list_matplotlib_backends_and_gui_loops.<locals>.<listcomp>)
pylabtoolsr   )r   r   r   list_alllist_gui_frameworksIPython.corer   listr-   keyssorted)r   retr   r7   r7   r8   '_list_matplotlib_backends_and_gui_loops  s   
r   r   c                 C      | r
|   dkr
dS | S )Nr   macosxr   r   r7   r7   r8   r        r   c                 C   r   )Nr   r   r   r   r7   r7   r8   r     r   r   )rQ   rR   F)F)NN)T)'__doc__ior   binasciir   	functoolsr   r0   IPython.core.displayr   IPython.utils.decoratorsr   _deprecated_backendsr   zipr   r   _deprecated_backend2guir9   rK   rP   rd   ru   r   r   r   r   r   r   r   r   bool__annotations__r   r   r   r   r   r   r7   r7   r7   r8   <module>   s   	


12

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