
    \e-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*dS )    )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                      e Zd ZU dZded<   ded<   ded<   	 	 	 	 	 	 dKdLdZdMdZdMdZdNdZ	 	 	 dOdPd*Z		 	 	 	 	 dQdRd2Z
	 	 	 	 dSdTd9Z	 	 dUdVd<ZdWdXd@ZdYdBZdMdCZdZd[dEZ	 	 	 	 d\d]dJZdS )^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_tight   	   r   TNnrowsintncolsfigsizetuple[float, float]
show_framebackend
str | Nonegridspec_kwdict[str, Any] | NonereturnNonec                P   |dd l }|                    |           t          |ddd          }|||d<   nt          d          |d<   t          j        ||fi |\  | _        }	|	                                | _        |s| j        D ]}
|
                    d	           d| _	        d S )
Nr   FT)r    squeezesharexshareyr%   equal)aspect
subplot_kwoff)

matplotlibusedictpltsubplotsr   flattenr   axisr   )selfr   r   r    r"   r#   r%   r1   kwargsaxesaxs              ;lib/python3.11/site-packages/contourpy/util/mpl_renderer.py__init__zMplRenderer.__init__*   s     NN7###!%guTZ^!_!_!_"$/F=!!#'w#7#7#7F< ,ue>>v>>	4\\^^
 	j      c                \    t          | d          rt          j        | j                   d S d S )Nr   )hasattrr4   closer   r8   s    r<   __del__zMplRenderer.__del__E   s6    4   	!Idi     	! 	!r>   c                    | j         D ]0}t          |dd          r|                    d           d|_        1| j        r3t          | j                   dk    r| j                                         d S d S d S )N_need_autoscaleFT)tightr   )r   getattrautoscale_viewrE   r   lenr   tight_layoutr8   r;   s     r<   
_autoscalezMplRenderer._autoscaleI   s     * 	+ 	+Br,e44 +!!!---%*" 	%DJ! 3 3I""$$$$$	% 	% 3 3r>   r;   
Axes | intr   c                J    t          |t                    r| j        |         }|S N)
isinstancer   r   rK   s     r<   _get_axzMplRenderer._get_axT   s$    b# 	 BB	r>   r   C0ffffff?filledcpy.FillReturn	fill_typeFillType | strcolorstralphafloatc                    t          |          }|                     |          }t          ||          }t          j        ||dd|          }|                    |           d|_        dS )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lwrZ   TN)r   rQ   r   mcollectionsPathCollectionadd_collectionrE   )r8   rT   rV   r;   rX   rZ   paths
collections           r<   rT   zMplRenderer.filledY   sx    * !++	\\"#FI66!0e1EK K K

*%%%!r>   black皙?xr   ypoint_colorquad_as_tri_alphac                4   |                      |          }|                     ||          \  }}t          ||          } |j        |||j        |j        fi | |dk    rd|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                              d          t          j        |ddddf         |
|ddddf         f                              d          t          j        |ddddf         |	|ddddf         f                              d          t          j        |ddddf         |
|ddddf         f                              d          fi | ||                    ||||d	d
           d|_        dS )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.
        )rX   rZ   r   g      ?Nr   rZ   )   rn   o)rX   rZ   markerra   T)	rQ   _grid_as_2dr3   plotTnpstackreshaperE   )r8   ri   rj   r;   rX   rZ   rk   rl   r9   xmidymids              r<   gridzMplRenderer.gridv   s   8 \\"1%%1!%E!?!?!?1ac13))&)))q  3B38qSbSz1Acrc122gJ>122qrr6JKD3B38qSbSz1Acrc122gJ>122qrr6JKD/F7OBG!CRC"H+tQqrr122vY788@@II!CRC"H+tQqrr122vY788@@II!ABBG*dAcrc122gJ788@@II!ABBG*dAcrc122gJ788@@II	 
    "GGAq5GKKK!r>         ?linescpy.LineReturn	line_typeLineType | str	linewidthc                    t          |          }|                     |          }t          ||          }t          j        |d|||          }|                    |           d|_        dS )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``.
        r]   r^   TN)r   rQ   r   rb   rc   rd   rE   )	r8   r|   r~   r;   rX   rZ   r   re   rf   s	            r<   r|   zMplRenderer.lines   sx    . !++	\\""5)44!0f9ES S S

*%%%!r>   z'ArrayLike | np.ma.MaskedArray[Any, Any]c                   t           j                            |          }|t           j        j        u rdS |                     |          }|                     ||          \  }}|                    ||         ||         d|           dS )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"``.
        Nrp   )c)ru   magetmasknomaskrQ   rr   rs   )r8   ri   rj   r   r;   rX   masks          r<   r   zMplRenderer.mask   s}    " u}}Q25<F\\"1%%1
$4#/////r>   Ffilenametransparentc                f    |                                   | j                            ||           dS )zSave plots to SVG or PNG file.

        Args:
            filename (str): Filename to save to.
            transparent (bool, optional): Whether background should be transparent, default
                ``False``.
        )r   N)rL   r   savefig)r8   r   r   s      r<   savezMplRenderer.save   s5     		(<<<<<r>   
io.BytesIOc                    |                                   t          j                    }| j                            |d           |                    d           |S )zhSave plots to an ``io.BytesIO`` buffer.

        Return:
            BytesIO: PNG image buffer.
        png)formatr   )rL   ioBytesIOr   r   seek)r8   bufs     r<   save_to_bufferzMplRenderer.save_to_buffer   sN     	jll	#e,,,
r>   c                T    |                                   t          j                     dS )zMShow plots in an interactive window, in the usual Matplotlib manner.
        N)rL   r4   showrB   s    r<   r   zMplRenderer.show   s#     	




r>   titlec                    |r,|                      |                              ||           dS |                      |                              |           dS )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.
        )rX   N)rQ   	set_title)r8   r   r;   rX   s       r<   r   zMplRenderer.title   s]      	.LL&&uE&:::::LL&&u-----r>   green.1ffmtquad_as_tric                   |                      |          }|                     ||          \  }}t          j        |          }|j        \  }}	t          |          D ]K}
t          |	          D ]9}|                    ||
|f         ||
|f         ||
|f         | dd|d           :L|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                   }|                    |||| dd|d           dS dS )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varX   clip_onr      N)rQ   rr   ru   asarrayshaperangetextmean)r8   ri   rj   r   r;   rX   r   r   nynxjixxyyzzs                  r<   z_valueszMplRenderer.z_values	  s   6 \\"1%%1JqMMBr 	3 	3A2YY 3 3!Q$1a4Qq!tWc*<*<h#T  3 3 3 33  	*2a4[[ * *r!t * *A1QqS5!AaC%<11B1QqS5!AaC%<11B1QqS5!AaC%<11BGGBr3MMh8SX$(  * * * *	*	* 	** *r>   )r   r   r   TNN)r   r   r   r   r    r!   r"   r   r#   r$   r%   r&   r'   r(   )r'   r(   )r;   rM   r'   r   )r   rR   rS   )rT   rU   rV   rW   r;   rM   rX   rY   rZ   r[   r'   r(   )r   rg   rh   Nr   )ri   r   rj   r   r;   rM   rX   rY   rZ   r[   rk   r$   rl   r[   r'   r(   )r   rR   r{   r   )r|   r}   r~   r   r;   rM   rX   rY   rZ   r[   r   r[   r'   r(   )r   rg   )ri   r   rj   r   r   r   r;   rM   rX   rY   r'   r(   )F)r   rY   r   r   r'   r(   )r'   r   )r   N)r   rY   r;   rM   rX   r$   r'   r(   )r   r   r   F)ri   r   rj   r   r   r   r;   rM   rX   rY   r   rY   r   r   r'   r(   )__name__
__module____qualname____doc____annotations__r=   rC   rL   rQ   rT   rz   r|   r   r   r   r   r   r    r>   r<   r   r      s          LLL '-"-1         6! ! ! !	% 	% 	% 	%    " " " " "B "&#$-" -" -" -" -"f " " " " "H 0 0 0 0 00	= 	= 	= 	= 	=
 
 
 
   . . . . .* !** ** ** ** ** ** **r>   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()``.
    r   r   r   r   r   r    r!   r'   r(   c                2   ddddddd}t                                          |||dd|           | j        D ]V}|                    d           |                    d           |                    g            |                    g            Wd| _        d S )	Ng{Gz?gGz?)leftrighttopbottomwspacehspaceTAgg)r"   r#   r%           F)superr=   r   set_xmarginset_ymargin
set_xticks
set_yticksr   )r8   r   r   r    gridspecr;   	__class__s         r<   r=   zMplTestRenderer.__init__<  s     
 
 	5'dEx 	 	
 	
 	
 * 	 	BNN3NN3MM"MM" r>   )r   r   r   )r   r   r   r   r    r!   r'   r(   )r   r   r   r   r=   __classcell__r   s   @r<   r   r   6  sW          '-	! ! ! ! ! ! ! ! ! ! !r>   r   c                       e Zd ZdZ	 	 	 	 d>d? fdZd@dZ	 	 	 	 	 	 	 	 dAdB fd)Z	 	 	 	 	 	 	 dCdD fd0Z	 	 dEdFd5Z	 	 dGdFd7Z		 	 	 dHdId=Z
 xZS )JMplDebugRendererzDebug renderer implemented using Matplotlib.

    Extends ``MplRenderer`` to add extra information to help in debugging such as markers, arrows,
    text, etc.
    r   r   Tr   r   r   r    r!   r"   r   r'   r(   c                P    t                                          ||||           d S rO   )r   r=   )r8   r   r   r    r"   r   s        r<   r=   zMplDebugRenderer.__init__]  s)     	w
;;;;;r>   r;   r   
line_startcpy.CoordinateArrayline_endrX   rY   rZ   r[   
arrow_sizec                   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          }
|                    |
d d df         |
d d df         d||           d S )Ng      ?r   r   -r   rZ   )ru   sqrtdotr   rv   rs   )r8   r;   r   r   rX   rZ   r   midalongr   arrows              r<   _arrowzMplDebugRenderer._arrowf  s     :():%u--...
E!HuQxi01159u$j00%)J&&59u$j00
  
 	aaadU111a4[#eDDDDDr>   r   C1rS   rR   redrh   rT   rU   rV   rW   rM   
line_color
line_alphark   start_point_colorc                    t          |          }t                                          |||||           ||d S |                     |          }t	          ||t
          j                  }|t          | D ]\  }}|t          |d d         |dd                    D ]\  }}|||         }|                    |d d df         |d d df         ||           |
dk    rMt          |          }t          |dz
            D ]+}|                     |||         ||dz            |||
           ,|t          | D ]\  }}|t          j        |d         t                    }d||dd          dz
  <   |	|d d         }d||<   |                    |d d df         |         |d d df         |         d||           |	:|                    |d d df         |         |d d df         |         d|	|           d S d S )	Nrn   r   r   r   r   )dtypeFrp   )r   r   rT   rQ   r
   r   ChunkCombinedOffsetziprs   rI   r   r   ru   onesr   )r8   rT   rV   r;   rX   rZ   r   r   rk   r   r   pointsoffsetsstartendxysnr   r   start_indicesr   s                       r<   rT   zMplDebugRenderer.filledz  s    !++	vy"eU;;;+"5F\\"	83OPP !#&< 
b 
b>"%gcrclGABBK"@"@ b bJE3 s+CGGC1Is111a4yJjGQQQ!C''HH!&qs b bA KKCFC!Hj*V`aaaab "#&< C C>wwr{$777&+WQRR[]#$0$+CRCLM*/D'111a4L&qqq!tT(:C;V`  b b b %0GGF111a4L71m9TVY/z  C C C #"C Cr>   r{   r|   r}   r~   r   r   c
           
     :   t          |          }t                                          ||||||           |	dk    r|d S |                     |          }t	          ||t
          j                  }
t          rt          t          j
        |
          }
|	dk    rP|
D ]M}t          t          |          dz
            D ]+}|                     |||         ||dz            |||	           ,N||
D ]}d}t          |          }|i|                    |d         |d         d||           d}|d         d         |d         d         k    r#|d         d         |d         d         k    r|dz  }|                    |||df         |||df         d||           d S d S )	Nr   r   r   )r   r   )r   r   rp   r   rn   )r   r   r|   rQ   r   r	   Separater   r   cpyLineReturn_Separater   rI   r   rs   )r8   r|   r~   r;   rX   rZ   r   rk   r   r   separate_linesliner   start_index	end_indexr   s                  r<   r|   zMplDebugRenderer.lines  s    !++	eYE5)DDD!4F\\"&ui9JKK 	K!#"9>JJN& R Rs4yy{++ R RAKKDGT!A#YujQQQQR "& 	. 	.II	$0GGDJT
C;LTYGZZZ"#KAwqzT"Xa[00T!WQZ48A;5N5N!Q	[2A56[=RTU=U8VX[u  . . . . #"	. 	.r>   ri   r   rj   r   c                h   |                      |          }|                     ||          \  }}t          j        |          }|j        \  }}t          |          D ]U}t          |          D ]C}	|	||z  z   }
|                    |||	f         |||	f         t          |
          dd|d           DVd S )Nr   r   Tr   rQ   rr   ru   r   r   r   r   rY   )r8   ri   rj   r   r;   rX   r   r   r   r   quads              r<   point_numberszMplDebugRenderer.point_numbers  s     \\"1%%1JqMMBr 	& 	&A2YY & &1R4x!Q$1a4#d))EQV $  & & & &&	& 	&r>   bluec                   |                      |          }|                     ||          \  }}t          j        |          }|j        \  }}t          d|          D ]}t          d|          D ]}	|	||z  z   }
||dz
  |dz   |	dz
  |	dz   f                                         }||dz
  |dz   |	dz
  |	dz   f                                         }|                    ||t          |
          dd|d           d S )Nr   r   Tr   )	rQ   rr   ru   r   r   r   r   r   rY   )r8   ri   rj   r   r;   rX   r   r   r   r   r   rx   ry   s                r<   quad_numberszMplDebugRenderer.quad_numbers  s'    \\"1%%1JqMMBq" 	d 	dA1b\\ d d1R4x1QqS!A#ac')*//111QqS!A#ac')*//11dCII(xu^bcccc	d	d 	dr>   Nr   lower_levelupper_levelfloat | Nonec                   |                      |          }|                     ||          \  }}t          j        |          }|j        \  }}	t          |          D ]m}
t          |	          D ][}||
|f         }|	||k    rd}n||k    rd}nd}|                    ||
|f         ||
|f         t          |          dd|d           \nd S )Nr   r   r   r   r   Tr   r   )r8   ri   rj   r   r   r   r;   rX   r   r   r   r   r   z_levels                 r<   z_levelszMplDebugRenderer.z_levels  s     \\"1%%1JqMMBr 
	& 
	&A2YY 	& 	&q!tW*rK/?/?GG+%%GGG!Q$1a4#g,,6hV[ $  & & & &	&
	& 
	&r>   )r   r   r   T)
r   r   r   r   r    r!   r"   r   r'   r(   )r;   r   r   r   r   r   rX   rY   rZ   r[   r   r[   r'   r(   )r   r   rS   rR   rS   rR   r   rh   )rT   rU   rV   rW   r;   rM   rX   rY   rZ   r[   r   rY   r   r[   rk   rY   r   rY   r   r[   r'   r(   )r   rR   r{   r   rR   r   rh   )r|   r}   r~   r   r;   rM   rX   rY   rZ   r[   r   r[   rk   rY   r   rY   r   r[   r'   r(   )r   r   )ri   r   rj   r   r   r   r;   rM   rX   rY   r'   r(   )r   r   )Nr   r   )ri   r   rj   r   r   r   r   r[   r   r  r;   rM   rX   rY   r'   r(   )r   r   r   r   r=   r   rT   r|   r   r   r  r   r   s   @r<   r   r   W  s]         '-< < < < < < <E E E E0 !&3C 3C 3C 3C 3C 3C 3Cr !&&. &. &. &. &. &. &.Z & & & & &. d d d d d2 %)& & & & & & & & &r>   r   )+
__future__r   collections.abcr   r   typingr   r   r   matplotlib.collectionscollectionsrb   matplotlib.pyplotpyplotr4   numpyru   	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   r>   r<   <module>r     s   " " " " " " $ $ $ $ $ $ 				 + + + + + + + + + + - - - - - -           ( ( ( ( ( ( ( ( ; ; ; ; ; ; ; ; : : : : : : : : K K K K K K K K , , , , , , '$$$$$$((((((&&&&&&&&&&&&Z* Z* Z* Z* Z*( Z* Z* Z*z! ! ! ! !k ! ! !B}& }& }& }& }&{ }& }& }& }& }&r>   