
    &e6                        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
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<d2Zd=d3Zd4 Zd5 Zd6 Zd>d7Zd8 Zd?d:Zd; ZdS )@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} | s |                                }d |D             S g }| D ]P}|j                            |          }|t          d|z             1|                    |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                 &    g | ]}|j         j        S  )canvasfigure).0fms     7lib/python3.11/site-packages/IPython/core/pylabtools.py
<listcomp>zgetfigs.<locals>.<listcomp>X   s    888R	 888    Nz!Warning: figure %s not available.)	matplotlib._pylab_helpersr/   get_all_fig_managersfigsgetprintappendr2   r3   )fig_numsr/   fig_managersr;   numfs         r6   getfigsrC   I   s     .----- //1188<8888 	- 	-CS!!Ay9C?@@@@AHO,,,,r8   c                 &    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sizeyrE   s      r6   figsizerI   d   s(     -2ENJ()))r8   pngtightFc                    | j         s	| j        sdS | j        }|dk    r|dz  }d}||                                 |                                 ||d}|                    |           t                      }| j        ddlm	}  ||             | j        j
        |fi | |                                }	|dk    r|	                    d	          }	n&|r$t          |	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   rJ   )format	facecolor	edgecolordpibbox_inchesr   )FigureCanvasBaser!   zutf-8Fnewlineascii)axeslinesrR   get_facecolorget_edgecolorupdater   r2   matplotlib.backend_basesrT   print_figuregetvaluedecoder   )
figfmtrS   base64kwargsrR   kwbytes_iorT   datas
             r6   r^   r^   o   s.   " 8 CI 
'C
hAg %%''%%''!
 
B IIfyyH
z======CJH+++++D
e||{{7##	 ?$...55g>>Kr8   c                     t          | fddd|}|dS t          |          \  }}|dz  |dz  d}|r$t          |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
    rM   Frb   rc   NrN   )widthheightrU   rW   )r^   r   r   r`   )ra   rc   rd   pngdatawhmetadatas          r6   retina_figurerp      s     3EHUEEfEEG '??DAqA1--H EWe444;;GDDHr8   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                    ddl }ddlm} |                    ddi          5   | g|R i | ddd           n# 1 swxY w Y   |                                r|                                 |j        j        r |                                 d|j        _        	 |j	        } |             dS # t          $ r Y dS 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)rE   matplotlib.pyplotpyplot
rc_contextis_interactiveshowdraw_if_interactivecalleddrawdraw_allAttributeError)fnamewherere   rE   pltdasafe_execfiles         r6   mpl_execfilez mpl_runner.<locals>.mpl_execfile   s?    	'''''' ""M5#9:: 	/ 	/M%.%...2...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ $$&& 	HHJJJ ") 	3HHJJJ-2C#*	B BDDDDD  	 	 	DD	s!   <A A B/ /
B=<B=r1   )r   r   s   ` r6   
mpl_runnerr      s%        @ r8   c                     	 | j         j        j        } |             dS # t          $ r}t	                      |d}~ww xY w)zreshow an nbagg figureN)r2   managerreshowr}   NotImplementedError)ra   r   es      r6   _reshow_nbagg_figurer      sT    #* 	  + + +!##*+s    
=8=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          |          }fd| j        j                                        D              |	                                
                                }|d	k    s|d
k    r'| j        j        }	|	                    t                     h d}
|                    |
          }|rYdd                    d |D                       z  }dd                    d |
D                       z  }t!          d|d|          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                 <    g | ]}|                     d           S )N)pop)r4   rB   r   s     r6   r7   z)select_figure_formats.<locals>.<listcomp>  s'    PPPaaeeFDPPPr8   r   r$   >   jpgr"   rJ   r!   jpegpng2xrM   z%s,c                 ,    g | ]}t          |          S r1   reprr4   rB   s     r6   r7   z)select_figure_formats.<locals>.<listcomp>  s    333!d1gg333r8   c                 ,    g | ]}t          |          S r1   r   r   s     r6   r7   z)select_figure_formats.<locals>.<listcomp>  s    999!d1gg999r8   zsupported formats are: z not rJ   Tri   rM   r   rc   r   r   r!   rb   r"   )rE   matplotlib.figurer   display_formatter
formatters
isinstancestrsetvaluesget_backendloweripython_display_formatterfor_typer   
differencejoin
ValueErrorr   r^   rp   )shellformatsrd   rE   svg_formatterpng_formatterjpg_formatterpdf_formatter
mplbackend	formatter	supportedbadbsgsr   s                 @r6   select_figure_formatsr      s    ((((((+6GM+6{CM+6|DM+67HIM'3 )'llGPPPP5#:#E#L#L#N#NPPPP''))//11JW
.M M M+E	6#7888GGGI


Y
'
'C
 HCHH33s333444CHH99y999:::jrrr22FGGGGLKeDKKFKK	
 	
 	
 7g00vw}'T'TT'TV'T'TUUU6W,,GLKeDKKFKK	
 	
 	
 vw|'Q'Q'Q&'Q'QRRRGLKeDKKFKK	
 	
 	
 	
 	
 r8   c                    ddl }t          |dd          dk    }t          t                    }|sd|d<   | r| dk    r||          }| d	k    rd} n:|j        d
         }t
                              |d          } |r| |k    r
|} ||          }| |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__version_info__)r   r   )      qt5aggr   autor    backend)rE   getattrdictbackendsrcParamsOrigbackend2guir<   )gui
gui_selectrE   has_unified_qt_backend	backends_r   s         r6   find_gui_and_backendr   /  s    " $Z1CVLLPVVXI! #"	$
 %sf}}C.%<<C ))4 oogt,,  	%#++CnG<r8   c                     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   )ru   F)	rE   rs   rF   ru   switch_backendrx   	_needmainr   ry   )r   rE   r   s      r6   activate_matplotlibr   `  s     4   
 &-J	"
 )(((((wCH ))@AACr8   Tc                     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 *
rI   r   )displayr   rC   N)execrI   IPython.displayr   rC   )user_ns
import_allsr   s       r6   import_pylabr   x  sr    
A 	G %Q !GI'''''' GI GIr8   c                 b    t          j        dt          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()`rN   )
stacklevelr   )configure_inline_supportN)warningswarnDeprecationWarning matplotlib_inline.backend_inliner   )r   r   configure_inline_support_origs      r6   r   r     sb     M	L	         "!%11111r8   )rJ   rK   F)F)NN)T)__doc__ior   binasciir   	functoolsr   r   IPython.core.displayr   IPython.utils.decoratorsr   r   r   zipr   keysr   rC   rI   r^   rp   r   r   r   r   r   r   r   r1   r8   r6   <module>r      s   + +
                    ' ' ' ' ' ' / / / / / /'	8 I I	
 	' 
8 
8 
7 	' 
8 W h  
5 
5  
5!" 	$#$ :--)  6 d33x(((--//::;; 05 4E [,!K !K D J  G H H  ;</0  6; ; ;/ / / /b   ./ / /d  5
 5
 5
x. . . .bB B B0! ! ! !B2 2 2 2 2r8   