
    XhC                     R   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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d/ Zd?d0Zd@d1Zd2 Zd3 Zd4 ZdAd5Zd6 ZdBd7Zdaedz  ed8<   d9efd:Z d9e!e"   fd;Z#d<e"dz  d9e"dz  fd=Z$d<e"dz  d9e"dz  fd>Z%y)Cz%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v r-t        j                  |  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__)names    K/var/www/html/myenv/lib/python3.12/site-packages/IPython/core/pylabtools.py__getattr__r:   K   sX    **f > >	

 y<v.//
78,.@I
JJ    c                  <   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fmrB   numfs          r9   getfigsrK   [   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sizeyrM   s      r9   figsizerQ   v   s     -2ENJ()r;   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linesrY   get_facecolorget_edgecolorupdater   r@   matplotlib.backend_basesr[   print_figuregetvaluedecoder   )
figfmtrZ   base64kwargsrY   kwbytes_ior[   datas
             r9   re   re      s    " 88CII
''C
hAg %%'%%'!
B IIfyH
zz=CJJH++D
e|{{7# K 
$.55g>Kr;   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
    rS   Fri   rj   NrT   )widthheightr\   r^   )re   r   r   rg   )rh   rj   rk   pngdatawhmetadatas          r9   retina_figurerw      sh     3EHUEfEG '?DAqA1-HWe4;;GDHr;   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                 v   ddl }ddlm} |j                  ddi      5   | g|i | ddd       |j	                         r|j                          |j                  j                  r!|j                          d|j                  _        	 |j                  } |        y# 1 sw Y   uxY w# 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)rM   matplotlib.pyplotpyplot
rc_contextis_interactiveshowdraw_if_interactivecalleddrawdraw_allr6   )fnamewhererl   rM   pltdasafe_execfiles         r9   mpl_execfilez mpl_runner.<locals>.mpl_execfile   s     	' ""M5#9: 	/%.%.2.	/ $$&HHJ ""))HHJ-2C##*	B D#	/ 	/  		s   B B,  B),	B87B8 )r   r   s   ` r9   
mpl_runnerr      s    @ r;   c                     	 | j                   j                  j                  } |        y# t        $ r}t	               |d}~ww xY w)zreshow an nbagg figureN)r@   managerreshowr6   NotImplementedError)rh   r   es      r9   _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v 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/pdf)r   r&   r'   r$   >   jpgr"   rU   r!   jpegpng2xrS   z%s,zsupported formats are: z not rU   Trp   rS   r   rj   r   r   r!   ri   r"   )rM   matplotlib.figurer   display_formatter
formatters
isinstancestrsetvaluespopget_backendloweripython_display_formatterfor_typer   
differencejoinrepr
ValueErrorr   re   rw   )shellformatsrk   rM   r   svg_formatterpng_formatterjpg_formatterpdf_formatterrJ   
mplbackend	formatter	supportedbadbsgss                   r9   select_figure_formatsr     sP    (++66GM++66{CM++66|DM++667HIM'3)'lG#(#:#:#E#E#L#L#NPaaeeFDP'')//1JSS++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&I+
/I0
c                    ddl }t               rv|j                  j                  j                  }| dv r$|j
                  d   }|j                  |      \  }} nt        |       } |j                  |       \  }} t        |       } | |fS t        |dd      }|dk\  }ddlm} t        |      }|sd	|d
<   | r| dk7  r||    }| dk(  r8d} n5|j
                  d   }ddlm}	 |	j                  |d      } |r| |k7  r|} ||    }| 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    )r0   r%   )rM   _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dictr0   rC   )
gui
gui_selectrM   r   r   mpl_version_infohas_unified_qt_backendr/   	backends_r0   s
             r9   find_gui_and_backendr   A  s1   " #%%..77HH .  --i8G+;;GDLGS,S1C+BB3GLGS*3/G| z+=vF-70XI!"	$
sf}C.%<C )))4 	8oogt, #+CnG h<r;   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   )r|   F)	rM   rz   rN   r|   switch_backendr   	_needmainr   r   )r   rM   r   s      r9   activate_matplotlibr     s[     4 
 &-J	"
 )wCHH ))@)@ACr;   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 *
rQ   r   )displayr   rK   N)execrQ   IPython.displayr   rK   )user_ns
import_allsr   s       r9   import_pylabr     sL    
A 	G%Q !GI' GI GIr;   "_matplotlib_manages_backends_valuereturnc                  x    t         	 ddlm}  t        | d      a t         S t         S # t        $ r
 da Y t         S w xY w)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.
    r   r   r   F)r   matplotlib.backends.registryr   hasattrImportErrorr   s    r9   r   r     sN     *1	7E18 ":2. .---  	716.--	7s   & 99c                     t               r?ddlm}  | j                         | j	                         D cg c]  }t        |       c}z   }n)ddlm} t        |j                  j                               }t        dg|z         S c c}w )z}Return list of all Matplotlib backends and GUI event loops.

    This is the list returned by
        %matplotlib --list
    r   r   )
pylabtoolsr   )r   r   r   list_alllist_gui_frameworksr   IPython.corer   listr/   keyssorted)r   r   retr   s       r9   '_list_matplotlib_backends_and_gui_loopsr     sx     $%A'')';;=-
 )--
 

 	,:&&++-.6(S.!!-
s   Br   c                 2    | r| j                         dk(  ry| S )Nr   macosxr   r   s    r9   r   r     s    
syy{e#Jr;   c                 2    | r| j                         dk(  ry| S )Nr   r   r   r   s    r9   r   r      s    
syy{h&Jr;   )rU   tightF)F)NN)T)&__doc__ior   binasciir   	functoolsr   r2   IPython.core.displayr   IPython.utils.decoratorsr   _deprecated_backendsr   zipr   r   _deprecated_backend2guir:   rK   rQ   re   rw   r   r   r   r   r   r   r   bool__annotations__r   r   r   r   r   r   r   r;   r9   <module>r      sn   +
     ' /'	8 I I	
 	' 
8 
8 
7 	' 
8 W h  
5 
5  
5!" 	$#$ :--) 6 ##%';'@'@'BC 
 HM L  !8!D'-  $'-  $ $  &+ 
 # $(   $)  !$)  ! G$E"E"E"D!GH;<K 6;/b./d5
xFRB0!F 37 "D4K 6.d .4"c "0C$J 3: cDj S4Z r;   