
    ^h6                        S r SSKJr  SSKJr  SSKJr  SSKrSSKJ	r	  SSK
Jr  0 SS	_S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S _S!S!_S"S"_S#S#_S$S%S%S&.Er\" \" \R                  5       \R!                  5       5      5      rS
=\S''   \S('   S\S)'   S\S*'   S\S+'   S\S,'   S\S'   S\S'   S\S'   \S	 \S 	 \S!	 \S"	 \S#	 \S$	 \S%	 S- rS. rS8S/ jrS9S0 jrS1 rS2 rS3 rS:S4 jrS5 rS;S6 jrS7 rg)<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                  R   SSK Jn  U (       d6  UR                  5       nU Vs/ s H  o3R                  R                  PM     sn$ / nU  HV  nUR
                  R                  U5      nUc  [        SU-  5        M1  UR                  UR                  R                  5        MX     U$ s  snf )ag  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          Q/home/james-whalen/.local/lib/python3.13/site-packages/IPython/core/pylabtools.pygetfigsr>   I   s     .//1+78<R		  <88CS!Ay9C?@AHHOO,   9s   B$c                 ,    SSK nX/UR                  S'   g)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     -2NJ()    c                    U R                   (       d  U R                  (       d  gU R                  nUS:X  a  US-  nSnUU R                  5       U R	                  5       UUS.nUR                  U5        [        5       nU R                  c  SSKJ	n  U" U 5        U R                  R                  " U40 UD6  UR                  5       n	US:X  a  U	R                  S	5      n	U	$ U(       a  [        U	S
S9R                  S5      n	U	$ )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=JJH++D
e|{{7# K 
$.55g>KrE   c                     [        U 4SSS.UD6nUc  g[        U5      u  pEUS-  US-  S.nU(       a  [        USS9R                  S5      nX64$ )	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      sd     3EHUEfEG '?DAA1-HWe4;;GDrE   c                    ^  U 4S jnU$ )a4  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SK nSSKJn  UR                  SS05         T" U /UQ70 UD6  SSS5        UR	                  5       (       a  UR                  5         UR                  R                  (       a!  UR                  5         SUR                  l         UR                  nU" 5         g! , (       d  f       N= f! [         a     gf = f)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pyplot
rc_contextis_interactiveshowdraw_if_interactivecalleddrawdraw_allAttributeError)fnamewherer`   r@   pltdasafe_execfiles         r=   mpl_execfile mpl_runner.<locals>.mpl_execfile   s     	' ""M5#9:%.%.2. ; $$&&HHJ ""))HHJ-2C##*	B D# ;:  		s   B*B; *
B8;
CC )r}   r~   s   ` r=   
mpl_runnerr      s    @ rE   c                      U R                   R                  R                  nU" 5         g! [         a  n[	        5       UeSnAff = f)zreshow an nbagg figureN)r2   managerreshowrx   NotImplementedError)r\   r   es      r=   _reshow_nbagg_figurer      s@    ##** 	  +!#*+s    * 
A?Ac           	      <   SSK nSSKJn  U R                  R                  S   nU R                  R                  S   nU R                  R                  S   nU R                  R                  S   n[        U[        5      (       a  U1n[        U5      nU R                  R                  R                  5        V	s/ s H  oR                  US5      PM       n	UR                  5       R                  5       n
U
S:X  d  U
S	:X  a,  U R                  R                  nUR                  U[        5        1 S
knUR                  U5      nU(       ao  SSR!                  U V	s/ s H  n	[#        U	5      PM     sn	5      -  nSSR!                  U V	s/ s H  n	[#        U	5      PM     sn	5      -  n[%        SU< SU< 35      eSU;   a#  UR                  U['        [(        4SSS.UD65        SU;   d  SU;   a"  UR                  U['        [*        4SS0UD65        SU;   d  SU;   a#  UR                  U['        [(        4SSS.UD65        SU;   a"  UR                  U['        [(        4SS0UD65        SU;   a$  UR                  U['        [(        4SSS.UD65        ggs  sn	f s  sn	f s  sn	f )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      sf    (++66GM++66{CM++66|DM++667HIM'3)'lG#(#:#:#E#E#L#L#NP#NaeeFD#NP'')//1JW
.M M++EE	6#78GI


Y
'C
CHHs3s!d1gs344CHHy9y!d1gy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   8JJ
J
c                    SSK n[        USS5      S:  n[        [        5      nU(       d  SUS'   U (       a  U S:w  a  X@   nU S	:X  a  Sn X4$ UR                  S
   n[
        R                  US5      n U(       a  X:w  a  Un X@   nX4$ )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)r@   getattrdictbackendsrcParamsOrigbackend2guir5   )gui
gui_selectr@   has_unified_qt_backend	backends_r   s         r=   find_gui_and_backendr   /  s    " $Z1CVLPVVXI!"	$
sf}.%<C" < )))4 oogt, #+CnG<rE   c                     SSK nUR                  S5        XR                  S'   SSK Jn  UR	                  U 5        SUR
                  l        [        UR                  5      Ul        g)z7Activate the given backend and set interactive to True.r   NTr   )rp   F)	r@   rn   rA   rp   switch_backendrs   	_needmainr   rt   )r   r@   r{   s      r=   activate_matplotlibr   `  sY     4 
 &-	"
 )wCHH ))@)@ACrE   c                 ~    Sn[        X 5        U(       a  Sn[        X 5        [        U S'   SSKJn  X0S'   [        U S'   g)	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   x  sF    
A 	%Q !GI' I GIrE   c                 T    [         R                  " S[        SS9  SSKJn  U" X5        g)z
.. 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   r   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./d5
x.bB0!B2rE   