o
    iN                     @  s  d dl mZ d dlZd dlm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rpd d
lm Z  d dl!m"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z) G dd deZ*G dd de*Z+G dd de*Z,dS )    )annotationsN)pairwise)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)Sequence)Axes)Figure)	ArrayLikec                   @  s   e Zd ZU dZded< ded< ded< 					
		dXdYddZdZddZdZddZd[d!d"Z	#	$	%d\d]d.d/Z		#	0	1		#d^d_d7d8Z
	#	$	9	d`dad?d@Z	#	0dbdcdCdDZdddedHdIZdfdKdLZdZdMdNZdgdhdPdQZ	#	R	S	EdidjdVdWZdS )k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                 C  s   |d urdd l }|| |dddd}|d ur||d< nddi|d< tj||fi |\| _}	|	 | _|sB| jD ]}
|
d	 q:d| _d S )
Nr   FT)r   ZsqueezeZsharexZshareyr$   ZaspectequalZ
subplot_kwoff)	Z
matplotlibZusepltZsubplotsr   flattenr   Zaxisr   )selfr   r   r   r!   r"   r$   ZmplkwargsZaxesax r/   j/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/contourpy/util/mpl_renderer.py__init__,   s   	




zMplRenderer.__init__c                 C  s   t | drt| j d S d S )Nr   )hasattrr*   closer   r,   r/   r/   r0   __del__H   s   
zMplRenderer.__del__c                 C  sT   | j D ]}t|ddr|jdd d|_q| jr&t| j dkr(| j  d S d S d S )N_need_autoscaleFT)Ztightr   )r   getattrZautoscale_viewr6   r   lenr   Ztight_layoutr,   r.   r/   r/   r0   
_autoscaleL   s   
zMplRenderer._autoscaler.   
Axes | intr   c                 C  s   t |tr
| j| }|S N)
isinstancer   r   r9   r/   r/   r0   _get_axW   s   

zMplRenderer._get_axr   C0ffffff?filledcpy.FillReturn	fill_typeFillType | strcolorstralphafloatc                 C  sD   t |}| |}t||}tj||dd|d}|| d|_dS )a  Plot filled contours on a single Axes.

        Args:
            filled (sequence of arrays): Filled contour data as returned by
                :meth:`~.ContourGenerator.filled`.
            fill_type (FillType or str): Type of :meth:`~.ContourGenerator.filled` data as returned
                by :attr:`~.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   Z
facecolorsZ
edgecolorslwrG   TN)r   r>   r   mcollectionsPathCollectionadd_collectionr6   )r,   rA   rC   r.   rE   rG   paths
collectionr/   r/   r0   rA   \   s   




zMplRenderer.filledblack皙?xr   ypoint_colorquad_as_tri_alphac                 C  s   |  |}| ||\}}||d}|j|||j|jfi | |dkrd|ddddf |ddddf  |ddddf  |ddddf   }	d|ddddf |ddddf  |ddddf  |ddddf   }
||d< |jt|ddddf |	|ddddf fdt|ddddf |
|ddddf fdt|ddddf |	|ddddf fdt|ddddf |
|ddddf fdfi | |dur|j||||d	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.
        )rE   rG   r   g      ?Nr   rG   )   rW   o)rE   rG   markerrK   T)r>   _grid_as_2dplotTnpstackZreshaper6   )r,   rS   rT   r.   rE   rG   rU   rV   r-   xmidymidr/   r/   r0   gridy   s&   

TT4444
zMplRenderer.grid      ?linescpy.LineReturn	line_typeLineType | str	linewidthc           	      C  sD   t |}| |}t||}tj|d|||d}|| d|_dS )aW  Plot contour lines on a single Axes.

        Args:
            lines (sequence of arrays): Contour line data as returned by
                :meth:`~.ContourGenerator.lines`.
            line_type (LineType or str): Type of :meth:`~.ContourGenerator.lines` data as returned
                by :attr:`~.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``.
        rI   rJ   TN)r   r>   r   rL   rM   rN   r6   )	r,   rd   rf   r.   rE   rG   rh   rO   rP   r/   r/   r0   rd      s   




zMplRenderer.linesz'ArrayLike | np.ma.MaskedArray[Any, Any]c                 C  sT   t j|}|t jju rdS | |}| ||\}}|j|| || d|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"``.
        NrY   )c)r^   maZgetmaskZnomaskr>   r[   r\   )r,   rS   rT   ri   r.   rE   maskr/   r/   r0   rm      s   
zMplRenderer.maskFfilenametransparentc                 C  s   |    | jj||d 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``.
        )ro   N)r:   r   savefig)r,   rn   ro   r/   r/   r0   save   s   zMplRenderer.save
io.BytesIOc                 C  s.   |    t }| jj|dd |d |S )zhSave plots to an ``io.BytesIO`` buffer.

        Return:
            BytesIO: PNG image buffer.
        Zpng)formatr   )r:   ioBytesIOr   rp   seek)r,   bufr/   r/   r0   save_to_buffer   s
   
zMplRenderer.save_to_bufferc                 C  s   |    t  dS )zMShow plots in an interactive window, in the usual Matplotlib manner.
        N)r:   r*   showr4   r/   r/   r0   ry      s   zMplRenderer.showtitlec                 C  s0   |r|  |j||d 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.
        )rE   N)r>   	set_title)r,   rz   r.   rE   r/   r/   r0   rz      s   zMplRenderer.titlegreen.1ffmtquad_as_tric                 C  s@  |  |}| ||\}}t|}|j\}}	t|D ]$}
t|	D ]}|j||
|f ||
|f ||
|f | dd|dd q!q|rt|d D ]U}
t|	d D ]J}tj||
|
d ||d f tjd}tj||
|
d ||d f tjd}t||
|
d ||d f }|j|||| dd|dd qPqHd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ZhavarE   Zclip_onr      ZdtypeN)	r>   r[   r^   asarrayshaperangetextmeanZfloat64)r,   rS   rT   ri   r.   rE   r~   r   nynxjixxyyzzr/   r/   r0   z_values  s,   


,(("zMplRenderer.z_values)r   r   r   TNN)r   r   r   r   r   r    r!   r   r"   r#   r$   r%   r&   r'   )r&   r'   )r.   r;   r&   r   )r   r?   r@   )rA   rB   rC   rD   r.   r;   rE   rF   rG   rH   r&   r'   )r   rQ   rR   Nr   )rS   r   rT   r   r.   r;   rE   rF   rG   rH   rU   r#   rV   rH   r&   r'   )r   r?   rc   r   )rd   re   rf   rg   r.   r;   rE   rF   rG   rH   rh   rH   r&   r'   )r   rQ   )rS   r   rT   r   ri   rj   r.   r;   rE   rF   r&   r'   )F)rn   rF   ro   r   r&   r'   )r&   rr   )r   N)rz   rF   r.   r;   rE   r#   r&   r'   )r   r|   r}   F)rS   r   rT   r   ri   r   r.   r;   rE   rF   r~   rF   r   r   r&   r'   )__name__
__module____qualname____doc____annotations__r1   r5   r:   r>   rA   rb   rd   rm   rq   rx   ry   rz   r   r/   r/   r/   r0   r      sT   
 


	!3$

r   c                      s*   e Zd ZdZ			dd fddZ  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                   sh   ddddddd}t  j|||dd|d | jD ]}|d |d |g  |g  qd| _d S )	Ng{Gz?gGz?)leftrighttopbottomZwspaceZhspaceTZAgg)r!   r"   r$           F)superr1   r   Zset_xmarginZset_ymarginZ
set_xticksZ
set_yticksr   )r,   r   r   r   Zgridspecr.   	__class__r/   r0   r1   ?  s    




zMplTestRenderer.__init__)r   r   r   )r   r   r   r   r   r    r&   r'   )r   r   r   r   r1   __classcell__r/   r/   r   r0   r   9  s    r   c                      s   e Zd ZdZ				dEdF fddZdGddZ							 	!dHdI fd+d,Z			-			 	!dJdK fd3d4Z		 dLdMd9d:Z		;dNdMd<d=Z		>		?dOdPdCdDZ
  ZS )Q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                   s   t  |||| d S r<   )r   r1   )r,   r   r   r   r!   r   r/   r0   r1   `  s   zMplDebugRenderer.__init__r.   r   
line_startcpy.CoordinateArrayline_endrE   rF   rG   rH   
arrow_sizec                 C  s   d||  }|| }|t t || }t |d |d  f}	t ||d |	 |  ||d |  ||d |	 |  f}
|j|
d d df |
d d df d||d d S )Ng      ?r   r   -rk   rG   )r^   sqrtdotr   r_   r\   )r,   r.   r   r   rE   rG   r   midZalongr   arrowr/   r/   r0   _arrowi  s   	0zMplDebugRenderer._arrowr   C1r@   r?   redrR   rA   rB   rC   rD   r;   
line_color
line_alpharU   start_point_colorc                   s  t |}t ||||| |d u r|d u rd S | |}t||tj}|d ur{t| D ]N\}}|d u r5q,t|D ]@\}}||| }|j	|d d df |d d df ||d |
dkryt
|}t|d D ]}| ||| ||d  |||
 qfq9q,|d urt| D ]d\}}|d u rqtj|d td}d||dd  d < |	d ur|d d }d||< |j	|d d df | |d d df | d||d |	d ur|j	|d d df | |d d df | d|	|d qd S d S )	Nr   r   r   r   rW   r   FrY   )r   r   rA   r>   r	   r   ZChunkCombinedOffsetzipr   r\   r8   r   r   r^   Zonesr   )r,   rA   rC   r.   rE   rG   r   r   rU   r   r   ZpointsoffsetsstartendZxysnr   rm   Zstart_indicesr   r/   r0   rA   }  sL   
*"
**zMplDebugRenderer.filledrc   rd   re   rf   rg   rh   c
              
     sT  t |}t |||||| |	dkr|d u rd S | |}t||tj}
tr-tt	j
|
}
|	dkrQ|
D ]}tt|d D ]}| ||| ||d  |||	 q=q3|d ur|
D ]P}d}t|}|d ur|j|d |d d||d d}|d d |d d kr|d d |d d kr|d8 }|j|||df |||df d||d qWd S d S )	Nr   r   r   )r   r   )r   r   rY   r   rW   )r   r   rd   r>   r
   r   ZSeparater   r   cpyZLineReturn_Separater   r8   r   r\   )r,   rd   rf   r.   rE   rG   rh   rU   r   r   Zseparate_linesliner   start_indexZ	end_indexr   r/   r0   rd     s6   
"0"zMplDebugRenderer.linesrS   r   rT   ri   c                 C  s   |  |}| ||\}}t|}|j\}}t|D ]%}t|D ]}	|	||  }
|j|||	f |||	f t|
dd|dd q!qd S )Nr   r   Tr   r>   r[   r^   r   r   r   r   rF   )r,   rS   rT   ri   r.   rE   r   r   r   r   quadr/   r/   r0   point_numbers  s   


$zMplDebugRenderer.point_numbersbluec                 C  s   |  |}| ||\}}t|}|j\}}td|D ]F}td|D ]>}	|	||  }
||d |d |	d |	d f  }||d |d |	d |	d f  }|j||t|
dd|dd q#qd S )Nr   r   Tr   )	r>   r[   r^   r   r   r   r   r   rF   )r,   rS   rT   ri   r.   rE   r   r   r   r   r   r`   ra   r/   r/   r0   quad_numbers  s   


((zMplDebugRenderer.quad_numbersNr|   lower_levelupper_levelfloat | Nonec                 C  s   |  |}| ||\}}t|}|j\}}	t|D ]9}
t|	D ]2}||
|f }|d ur4||kr4d}n	||kr;d}nd}|j||
|f ||
|f t|dd|dd q!qd S )Nr   r   r   r   r   Tr   r   )r,   rS   rT   ri   r   r   r.   rE   r   r   r   r   r   Zz_levelr/   r/   r0   z_levels  s"   



$zMplDebugRenderer.z_levels)r   r   r   T)
r   r   r   r   r   r    r!   r   r&   r'   )r.   r   r   r   r   r   rE   rF   rG   rH   r   rH   r&   r'   )r   r   r@   r?   r@   r?   r   rR   )rA   rB   rC   rD   r.   r;   rE   rF   rG   rH   r   rF   r   rH   rU   rF   r   rF   r   rH   r&   r'   )r   r?   rc   r   r?   r   rR   )rd   re   rf   rg   r.   r;   rE   rF   rG   rH   rh   rH   rU   rF   r   rF   r   rH   r&   r'   )r   r   )rS   r   rT   r   ri   r   r.   r;   rE   rF   r&   r'   )r   r   )Nr   r|   )rS   r   rT   r   ri   r   r   rH   r   r   r.   r;   rE   rF   r&   r'   )r   r   r   r   r1   r   rA   rd   r   r   r   r   r/   r/   r   r0   r   Z  sF    
	9-r   )-
__future__r   rt   	itertoolsr   typingr   r   r   Zmatplotlib.collectionscollectionsrL   Zmatplotlib.pyplotZpyplotr*   numpyr^   Z	contourpyr   r   Zcontourpy.convertr	   r
   Zcontourpy.enum_utilr   r   Zcontourpy.util.mpl_utilr   r   Zcontourpy.util.rendererr   collections.abcr   Zmatplotlib.axesr   Zmatplotlib.figurer   Znumpy.typingr   Zcontourpy._contourpyZ
_contourpyr   r   r   r   r/   r/   r/   r0   <module>   s.       !