o
    hN                     @  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   squeezesharexshareyr$   aspectequal
subplot_kwoff)	
matplotlibusepltsubplotsr   flattenr   axisr   )selfr   r   r   r!   r"   r$   mplkwargsaxesax r:   o/var/www/html/construction_image-detection-poc/venv/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   )hasattrr1   closer   r5   r:   r:   r;   __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)tightr   )r   getattrautoscale_viewrA   r   lenr   tight_layoutr5   r9   r:   r:   r;   
_autoscaleL   s   
zMplRenderer._autoscaler9   
Axes | intr   c                 C  s   t |tr
| j| }|S N)
isinstancer   r   rG   r:   r:   r;   _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   
facecolors
edgecolorslwrU   TN)r   rL   r   mcollectionsPathCollectionadd_collectionrA   )r5   rO   rQ   r9   rS   rU   paths
collectionr:   r:   r;   rO   \   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.
        )rS   rU   r   g      ?Nr   rU   )   rg   o)rS   rU   markerr[   T)rL   _grid_as_2dplotTnpstackreshaperA   )r5   rc   rd   r9   rS   rU   re   rf   r7   xmidymidr:   r:   r;   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``.
        rW   rX   TN)r   rL   r   r\   r]   r^   rA   )	r5   ru   rw   r9   rS   rU   ry   r_   r`   r:   r:   r;   ru      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"``.
        Nri   )c)rn   magetmasknomaskrL   rk   rl   )r5   rc   rd   rz   r9   rS   maskr:   r:   r;   r      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``.
        )r   N)rH   r   savefig)r5   r   r   r:   r:   r;   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.
        png)formatr   )rH   ioBytesIOr   r   seek)r5   bufr:   r:   r;   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)rH   r1   showr?   r:   r:   r;   r      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.
        )rS   N)rL   	set_title)r5   r   r9   rS   r:   r:   r;   r      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havarS   clip_onr      dtypeN)	rL   rk   rn   asarrayshaperangetextmeanfloat64)r5   rc   rd   rz   r9   rS   r   r   nynxjixxyyzzr:   r:   r;   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'   )r9   rI   r&   r   )r   rM   rN   )rO   rP   rQ   rR   r9   rI   rS   rT   rU   rV   r&   r'   )r   ra   rb   Nr   )rc   r   rd   r   r9   rI   rS   rT   rU   rV   re   r#   rf   rV   r&   r'   )r   rM   rt   r   )ru   rv   rw   rx   r9   rI   rS   rT   rU   rV   ry   rV   r&   r'   )r   ra   )rc   r   rd   r   rz   r{   r9   rI   rS   rT   r&   r'   )F)r   rT   r   r   r&   r'   )r&   r   )r   N)r   rT   r9   rI   rS   r#   r&   r'   )r   r   r   F)rc   r   rd   r   rz   r   r9   rI   rS   rT   r   rT   r   r   r&   r'   )__name__
__module____qualname____doc____annotations__r<   r@   rH   rL   rO   rs   ru   r   r   r   r   r   r   r:   r:   r:   r;   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bottomwspacehspaceTAgg)r!   r"   r$           F)superr<   r   set_xmarginset_ymargin
set_xticks
set_yticksr   )r5   r   r   r   gridspecr9   	__class__r:   r;   r<   ?  s    




zMplTestRenderer.__init__)r   r   r   )r   r   r   r   r   r    r&   r'   )r   r   r   r   r<   __classcell__r:   r:   r   r;   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 rJ   )r   r<   )r5   r   r   r   r!   r   r:   r;   r<   `  s   zMplDebugRenderer.__init__r9   r   
line_startcpy.CoordinateArrayline_endrS   rT   rU   rV   
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   -r|   rU   )rn   sqrtdotr   ro   rl   )r5   r9   r   r   rS   rU   r   midalongr   arrowr:   r:   r;   _arrowi  s   	0zMplDebugRenderer._arrowr   C1rN   rM   redrb   rO   rP   rQ   rR   rI   
line_color
line_alphare   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   rg   r   Fri   )r   r   rO   rL   r	   r   ChunkCombinedOffsetzipr   rl   rE   r   r   rn   onesr   )r5   rO   rQ   r9   rS   rU   r   r   re   r   r   pointsoffsetsstartendxysnr   r   start_indicesr   r:   r;   rO   }  sL   
*"
**zMplDebugRenderer.filledrt   ru   rv   rw   rx   ry   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   ri   r   rg   )r   r   ru   rL   r
   r   Separater   r   cpyLineReturn_Separater   rE   r   rl   )r5   ru   rw   r9   rS   rU   ry   re   r   r   separate_linesliner   start_index	end_indexr   r:   r;   ru     s6   
"0"zMplDebugRenderer.linesrc   r   rd   rz   c                 C  s   |  |}| ||\}}t|}|j\}}t|D ]%}t|D ]}	|	||  }
|j|||	f |||	f t|
dd|dd q!qd S )Nr   r   Tr   rL   rk   rn   r   r   r   r   rT   )r5   rc   rd   rz   r9   rS   r   r   r   r   quadr:   r:   r;   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   )	rL   rk   rn   r   r   r   r   r   rT   )r5   rc   rd   rz   r9   rS   r   r   r   r   r   rq   rr   r:   r:   r;   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   )r5   rc   rd   rz   r   r   r9   rS   r   r   r   r   r   z_levelr:   r:   r;   z_levels  s"   



$zMplDebugRenderer.z_levels)r   r   r   T)
r   r   r   r   r   r    r!   r   r&   r'   )r9   r   r   r   r   r   rS   rT   rU   rV   r   rV   r&   r'   )r   r   rN   rM   rN   rM   r   rb   )rO   rP   rQ   rR   r9   rI   rS   rT   rU   rV   r   rT   r   rV   re   rT   r   rT   r   rV   r&   r'   )r   rM   rt   r   rM   r   rb   )ru   rv   rw   rx   r9   rI   rS   rT   rU   rV   ry   rV   re   rT   r   rT   r   rV   r&   r'   )r   r   )rc   r   rd   r   rz   r   r9   rI   rS   rT   r&   r'   )r   r   )Nr   r   )rc   r   rd   r   rz   r   r   rV   r   r   r9   rI   rS   rT   r&   r'   )r   r   r   r   r<   r   rO   ru   r   r   r   r   r:   r:   r   r;   r   Z  sF    
	9-r   )-
__future__r   r   	itertoolsr   typingr   r   r   matplotlib.collectionscollectionsr\   matplotlib.pyplotpyplotr1   numpyrn   	contourpyr   r   contourpy.convertr	   r
   contourpy.enum_utilr   r   contourpy.util.mpl_utilr   r   contourpy.util.rendererr   collections.abcr   matplotlib.axesr   matplotlib.figurer   numpy.typingr   contourpy._contourpy
_contourpyr   r   r   r   r:   r:   r:   r;   <module>   s.       !