Format: application/x-python-code
⬇ Download File (12.4 KB)
   1  o
   2  
   3  ��h�F�@sUdZddlmZddlmZddlmZddlZddlm	Z	ddl
   4  mZidd	�d
   5  d�dd
   6  �dd�dd�dd�dd�dd�dd�dd�dd�dd�dd�d d �d!d!�d"d"�d#d#�d$d%d%d&��Ze
   7  ee��e����Zd
   8  ed'<ed(<ded)<ded*<ded+<ded,<ded<ded<ded<ed=ed =ed!=ed"=ed#=ed$=ed%=d-d.�Zd/d0�Zd1d2�ZdTd6d7�ZdUd8d9�Zd:d;�Zd<d=�Zd>d?�ZdVd@dA�ZdBdC�ZdWdEdF�ZdGdH�ZdaedBe dI<dJefdKdL�Z!dJe"e#fdMdN�Z$dOe#dBdJe#dBfdPdQ�Z%dOe#dBdJe#dBfdRdS�Z&dS)Xz%Pylab (matplotlib) support utilities.�)�BytesIO)�
   9  b2a_base64)�partialN)�_pngxy)�
  10  flag_callsZtkZTkAggZgtkZGTKAggZgtk3ZGTK3AggZgtk4ZGTK4AggZwxZWXAggZqt4ZQt4AggZqt5ZQt5AggZqt6ZQtAgg�qt�osxZMacOSX�nbaggZnbAggZwebaggZWebAgg�notebook�agg�svg�pdfZpsz)module://matplotlib_inline.backend_inline�module://ipympl.backend_nbagg)�inline�ipympl�widgetZGTKZGTKCairoZ	GTK3CairoZ	GTK4CairoZWXZCocoaAggcCs>|dvrt�|�d�t�t�d|��Stdt�d|����)N)�backends�backend2guizg is deprecated since IPython 8.24, backends are managed in matplotlib and can be externally registered.Z_deprecated_zmodule z has no attribute )�warnings�warn�DeprecationWarning�globals�AttributeError�__name__)�name�r�Mc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/pylabtools.py�__getattr__Ks�rcGshddlm}|s|��}dd�|D�Sg}|D]}|j�|�}|dur*td|�q|�|jj�q|S)a�Get a list of matplotlib figures by figure numbers.
  11  
  12      If no arguments are given, all available figures are returned.  If the
  13      argument list contains references to invalid figures, a warning is printed
  14      but the function continues pasting further figures.
  15  
  16      Parameters
  17      ----------
  18      figs : tuple
  19          A tuple of ints giving the figure numbers of the figures to return.
  20      r)�GcfcSsg|]}|jj�qSr)�canvas�figure)�.0�fmrrr�
  21  <listcomp>j�zgetfigs.<locals>.<listcomp>Nz!Warning: figure %s not available.)	Zmatplotlib._pylab_helpersrZget_all_fig_managers�figs�get�print�appendrr )Zfig_numsrZfig_managersr%�num�frrr�getfigs[sr+cCsddl}||g|jd<dS)z�Set the default figure size to be [sizex, sizey].
  22  
  23      This is just an easy to remember, convenience wrapper that sets::
  24  
  25        matplotlib.rcParams['figure.figsize'] = [sizex, sizey]
  26      rNzfigure.figsize)�
  27  matplotlib�rcParams)ZsizexZsizeyr,rrr�figsizevsr.�png�tightFc
  28  Ks�|js|jsdS|j}|dkr|d}d}||��|��||d�}|�|�t�}|jdur8ddlm	}||�|jj
  29  |fi|��|��}	|dkrQ|	�d	�}	|	S|r\t
  30  |	d
  31  d��d�}	|	S)
  32  a�Print a figure to an image, and return the resulting file data
  33  
  34      Returned data will be bytes unless ``fmt='svg'``,
  35      in which case it will be unicode.
  36  
  37      Any keyword args are passed to fig.canvas.print_figure,
  38      such as ``quality`` or ``bbox_inches``.
  39  
  40      If `base64` is True, return base64-encoded str instead of raw bytes
  41      for binary-encoded image formats
  42  
  43      .. versionadded:: 7.29
  44          base64 argument
  45      N�retina�r/)�formatZ	facecolorZ	edgecolor�dpi�bbox_inchesr)�FigureCanvasBaserzutf-8F��newline�ascii)Zaxes�linesr4Z
  46  get_facecolorZ
  47  get_edgecolor�updaterrZmatplotlib.backend_basesr6�print_figure�getvalue�decoder)
  48  �fig�fmtr5�base64�kwargsr4�kwZbytes_ior6�datarrrr<�s2�
  49  
  50  
  51  �r<cKs^t|fddd�|��}|durdSt|�\}}|d|dd�}|r+t|dd��d�}||fS)	z�format a figure as a pixel-doubled (retina) PNG
  52  
  53      If `base64` is True, return base64-encoded str instead of raw bytes
  54      for binary-encoded image formats
  55  
  56      .. versionadded:: 7.29
  57          base64 argument
  58      r1F�r@rANr2)�width�heightr7r9)r<rrr>)r?rArBZpngdata�w�h�metadatarrr�
  59  retina_figure�s	rKcs�fdd�}|S)a\Factory to return a matplotlib-enabled runner for %run.
  60  
  61      Parameters
  62      ----------
  63      safe_execfile : function
  64          This must be a function with the same interface as the
  65          :meth:`safe_execfile` method of IPython.
  66  
  67      Returns
  68      -------
  69      A function suitable for use as the ``runner`` argument of the %run magic
  70      function.
  71      cs�ddl}ddlm}|�ddi���|g|�Ri|��Wd�n1s'wY|��r4|��|jjr@|��d|j_z|j	}Wn
  72  t
  73  yOYdSw|�dS)z�matplotlib-aware wrapper around safe_execfile.
  74  
  75          Its interface is identical to that of the :func:`execfile` builtin.
  76  
  77          This is ultimately a call to execfile(), but wrapped in safeties to
  78          properly handle interactive rendering.rN�interactiveF)r,Zmatplotlib.pyplot�pyplotZ
  79  rc_context�is_interactive�show�draw_if_interactive�calledZdrawZdraw_allr)�fname�whererCr,�plt�da��
  80  safe_execfilerr�mpl_execfile�s �
  81  �
  82  z mpl_runner.<locals>.mpl_execfiler)rWrXrrVr�
  83  mpl_runner�s rYc
  84  Cs:z|jjj}Wnty}zt�|�d}~ww|�dS)zreshow an nbagg figureN)r�manager�reshowr�NotImplementedError)r?r[�errr�_reshow_nbagg_figure�s��
  85  r^cs�ddl}ddlm�|jjd}|jjd}|jjd}|jjd}t|t�r*|h}t|�}�fdd	�|jj��D�|�	��
  86  �}|d
  87  vrO|jj}	|	��t
  88  �hd�}
  89  |�|
  90  �}|rzdd
  91  �dd	�|D��}dd
  92  �dd	�|
  93  D��}
  94  td|
  95  |f��d|vr�|��ttfddd�|���d|vs�d|vr�|��ttfddi|���d|vs�d|vr�|��ttfddd�|���d|vr�|��ttfddi|���d|vr�|��ttfddd�|���dSdS)a_Select figure formats for the inline backend.
  96  
  97      Parameters
  98      ----------
  99      shell : InteractiveShell
 100          The main IPython instance.
 101      formats : str or set
 102          One or a set of figure formats to enable: 'png', 'retina', 'jpeg', 'svg', 'pdf'.
 103      **kwargs : any
 104          Extra keyword arguments to be passed to fig.canvas.print_figure.
 105      rN��Figurez
 106  image/svg+xmlz	image/pngz
 107  image/jpegzapplication/pdfcsg|]}|��d��qS)N)�pop�r!r*r_rrr#sz)select_figure_formats.<locals>.<listcomp>)r	rrr>r
 108  �png2xr1�jpeg�jpgrr/z%s�,cS�g|]}t|��qSr��reprrbrrrr#'r$cSrgrrhrbrrrr#(r$z supported formats are: %s not %sr/TrEr1rcrArerdrr@r
 109  )r,Zmatplotlib.figurer`�display_formatter�
 110  formatters�
 111  isinstance�str�set�values�get_backend�lowerZipython_display_formatterZfor_typer^�
 112  difference�join�
 113  ValueErrorrr<rK)�shell�formatsrBr,Z
 114  svg_formatterZ
 115  png_formatterZ
 116  jpg_formatterZ
 117  pdf_formatterZ
 118  mplbackend�	formatter�	supported�bad�bs�gsrr_r�select_figure_formatssJ
 119  
 120  ����r|c
 121  Csddl}t�r0|jjj}|dvr|jd}|�|�\}}nt|�}|�|�\}}t	|�}||fSt
 122  |dd�}|dk}ddlm}t|�}|sJd	|d
 123  <|r[|dkr[||}|dkrZd}n|jd}dd
 124  lm
 125  }	|	�|d�}|rx||krx|}||}|dkr~d}||fS)a�Given a gui string return the gui and mpl backend.
 126  
 127      Parameters
 128      ----------
 129      gui : str
 130          Can be one of ('tk','gtk','wx','qt','qt4','inline','agg').
 131      gui_select : str
 132          Can be one of ('tk','gtk','wx','qt','qt4','inline').
 133          This is any gui already selected by the shell.
 134  
 135      Returns
 136      -------
 137      A tuple of (gui, backend) where backend is one of ('TkAgg','GTKAgg',
 138      'WXAgg','Qt4Agg','module://matplotlib_inline.backend_inline','agg').
 139      rN)�autoN�backend�__version_info__)rr)��)rZqt5aggrr}r)rr)r,�_matplotlib_manages_backendsr�registry�backend_registryZrcParamsOrigZresolve_backend�_convert_gui_to_matplotlib�resolve_gui_or_backend�_convert_gui_from_matplotlib�getattrZIPython.core.pylabtools�dictrr&)
 140  �guiZ
 141  gui_selectr,r�r~Zmpl_version_infoZhas_unified_qt_backendrZ	backends_rrrr�find_gui_and_backendAs<
 142  
 143  �
 144  r�cCsJddl}|�d�||jd<ddlm}|�|�d|j_t|j�|_dS)z7Activate the given backend and set interactive to True.rNTr~)rMF)	r,rLr-rMZswitch_backendrOZ	_needmainrrP)r~r,rTrrr�activate_matplotlib�s
 145  
 146  
 147  r�TcCsHd}t||�|rd}t||�t|d<ddlm}||d<t|d<dS)	z�Populate the namespace with pylab-related values.
 148  
 149      Imports matplotlib, pylab, numpy, and everything from pylab and numpy.
 150  
 151      Also imports a few names from IPython (figsize, display, getfigs)
 152  
 153      zbimport numpy
 154  import matplotlib
 155  from matplotlib import pylab, mlab, pyplot
 156  np = numpy
 157  plt = pyplot
 158  z3from matplotlib.pylab import *
 159  from numpy import *
 160  r.r)�displayr�r+N)�execr.�IPython.displayr�r+)Zuser_nsZ
 161  import_all�sr�rrr�import_pylab�s
 162  
 163  r�cCs*tjdtdd�ddlm}|||�dS)a
 164  
 165      .. deprecated:: 7.23
 166  
 167          use `matplotlib_inline.backend_inline.configure_inline_support()`
 168  
 169      Configure an IPython shell object for matplotlib use.
 170  
 171      Parameters
 172      ----------
 173      shell : InteractiveShell instance
 174      backend : matplotlib backend
 175      z�`configure_inline_support` is deprecated since IPython 7.23, directly use `matplotlib_inline.backend_inline.configure_inline_support()`r2)�
 176  stacklevelr)�configure_inline_supportN)rrrZ matplotlib_inline.backend_inliner�)rur~Zconfigure_inline_support_origrrrr��s
 177  �r��"_matplotlib_manages_backends_value�returncCsBtdurzddlm}t|d�aWtStydaYtSwtS)a�Return True if Matplotlib manages backends, False otherwise.
 178  
 179      If it returns True, the caller can be sure that
 180      matplotlib.backends.registry.backend_registry is available along with
 181      member functions resolve_gui_or_backend, resolve_backend, list_all, and
 182      list_gui_frameworks.
 183  
 184      This function can be removed as it will always return True when Python
 185      3.12, the latest version supported by Matplotlib < 3.9, reaches
 186      end-of-life in late 2028.
 187      Nr�r�r�F)r��matplotlib.backends.registryr��hasattr�ImportErrorr�rrrr��s
 188  ���r�cCsVt�rddlm}|��dd�|��D�}n
 189  ddlm}t|j�	��}t
 190  dg|�S)z}Return list of all Matplotlib backends and GUI event loops.
 191  
 192      This is the list returned by
 193          %matplotlib --list
 194      rr�cSrgr)r�)r!r�rrrr#s��z;_list_matplotlib_backends_and_gui_loops.<locals>.<listcomp>)�
 195  pylabtoolsr})r�r�r�Zlist_allZlist_gui_frameworksZIPython.corer��listr�keys�sorted)r��retr�rrr�'_list_matplotlib_backends_and_gui_loops�s
 196  �r�r�cC�|r
 197  |��dkr
 198  dS|S)Nr�macosx�rq�r�rrrr��r�cCr�)Nr�rr�r�rrrr�r�r�)r/r0F)F)NN)T)'�__doc__�ior�binasciir�	functoolsrrZIPython.core.displayrZIPython.utils.decoratorsrZ_deprecated_backendsr��zipror�Z_deprecated_backend2guirr+r.r<rKrYr^r|r�r�r�r�r��bool�__annotations__r�r�rmr�r�r�rrrr�<module>s���������	�
 199  ���
 200  �������
 201  
 202  12
 203  
 204  <I
 205  !