
    f6                        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j                         ej!                                     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d8d/Zd9d0Zd1 Zd2 Zd3 Zd:d4Zd5 Zd;d6Zd7 Zy)<z%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dl m} | s4|j                         }|D cg c]  }|j                  j                   c}S g }| D ]S  }|j
                  j                  |      }|t        d|z         /|j                  |j                  j                         U |S c c}w )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   )Gcfz!Warning: figure %s not available.)	matplotlib._pylab_helpersr/   get_all_fig_managerscanvasfigurefigsgetprintappend)fig_numsr/   fig_managersfmr4   numfs          R/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/core/pylabtools.pygetfigsr>   I   s     .//1+78R		  88 	-CS!Ay9C?@AHHOO,	-  9s   Bc                 .    ddl }| |g|j                  d<   y)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sizeyr@   s      r=   figsizerD   d   s     -2ENJ()    c                    | j                   s| j                  sy| j                  }|dk(  r|dz  }d}|| j                         | j	                         ||d}|j                  |       t               }| j                  ddlm	}  ||         | j                  j                  |fi | |j                         }	|dk(  r|	j                  d	      }	|	S |rt        |	d
      j                  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   png)format	facecolor	edgecolordpibbox_inchesr   )FigureCanvasBaser!   zutf-8Fnewlineascii)axeslinesrM   get_facecolorget_edgecolorupdater   r2   matplotlib.backend_basesrO   print_figuregetvaluedecoder   )
figfmtrN   base64kwargsrM   kwbytes_iorO   datas
             r=   rY   rY   o   s    " 88CII
''C
hAg %%'%%'!
B IIfyH
zz=CJJH++D
e|{{7# K 
$.55g>KrE   c                     t        | fddd|}|yt        |      \  }}|dz  |dz  d}|rt        |d      j                  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
    rG   Fr]   r^   NrH   )widthheightrP   rR   )rY   r   r   r[   )r\   r^   r_   pngdatawhmetadatas          r=   retina_figurerk      sh     3EHUEfEG '?DAqA1-HWe4;;GDHrE   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                 H   ddl }ddlm} |j                  d   }|j	                  d        | g|i | |j	                  |       |j
                  j                  r!|j                          d|j
                  _        	 |j                  } |        y# t        $ r Y y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)
r@   matplotlib.pyplotpyplotrA   rn   draw_if_interactivecalleddrawdraw_allAttributeError)fnamewherer`   r@   pltis_interactivedasafe_execfiles          r=   mpl_execfilez mpl_runner.<locals>.mpl_execfile   s     	' $,,];u%e(U(R(~.""))HHJ-2C##*	B D  		s   B 	B! B! )r{   r|   s   ` r=   
mpl_runnerr~      s    < rE   c                     	 | j                   j                  j                  } |        y# t        $ r}t	               |d}~ww xY w)zreshow an nbagg figureN)r2   managerreshowru   NotImplementedError)r\   r   es      r=   _reshow_nbagg_figurer      s@    ##** 	  +!#*+s    * 	A>A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        |      }| j                  j                  j                         D 	cg c]  }	|	j                  |d       c}	 |j                         j                         }
|
dk(  s|
d	k(  r,| j                  j                  }|j                  |t               h d
}|j                  |      }|rgddj!                  |D 	cg c]  }	t#        |	       c}	      z  }ddj!                  |D 	cg c]  }	t#        |	       c}	      z  }t%        d|d|      d|v r#|j                  |t'        t(        fddd|       d|v sd|v r"|j                  |t'        t*        fddi|       d|v sd|v r#|j                  |t'        t(        fddd|       d|v r"|j                  |t'        t(        fddi|       d|v r$|j                  |t'        t(        fddd|       yyc c}	w c c}	w c c}	w )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/pdfr   r$   >   jpgr"   rI   r!   jpegpng2xrG   z%s,zsupported formats are: z not rI   Trd   rG   r   r^   r   r   r!   r]   r"   )r@   matplotlib.figurer   display_formatter
formatters
isinstancestrsetvaluespopget_backendloweripython_display_formatterfor_typer   
differencejoinrepr
ValueErrorr   rY   rk   )shellformatsr_   r@   r   svg_formatterpng_formatterjpg_formatterpdf_formatterr<   
mplbackend	formatter	supportedbadbsgss                   r=   select_figure_formatsr      sW    (++66GM++66{CM++66|DM++667HIM'3)'lG#(#:#:#E#E#L#L#NPaaeeFDP'')//1JW
.M M++EE	6#78GI


Y
'C
CHHs3!d1g344CHHy9!d1g9::r2FGGGLKeDKFK	
 7g0vw}'TT'TV'TU6W,GLKeDKFK	
 vw|'Q'Q&'QRGLKeDKFK	
 3 Q 49s   3I,
I1
5I6
c                     ddl }| r| dk7  rt        |    }| dk(  rd} | |fS |j                  d   }t        j	                  |d      } |r| |k7  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)r@   backendsrcParamsOrigbackend2guir5   )gui
gui_selectr@   r   s       r=   find_gui_and_backendr   -  sy    " 
sf}3-%<C" < )))4 oogt, #+CsmG<rE   c                     ddl }|j                  d       | |j                  d<   ddl m} |j	                  |        d|j
                  _        t        |j                        |_        y)z7Activate the given backend and set interactive to True.r   NTr   )rp   F)	r@   rn   rA   rp   switch_backendshow	_needmainr   rq   )r   r@   rx   s      r=   activate_matplotlibr   X  s[     4 
 &-J	"
 )wCHH ))@)@ACrE   c                 z    d}t        ||        |rd}t        ||        t        | d<   ddlm} || d<   t        | d<   y)	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 *
rD   r   )displayr   r>   N)execrD   IPython.displayr   r>   )user_ns
import_allsr   s       r=   import_pylabr   p  sL    
A 	G%Q !GI' GI GIrE   c                 Z    t        j                  dt        d       ddlm}  || |       y)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()`rH   )
stacklevelr   )configure_inline_supportN)warningswarnDeprecationWarning matplotlib_inline.backend_inliner   )r   r   configure_inline_support_origs      r=   r   r     s-     MM	L	 "%1rE   )rI   tightF)F)NN)T)__doc__ior   binasciir   	functoolsr   r   IPython.core.displayr   IPython.utils.decoratorsr   r   dictzipr   keysr   r>   rD   rY   rk   r~   r   r   r   r   r   r   r}   rE   r=   <module>r      s   +
     ' /'	8 I I	
 	' 
8 
8 
7 	( 
8 W h  
5 
5  
5!" 	$#$ :--)6 3x((--/:; 05 4E [,!K !K D J  G H H  ;</06;/b.-`5
x(VB0!B2rE   