o
    i6                     @   s  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dGd4d5ZdHd6d7Zd8d9 Zd:d; Zd<d= ZdId>d?Zd@dA ZdJdCdDZdEdF ZdS )Kz%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                  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  )canvasfigure).0fmr.   r.   R/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/IPython/core/pylabtools.py
<listcomp>X       zgetfigs.<locals>.<listcomp>Nz!Warning: figure %s not available.)	matplotlib._pylab_helpersr-   get_all_fig_managersfigsgetprintappendr/   r0   )fig_numsr-   fig_managersr8   numfr.   r.   r3   getfigsI   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)sizexsizeyrA   r.   r.   r3   figsized   s   rE   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   rF   )format	facecolor	edgecolordpibbox_inchesr   )FigureCanvasBaser    zutf-8Fnewlineascii)axeslinesrM   get_facecolorget_edgecolorupdater   r/   matplotlib.backend_basesrO   print_figuregetvaluedecoder   )
figfmtrN   base64kwargsrM   kwbytes_iorO   datar.   r.   r3   rY   o   s2   


rY   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
    rH   Fr]   r^   NrI   )widthheightrP   rR   )rY   r   r   r[   )r\   r^   r_   pngdatawhmetadatar.   r.   r3   retina_figure   s   	rj   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} |jd }|d  | g|R i | || |jjr0|  d|j_z|j}W n
 t	y?   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)
rA   matplotlib.pyplotpyplotrB   rk   draw_if_interactivecalleddrawdraw_allAttributeError)fnamewherer`   rA   pltis_interactivedasafe_execfiler.   r3   mpl_execfile   s   




z mpl_runner.<locals>.mpl_execfiler.   )ry   rz   r.   rx   r3   
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reshowrr   NotImplementedError)r\   r}   er.   r.   r3   _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
ksI|dkrS| jj}	|	 t h d}
||
}|r~d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r1   r?   r   r.   r3   r4   
  s    z)select_figure_formats.<locals>.<listcomp>r   r#   >   jpgr!   rF   r    jpegpng2xrH   z%s,c                 S      g | ]}t |qS r.   reprr   r.   r.   r3   r4     r5   c                 S   r   r.   r   r   r.   r.   r3   r4     r5   z supported formats are: %s not %srF   Trc   rH   r   r^   r   r   r    r]   r!   )rA   matplotlib.figurer   display_formatter
formatters
isinstancestrsetvaluesget_backendloweripython_display_formatterfor_typer   
differencejoin
ValueErrorr   rY   rj   )shellformatsr_   rA   svg_formatterpng_formatterjpg_formatterpdf_formatter
mplbackend	formatter	supportedbadbsgsr.   r   r3   select_figure_formats   sJ   

r   c                 C   sf   ddl }| r| dkrt|  }| dkrd} | |fS |jd }t|d} |r/| |kr/|} t|  }| |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autor   backend)rA   backendsrcParamsOrigbackend2guir9   )gui
gui_selectrA   r   r.   r.   r3   find_gui_and_backend-  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)	rA   rk   rB   rm   switch_backendshow	_needmainr   rn   )r   rA   ru   r.   r.   r3   activate_matplotlibX  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 *
rE   r   )displayr   r@   N)execrE   IPython.displayr   r@   )user_ns
import_allsr   r.   r.   r3   import_pylabp  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()`rI   )
stacklevelr   )configure_inline_supportN)warningswarnDeprecationWarning matplotlib_inline.backend_inliner   )r   r   configure_inline_support_origr.   r.   r3   r     s   r   )rF   rG   F)F)NN)T)__doc__ior   binasciir   	functoolsr   r   IPython.core.displayr   IPython.utils.decoratorsr   r   dictzipr   keysr   r@   rE   rY   rj   r{   r   r   r   r   r   r   r.   r.   r.   r3   <module>   s   	


10

<+
!