
    Vf-N                       d dl mZ d dlmZ d dlZd dlmZmZmZ d dl	m
Z d dlmZ d dlZd dlmZmZ d dlmZmZ d dlmZmZ d dlmZmZ d d	lmZ erd d
lm Z  d dl!m"Z" d dl#m$Z$ d dl%m&Z'  G d de      Z( G d de(      Z) G d de(      Z*y)    )annotations)SequenceN)TYPE_CHECKINGAnycast)FillTypeLineType)convert_filledconvert_lines)as_fill_typeas_line_type)filled_to_mpl_pathslines_to_mpl_paths)Renderer)Axes)Figure)	ArrayLikec                  t   e Zd ZU dZded<   ded<   ded<   	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd	Zdd
ZddZddZ	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ		 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 d 	 	 	 	 	 	 	 	 	 	 	 d!dZd"d#dZd$dZddZd%d&dZ	 	 	 	 d'	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(dZy))MplRenderera  Utility renderer using Matplotlib to render a grid of plots over the same (x, y) range.

    Args:
        nrows (int, optional): Number of rows of plots, default ``1``.
        ncols (int, optional): Number of columns of plots, default ``1``.
        figsize (tuple(float, float), optional): Figure size in inches, default ``(9, 9)``.
        show_frame (bool, optional): Whether to show frame and axes ticks, default ``True``.
        backend (str, optional): Matplotlib backend to use or ``None`` for default backend.
            Default ``None``.
        gridspec_kw (dict, optional): Gridspec keyword arguments to pass to ``plt.subplots``,
            default None.
    zSequence[Axes]_axesr   _figbool_want_tightNc                <   |dd l }|j                  |       t        |ddd      }|||d<   nt        d      |d<   t        j                  ||fi |\  | _        }	|	j                         | _        |s"| j                  D ]  }
|
j                  d	        d| _	        y )
Nr   FT)figsizesqueezesharexshareygridspec_kwequal)aspect
subplot_kwoff)

matplotlibusedictpltsubplotsr   flattenr   axisr   )selfnrowsncolsr   
show_framebackendr   r$   kwargsaxesaxs              d/var/www/html/software/conda/envs/catlas/lib/python3.12/site-packages/contourpy/util/mpl_renderer.py__init__zMplRenderer.__init__*   s     NN7#!%guTZ^!_"$/F=!#'w#7F< ,,ue>v>	4\\^
jj       c                \    t        | d      r t        j                  | j                         y y )Nr   )hasattrr'   closer   r+   s    r3   __del__zMplRenderer.__del__E   s!    4 IIdii  !r5   c                    | j                   D ])  }t        |dd      s|j                  d       d|_        + | j                  r4t        | j                         dkD  r| j                  j                          y y y )N_need_autoscaleFT)tight   )r   getattrautoscale_viewr<   r   lenr   tight_layoutr+   r2   s     r3   
_autoscalezMplRenderer._autoscaleI   so     ** 	+Br,e4!!!-%*"	+ DJJ! 3II""$ !4r5   c                D    t        |t              r| j                  |   }|S N)
isinstanceintr   rC   s     r3   _get_axzMplRenderer._get_axT   s    b#BB	r5   c                    t        |      }| j                  |      }t        ||      }t        j                  ||dd|      }|j                  |       d|_        y)a  Plot filled contours on a single Axes.

        Args:
            filled (sequence of arrays): Filled contour data as returned by
                :func:`~contourpy.ContourGenerator.filled`.
            fill_type (FillType or str): Type of ``filled`` data as returned by
                :attr:`~contourpy.ContourGenerator.fill_type`, or string equivalent
            ax (int or Maplotlib Axes, optional): Which axes to plot on, default ``0``.
            color (str, optional): Color to plot with. May be a string color or the letter ``"C"``
                followed by an integer in the range ``"C0"`` to ``"C9"`` to use a color from the
                ``tab10`` colormap. Default ``"C0"``.
            alpha (float, optional): Opacity to plot with, default ``0.7``.
        noner   
facecolors
edgecolorslwalphaTN)r   rI   r   mcollectionsPathCollectionadd_collectionr<   )r+   filled	fill_typer2   colorrP   paths
collections           r3   rT   zMplRenderer.filledY   sZ    * !+	\\"#FI6!00e1EK

*%!r5   c                   | j                  |      }| j                  ||      \  }}t        ||      } |j                  |||j                  |j                  fi | |dkD  r[d|ddddf   |ddddf   z   |ddddf   z   |ddddf   z   z  }	d|ddddf   |ddddf   z   |ddddf   z   |ddddf   z   z  }
||d<    |j                  t        j                  |ddddf   |	|ddddf   f      j                  d      t        j                  |ddddf   |
|ddddf   f      j                  d      t        j                  |ddddf   |	|ddddf   f      j                  d      t        j                  |ddddf   |
|ddddf   f      j                  d      fi | ||j                  ||||d	d
       d|_        y)a  Plot quad grid lines on a single Axes.

        Args:
            x (array-like of shape (ny, nx) or (nx,)): The x-coordinates of the grid points.
            y (array-like of shape (ny, nx) or (ny,)): The y-coordinates of the grid points.
            ax (int or Matplotlib Axes, optional): Which Axes to plot on, default ``0``.
            color (str, optional): Color to plot grid lines, default ``"black"``.
            alpha (float, optional): Opacity to plot lines with, default ``0.1``.
            point_color (str, optional): Color to plot grid points or ``None`` if grid points
                should not be plotted, default ``None``.
            quad_as_tri_alpha (float, optional): Opacity to plot ``quad_as_tri`` grid, default 0.

        Colors may be a string color or the letter ``"C"`` followed by an integer in the range
        ``"C0"`` to ``"C9"`` to use a color from the ``tab10`` colormap.

        Warning:
            ``quad_as_tri_alpha > 0`` plots all quads as though they are unmasked.
        )rV   rP   r   g      ?Nr>   rP   )   rZ   o)rV   rP   markerrO   T)	rI   _grid_as_2dr&   plotTnpstackreshaper<   )r+   xyr2   rV   rP   point_colorquad_as_tri_alphar0   xmidymids              r3   gridzMplRenderer.gridv   s0   8 \\"1%1!%E!?1acc133)&)q 3B38qSbSz1Acrc12gJ>12qr6JKD3B38qSbSz1Acrc12gJ>12qr6JKD/F7OBGG!CRC"H+tQqr12vY78@@I!CRC"H+tQqr12vY78@@I!ABG*dAcrc12gJ78@@I!ABG*dAcrc12gJ78@@I	
  "GGAq5GK!r5   c                    t        |      }| j                  |      }t        ||      }t        j                  |d|||      }|j                  |       d|_        y)aR  Plot contour lines on a single Axes.

        Args:
            lines (sequence of arrays): Contour line data as returned by
                :func:`~contourpy.ContourGenerator.lines`.
            line_type (LineType or str): Type of ``lines`` data as returned by
                :attr:`~contourpy.ContourGenerator.line_type`, or string equivalent.
            ax (int or Matplotlib Axes, optional): Which Axes to plot on, default ``0``.
            color (str, optional): Color to plot lines. May be a string color or the letter ``"C"``
                followed by an integer in the range ``"C0"`` to ``"C9"`` to use a color from the
                ``tab10`` colormap. Default ``"C0"``.
            alpha (float, optional): Opacity to plot lines with, default ``1.0``.
            linewidth (float, optional): Width of lines, default ``1``.
        rK   rL   TN)r   rI   r   rQ   rR   rS   r<   )	r+   lines	line_typer2   rV   rP   	linewidthrW   rX   s	            r3   rl   zMplRenderer.lines   sZ    . !+	\\""5)4!00f9ES

*%!r5   c                    t         j                  j                  |      }|t         j                  j                  u ry| j	                  |      }| j                  ||      \  }}|j                  ||   ||   d|       y)a  Plot masked out grid points as circles on a single Axes.

        Args:
            x (array-like of shape (ny, nx) or (nx,)): The x-coordinates of the grid points.
            y (array-like of shape (ny, nx) or (ny,)): The y-coordinates of the grid points.
            z (masked array of shape (ny, nx): z-values.
            ax (int or Matplotlib Axes, optional): Which Axes to plot on, default ``0``.
            color (str, optional): Circle color, default ``"black"``.
        Nr\   )c)ra   magetmasknomaskrI   r^   r_   )r+   rd   re   zr2   rV   masks          r3   ru   zMplRenderer.mask   si    " uu}}Q255<<\\"1%1
$4#/r5   c                ^    | j                          | j                  j                  ||       y)zSave plots to SVG or PNG file.

        Args:
            filename (str): Filename to save to.
            transparent (bool, optional): Whether background should be transparent, default
                ``False``.
        )transparentN)rD   r   savefig)r+   filenamerw   s      r3   savezMplRenderer.save   s%     			(<r5   c                    | j                          t        j                         }| j                  j	                  |d       |j                  d       |S )zhSave plots to an ``io.BytesIO`` buffer.

        Return:
            BytesIO: PNG image buffer.
        png)formatr   )rD   ioBytesIOr   rx   seek)r+   bufs     r3   save_to_bufferzMplRenderer.save_to_buffer   s@     	jjl		#e,
r5   c                L    | j                          t        j                          y)zMShow plots in an interactive window, in the usual Matplotlib manner.
        N)rD   r'   showr9   s    r3   r   zMplRenderer.show   s     	
r5   c                    |r#| j                  |      j                  ||       y| j                  |      j                  |       y)a  Set the title of a single Axes.

        Args:
            title (str): Title text.
            ax (int or Matplotlib Axes, optional): Which Axes to set the title of, default ``0``.
            color (str, optional): Color to set title. May be a string color or the letter ``"C"``
                followed by an integer in the range ``"C0"`` to ``"C9"`` to use a color from the
                ``tab10`` colormap. Default is ``None`` which uses Matplotlib's default title color
                that depends on the stylesheet in use.
        )rV   N)rI   	set_title)r+   titler2   rV   s       r3   r   zMplRenderer.title   s:     LL&&uE&:LL&&u-r5   c                   | j                  |      }| j                  ||      \  }}t        j                  |      }|j                  \  }}	t        |      D ]>  }
t        |	      D ].  }|j                  ||
|f   ||
|f   ||
|f   | ddd|d       0 @ |rt        |dz
        D ]  }
t        |	dz
        D ]  }t        j                  ||
|
dz   ||dz   f         }t        j                  ||
|
dz   ||dz   f         }t        j                  ||
|
dz   ||dz   f         }|j                  |||| ddd|d         yy)a  Show ``z`` values on a single Axes.

        Args:
            x (array-like of shape (ny, nx) or (nx,)): The x-coordinates of the grid points.
            y (array-like of shape (ny, nx) or (ny,)): The y-coordinates of the grid points.
            z (array-like of shape (ny, nx): z-values.
            ax (int or Matplotlib Axes, optional): Which Axes to plot on, default ``0``.
            color (str, optional): Color of added text. May be a string color or the letter ``"C"``
                followed by an integer in the range ``"C0"`` to ``"C9"`` to use a color from the
                ``tab10`` colormap. Default ``"green"``.
            fmt (str, optional): Format to display z-values, default ``".1f"``.
            quad_as_tri (bool, optional): Whether to show z-values at the ``quad_as_tri`` centers
                of quads.

        Warning:
            ``quad_as_tri=True`` shows z-values for all quads, even if masked.
         centerThavarV   clip_onr>      N)rI   r^   ra   asarrayshaperangetextmean)r+   rd   re   rt   r2   rV   fmtquad_as_trinynxjixxyyzzs                  r3   z_valueszMplRenderer.z_values	  s   6 \\"1%1JJqMBr 	3A2Y 3!Q$1a4Qq!tWcU FOh#T  33	3 2a4[ *r!t *A1QqS5!AaC%<1B1QqS5!AaC%<1B1QqS5!AaC%<1BGGBr3%pjh8SX$(  *	** r5   )r>   r>   	   r   TNN)r,   rH   r-   rH   r   tuple[float, float]r.   r   r/   
str | Noner   zdict[str, Any] | NonereturnNone)r   r   )r2   
Axes | intr   r   )r   C0ffffff?)rT   cpy.FillReturnrU   FillType | strr2   r   rV   strrP   floatr   r   )r   black皙?Nr   )rd   r   re   r   r2   r   rV   r   rP   r   rf   r   rg   r   r   r   )r   r         ?r>   )rl   cpy.LineReturnrm   LineType | strr2   r   rV   r   rP   r   rn   r   r   r   )r   r   )rd   r   re   r   rt   z'ArrayLike | np.ma.MaskedArray[Any, Any]r2   r   rV   r   r   r   )F)ry   r   rw   r   r   r   )r   z
io.BytesIO)r   N)r   r   r2   r   rV   r   r   r   )r   greenz.1fF)rd   r   re   r   rt   r   r2   r   rV   r   r   r   r   r   r   r   )__name__
__module____qualname____doc____annotations__r4   r:   rD   rI   rT   rj   rl   ru   rz   r   r   r   r    r5   r3   r   r      sJ    
L '-"-1     %	 
     +  
 6!	% "" "" 	"
 " " 
"B "&#$-"-" -" 	-"
 -" -"  -" !-" 
-"f "" "" 	"
 " " " 
"H 00 0 3	0
 0 0 
00	=
.* !**** ** 	**
 ** ** ** ** 
**r5   r   c                  :     e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 d fdZ xZS )MplTestRendererzTest renderer implemented using Matplotlib.

    No whitespace around plots and no spines/ticks displayed.
    Uses Agg backend, so can only save to file/buffer, cannot call ``show()``.
    c                    ddddddd}t         |   |||dd|       | j                  D ]F  }|j                  d       |j	                  d       |j                  g        |j                  g        H d| _        y )	Ng{Gz?gGz?)leftrighttopbottomwspacehspaceTAgg)r.   r/   r           F)superr4   r   set_xmarginset_ymargin
set_xticks
set_yticksr   )r+   r,   r-   r   gridspecr2   	__class__s         r3   r4   zMplTestRenderer.__init__<  s     
 	5'dEx 	 	
 ** 	BNN3NN3MM"MM"		 !r5   )r>   r>   r   )r,   rH   r-   rH   r   r   r   r   )r   r   r   r   r4   __classcell__r   s   @r3   r   r   6  sC     '-	!! ! %	!
 
! !r5   r   c                  d    e Zd ZdZ	 	 	 	 d		 	 	 	 	 	 	 	 	 d
 fdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ		 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
 xZS )MplDebugRendererzDebug renderer implemented using Matplotlib.

    Extends ``MplRenderer`` to add extra information to help in debugging such as markers, arrows,
    text, etc.
    c                *    t         |   ||||       y rF   )r   r4   )r+   r,   r-   r   r.   r   s        r3   r4   zMplDebugRenderer.__init__]  s     	w
;r5   c                l   d||z   z  }||z
  }|t        j                  t        j                  ||            z  }t        j                  |d   |d    f      }	t        j                  ||dz  |	z
  |z  z
  ||dz  |z  z   ||dz  |	z   |z  z
  f      }
|j                  |
d d df   |
d d df   d||       y )Ng      ?r>   r   -rp   rP   )ra   sqrtdotr   rb   r_   )r+   r2   
line_startline_endrV   rP   
arrow_sizemidalongr   arrows              r3   _arrowzMplDebugRenderer._arrowf  s     :():%u-..

E!HuQxi0159u$j00%)J&&59u$j00
 
 	adU1a4[#eDr5   c                   t        |      }t        | 	  |||||       ||y | j                  |      }t	        ||t
        j                        }|t        | D ]  \  }}|	t        |d d |dd        D ]p  \  }}||| }|j                  |d d df   |d d df   ||       |
dkD  s4t        |      }t        |dz
        D ]!  }| j                  |||   ||dz      |||
       # r  |t        | D ]  \  }}|	t        j                  |d   t              }d||dd  dz
  <   |	
|d d }d||<   |j                  |d d df   |   |d d df   |   d||       |	k|j                  |d d df      |d d df   |   d|	|        y y )	NrZ   r>   r   r   r   )dtypeFr\   )r   r   rT   rI   r
   r   ChunkCombinedOffsetzipr_   rA   r   r   ra   onesr   )r+   rT   rU   r2   rV   rP   
line_color
line_alpharf   start_point_colorr   pointsoffsetsstartendxysnr   ru   start_indicesr   s                       r3   rT   zMplDebugRenderer.filledz  s
    !+	vy"eU;+"5\\"	83O3OP !#&< 
b>"%gcrlGABK"@ bJE3 s+CGGC1Is1a4yJjGQ!C'H!&qs bA KKCFC!Hj*V`abb
b "#&< C>wwwr{$7&+WQR[]#$0$+CRLM*/D'1a4L&q!tT(:C;V`  b %0GGF1a4L71m9TVY/z  CC #r5   c
           
     ~   t        |      }t        | 	  ||||||       |	dk(  r|y | j                  |      }t	        ||t
        j                        }
t        rt        t        j                  |
      }
|	dkD  rB|
D ]=  }t        t        |      dz
        D ]!  }| j                  |||   ||dz      |||	       # ? ||
D ]z  }d}t        |      }|E|j                  |d   |d   d||       d}|d   d   |d   d   k(  r|d   d   |d   d   k(  r|dz  }|j                  |||df   |||df   d||       | y y )	Nr   r>   r   )r   r   )r   r>   r\   r   rZ   )r   r   rl   rI   r   r	   Separater   r   cpyLineReturn_Separater   rA   r   r_   )r+   rl   rm   r2   rV   rP   rn   rf   r   r   separate_linesliner   start_index	end_indexr   s                  r3   rl   zMplDebugRenderer.lines  s    !+	eYE5)D!4\\"&ui9J9JK!#"9"9>JN& Rs4y{+ RAKKDGT!A#YujQRR "& 	.I	$0GGDJT
C;LTYGZ"#KAwqzT"Xa[0T!WQZ48A;5N!Q	[2A56[=RTU=U8VX[u  .	. #r5   c                >   | j                  |      }| j                  ||      \  }}t        j                  |      }|j                  \  }}t        |      D ]E  }t        |      D ]5  }	|	||z  z   }
|j                  |||	f   |||	f   t        |
      dd|d       7 G y )Nr   r   Tr   rI   r^   ra   r   r   r   r   r   )r+   rd   re   rt   r2   rV   r   r   r   r   quads              r3   point_numberszMplDebugRenderer.point_numbers  s     \\"1%1JJqMBr 	&A2Y &1R4x!Q$1a4#d)EQV $  &&	&r5   c                   | j                  |      }| j                  ||      \  }}t        j                  |      }|j                  \  }}t        d|      D ]  }t        d|      D ]u  }	|	||z  z   }
||dz
  |dz   |	dz
  |	dz   f   j                         }||dz
  |dz   |	dz
  |	dz   f   j                         }|j                  ||t        |
      dd|d       w  y )Nr>   r   Tr   )	rI   r^   ra   r   r   r   r   r   r   )r+   rd   re   rt   r2   rV   r   r   r   r   r   rh   ri   s                r3   quad_numberszMplDebugRenderer.quad_numbers  s     \\"1%1JJqMBq" 	dA1b\ d1R4x1QqS!A#ac')*//11QqS!A#ac')*//1dCI(xu^bc	d	dr5   c                d   | j                  |      }| j                  ||      \  }}t        j                  |      }|j                  \  }}	t        |      D ]X  }
t        |	      D ]H  }||
|f   }|||kD  rd}n
||kD  rd}nd}|j                  ||
|f   ||
|f   t        |      dd|d       J Z y )Nr   r>   r   r   r   Tr   r   )r+   rd   re   rt   lower_levelupper_levelr2   rV   r   r   r   r   r   z_levels                 r3   z_levelszMplDebugRenderer.z_levels  s     \\"1%1JJqMBr 
	&A2Y 	&q!tW*rK/?G+%GG!Q$1a4#g,6hV[ $  &	&
	&r5   )r>   r>   r   T)
r,   rH   r-   rH   r   r   r.   r   r   r   )r2   r   r   cpy.CoordinateArrayr   r   rV   r   rP   r   r   r   r   r   )r   C1r   r   r   r   redr   )rT   r   rU   r   r2   r   rV   r   rP   r   r   r   r   r   rf   r   r   r   r   r   r   r   )r   r   r   r>   r   r   r   )rl   r   rm   r   r2   r   rV   r   rP   r   rn   r   rf   r   r   r   r   r   r   r   )r   r   )rd   r   re   r   rt   r   r2   r   rV   r   r   r   )r   blue)Nr   r   )rd   r   re   r   rt   r   r   r   r   zfloat | Noner2   r   rV   r   r   r   )r   r   r   r   r4   r   rT   rl   r   r   r   r   r   s   @r3   r   r   W  s    '-<< < %	<
 < 
<EE (E &	E
 E E E 
E0 !&3C3C "3C 	3C
 3C 3C 3C 3C 3C 3C 3C 
3Cr !&&.&. "&. 	&.
 &. &. &. &. &. &. 
&.Z && & 	&
 & & 
&. dd d 	d
 d d 
d2 %)&& & 	&
 & "& & & 
&r5   r   )+
__future__r   collections.abcr   r~   typingr   r   r   matplotlib.collectionscollectionsrQ   matplotlib.pyplotpyplotr'   numpyra   	contourpyr   r	   contourpy.convertr
   r   contourpy.enum_utilr   r   contourpy.util.mpl_utilr   r   contourpy.util.rendererr   matplotlib.axesr   matplotlib.figurer   numpy.typingr   contourpy._contourpy
_contourpyr   r   r   r   r   r5   r3   <module>r     se    " $ 	 + + -   ( ; : K ,$(&&Z*( Z*z!k !B}&{ }&r5   