o
    jHW                     @   s   d dl mZ d dlZd dlmZ d dlZd dlmZm	Z	 d dl
mZ ddlmZmZmZ ddlmZmZ G d	d
 d
Ze	edZG dd dZG dd deZeZdS )    )NumberN)
MethodType)_apicbook)SubplotSpec   )SizeSubplotDividerDivider)AxesSimpleAxisArtistc                       s$   e Zd Z fddZdd Z  ZS )CbarAxesBasec                   s   || _ t j|i | d S N)orientationsuper__init__)selfr   argskwargs	__class__ b/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.pyr      s   zCbarAxesBase.__init__c                 K   s"   | j ddj|f| | jd|S )NFroot)caxlocation)
get_figurecolorbarr   )r   Zmappabler   r   r   r   r      s   zCbarAxesBase.colorbar)__name__
__module____qualname__r   r   __classcell__r   r   r   r   r      s    r   zCbar{}c                   @   s   e Zd ZdZeZ			d%dddddddd	d
Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ ZdS )&GridaL  
    A grid of Axes.

    In Matplotlib, the Axes location (and size) is specified in normalized
    figure coordinates. This may not be ideal for images that needs to be
    displayed with a given aspect ratio; for example, it is difficult to
    display multiple images of a same size with some fixed padding between
    them.  AxesGrid can be used in such case.

    Attributes
    ----------
    axes_all : list of Axes
        A flat list of Axes. Note that you can also access this directly
        from the grid. The following is equivalent ::

            grid[i] == grid.axes_all[i]
            len(grid) == len(grid.axes_all)

    axes_column : list of list of Axes
        A 2D list of Axes where the first index is the column. This results
        in the usage pattern ``grid.axes_column[col][row]``.
    axes_row : list of list of Axes
        A 2D list of Axes where the first index is the row. This results
        in the usage pattern ``grid.axes_row[row][col]``.
    axes_llc : Axes
        The Axes in the lower left corner.
    ngrids : int
        Number of Axes in the grid.
    Nrow{Gz?FTL)	share_allshare_xshare_y
label_mode
axes_classaspectc                C   sH  |\| _ | _|du r| j | j }nd|  k r"| j | j ks'td td|| _ttjt|d\| _	| _
tjddg|d || _|du rL| j}nt|ttfr`|\}}tj|fi |}tg g |d}t|ttfryt||fi || _n(t|d	krt|g|R i || _nt|d
krt||fi || _ntd| j }tj| j | jfdtd}t| jD ]2}|  |\}}|r|d  }}n|r|d|f nd}|	r||df nd}|||||d|||f< q|j!| jdkrdndd" | _#|j$" | _%|" | _&| j%d d | _'| (  | j#D ]}|)| q| *|
 dS )a  
        Parameters
        ----------
        fig : `.Figure`
            The parent figure.
        rect : (float, float, float, float), (int, int, int), int, or     `~.SubplotSpec`
            The axes position, as a ``(left, bottom, width, height)`` tuple,
            as a three-digit subplot position code (e.g., ``(1, 2, 1)`` or
            ``121``), or as a `~.SubplotSpec`.
        nrows_ncols : (int, int)
            Number of rows and columns in the grid.
        ngrids : int or None, default: None
            If not None, only the first *ngrids* axes in the grid are created.
        direction : {"row", "column"}, default: "row"
            Whether axes are created in row-major ("row by row") or
            column-major order ("column by column").  This also affects the
            order in which axes are accessed using indexing (``grid[index]``).
        axes_pad : float or (float, float), default: 0.02
            Padding or (horizontal padding, vertical padding) between axes, in
            inches.
        share_all : bool, default: False
            Whether all axes share their x- and y-axis.  Overrides *share_x*
            and *share_y*.
        share_x : bool, default: True
            Whether all axes of a column share their x-axis.
        share_y : bool, default: True
            Whether all axes of a row share their y-axis.
        label_mode : {"L", "1", "all", "keep"}, default: "L"
            Determines which axes will get tick labels:

            - "L": All axes on the left column get vertical tick labels;
              all axes on the bottom row get horizontal tick labels.
            - "1": Only the bottom left axes is labelled.
            - "all": All axes are labelled.
            - "keep": Do not do anything.

        axes_class : subclass of `matplotlib.axes.Axes`, default: `.mpl_axes.Axes`
            The type of Axes to create.
        aspect : bool, default: False
            Whether the axes aspect ratio follows the aspect ratio of the data
            limits.
        Nr   z7ngrids must be positive and not larger than nrows*ncols   columnr$   )	direction)
horizontalverticalr,         zIncorrect rect format)Zdtype)r   r   )sharexshareyCF)order)+_nrows_ncols
ValueErrorngridsmapr   ZFixednpZbroadcast_to_horiz_pad_size_vert_pad_sizer   check_in_list
_direction_defaultAxesClass
isinstancelisttuple	functoolspartialdictr   r   r	   _dividerlenr
   	TypeErrorget_positionfullobjectrange_get_col_rowZraveltolistaxes_allTaxes_columnaxes_rowaxes_llc_init_locatorsadd_axesset_label_mode)r   figrectnrows_ncolsr=   r/   axes_padr'   r(   r)   r*   r+   r,   clsr   kwZ
axes_arrayicolr$   r4   r5   axr   r   r   r   <   sj   9


zGrid.__init__c                 C   s   | j td| jg| jd  tdg  | j td| jg| jd  tdg  t	| j
D ] }| |\}}| j| | j jd| d| jd |  d q3d S )Nr   r-   nxny)rK   set_horizontalr   ZScaledr@   r;   set_verticalrA   r:   rQ   r=   rR   rT   set_axes_locatornew_locator)r   rb   rc   r$   r   r   r   rY      s   $$
 zGrid._init_locatorsc                 C   s:   | j dkrt|| j\}}||fS t|| j\}}||fS )Nr.   )rC   divmodr:   r;   )r   nrc   r$   r   r   r   rR      s
   
zGrid._get_col_rowc                 C   s
   t | jS r   )rL   rT   r   r   r   r   __len__      
zGrid.__len__c                 C   s
   | j | S r   )rT   )r   rb   r   r   r   __getitem__   rp   zGrid.__getitem__c                 C   s   | j | jfS )zV
        Return the number of rows and columns of the grid as (nrows, ncols).
        )r:   r;   rn   r   r   r   get_geometry   s   zGrid.get_geometryc                 C   s   |d | j _|d | j_dS )z
        Set the padding between the axes.

        Parameters
        ----------
        axes_pad : (float, float)
            The padding (horizontal pad, vertical pad) in inches.
        r   r   Nr@   
fixed_sizerA   )r   r_   r   r   r   set_axes_pad   s   	zGrid.set_axes_padc                 C   s   | j j| jjfS )z
        Return the axes padding.

        Returns
        -------
        hpad, vpad
            Padding (horizontal pad, vertical pad) in inches.
        rs   rn   r   r   r   get_axes_pad   s   	zGrid.get_axes_padc                 C   s   | j | dS )z%Set the aspect of the SubplotDivider.N)rK   
set_aspect)r   r,   r   r   r   rw      s   zGrid.set_aspectc                 C   
   | j  S )z(Return the aspect of the SubplotDivider.)rK   
get_aspectrn   r   r   r   ry      s   
zGrid.get_aspectc                 C   sL  t jg d|d tjd| jd| jf | jd ggdgggk\}}|dkr4t| j| jfd }}n|dkr=|}|}n|d	krH||@  }}ndS t| jD ]T}t| jD ]L}| j| | }t	|j
trzt|jd|jd
 }	t|jd|jd }
n
|j
d
 }	|j
d }
|	j|||f |||f d |
j|||f |||f d qVqOdS )a  
        Define which axes have tick labels.

        Parameters
        ----------
        mode : {"L", "1", "all", "keep"}
            The label mode:

            - "L": All axes on the left column get vertical tick labels;
              all axes on the bottom row get horizontal tick labels.
            - "1": Only the bottom left axes is labelled.
            - "all": All axes are labelled.
            - "keep": Do not do anything.
        )allr&   1Zkeep)modeNr   r   rz   Tr&   r{   bottomleft)Z
ticklabelslabel)r   rB   r?   Zmgridr:   r;   rO   rQ   rW   rE   Zaxisr   r   ZxaxisZspinesZyaxistoggle)r   r|   Zis_last_rowZis_first_colr}   r~   rb   jrd   Zbottom_axisZ	left_axisr   r   r   r[      s.   .

 zGrid.set_label_modec                 C   s   | j S r   )rK   rn   r   r   r   get_divider  s   zGrid.get_dividerc                 C   s   | j | d S r   )rK   Zset_locator)r   locatorr   r   r   rj     s   zGrid.set_axes_locatorc                 C   rx   r   )rK   Zget_locatorrn   r   r   r   get_axes_locator  rp   zGrid.get_axes_locatorNr$   r%   )r   r    r!   __doc__r   rD   r   rY   rR   ro   rq   rr   ru   rv   rw   ry   r[   r   rj   r   r   r   r   r   r#      s6    s
	'r#   c                       sF   e Zd ZdZ			dddddddd	ddd
	 fddZdd Z  ZS )	ImageGridaR  
    A grid of Axes for Image display.

    This class is a specialization of `~.axes_grid1.axes_grid.Grid` for displaying a
    grid of images.  In particular, it forces all axes in a column to share their x-axis
    and all axes in a row to share their y-axis.  It further provides helpers to add
    colorbars to some or all axes.
    Nr$   r%   FTr&   rightz5%)	r'   r,   r*   	cbar_modecbar_locationcbar_pad	cbar_sizecbar_set_caxr+   c       	            s  t jg d|
d t jg d|d |
| _|| _|| _|| _t j|||||||dd||	|d | jD ]}|	| q3|r| jdkrP| j
D ]}| jd |_qEdS | jd	krzt| j
D ]\}}| |\}}| jd
v rq| j| |_qZ| j| |_qZdS t| j
| jD ]	\}}||_qdS dS )a
  
        Parameters
        ----------
        fig : `.Figure`
            The parent figure.
        rect : (float, float, float, float) or int
            The axes position, as a ``(left, bottom, width, height)`` tuple or
            as a three-digit subplot position code (e.g., "121").
        nrows_ncols : (int, int)
            Number of rows and columns in the grid.
        ngrids : int or None, default: None
            If not None, only the first *ngrids* axes in the grid are created.
        direction : {"row", "column"}, default: "row"
            Whether axes are created in row-major ("row by row") or
            column-major order ("column by column").  This also affects the
            order in which axes are accessed using indexing (``grid[index]``).
        axes_pad : float or (float, float), default: 0.02in
            Padding or (horizontal padding, vertical padding) between axes, in
            inches.
        share_all : bool, default: False
            Whether all axes share their x- and y-axis.  Note that in any case,
            all axes in a column share their x-axis and all axes in a row share
            their y-axis.
        aspect : bool, default: True
            Whether the axes aspect ratio follows the aspect ratio of the data
            limits.
        label_mode : {"L", "1", "all"}, default: "L"
            Determines which axes will get tick labels:

            - "L": All axes on the left column get vertical tick labels;
              all axes on the bottom row get horizontal tick labels.
            - "1": Only the bottom left axes is labelled.
            - "all": all axes are labelled.

        cbar_mode : {"each", "single", "edge", None}, default: None
            Whether to create a colorbar for "each" axes, a "single" colorbar
            for the entire grid, colorbars only for axes on the "edge"
            determined by *cbar_location*, or no colorbars.  The colorbars are
            stored in the :attr:`cbar_axes` attribute.
        cbar_location : {"left", "right", "bottom", "top"}, default: "right"
        cbar_pad : float, default: None
            Padding between the image axes and the colorbar axes.

            .. versionchanged:: 3.10
                ``cbar_mode="single"`` no longer adds *axes_pad* between the axes
                and the colorbar if the *cbar_location* is "left" or "bottom".

        cbar_size : size specification (see `.Size.from_any`), default: "5%"
            Colorbar size.
        cbar_set_cax : bool, default: True
            If True, each axes in the grid has a *cax* attribute that is bound
            to associated *cbar_axes*.
        axes_class : subclass of `matplotlib.axes.Axes`, default: None
        )eachsingleedgeN)r   )r~   r   r}   top)r   T)r/   r_   r'   r(   r)   r,   r*   r+   r   r   r   r~   r   N)r   rB   _colorbar_mode_colorbar_location_colorbar_pad_colorbar_sizer   r   	cbar_axesrZ   rT   r   	enumeraterR   zip)r   r\   r]   r^   r=   r/   r_   r'   r,   r*   r   r   r   r   r   r+   rd   indexrc   r$   r   r   r   r   r   )  sD   
G





zImageGrid.__init__c                    sp   j d u r jdv r jj _ n jj _  fddt jD  _ j} j}g }g }g }g }|dkr|dv r|dkrc j	t
 j }|t
 j| |t
 j |  jjdddd	}n*|d
kr jt
 j }|t
 j| |t
 j |  jjdddd}t jD ]
}	 j|	 d q jd |  jd d t jd D ]\}
}|
dkr| j |rt
j|d jd d}nt
j jd d jd d}|dkr|dks|dkr|
dkr|t| |t
 j| |t
 j | |t| || |dkrJ|dks/|dkrJ|
 jd krJ|t
 j | |t| |t
 j| qg }g }t jd d d d D ]\}}|dkrj| j |ryt
j|d jd d}nt
j jd d jd d}|d
kr|dks|dkr|dkr|t| |t
 j| |t
 j | |t| || |dkr|dks|dkr| j	d kr|t
 j | |t| |t
 j| q[t jD ]}	 |	\}
} jj||
 | j	d |  d} j|	 | |dkrY|dv r9 jj||
 | j	d |  d}n|dv rO jj||
 | j	d |  d} j|	 | q|dkr|dkrh|
dksu|dkr|
 jd kr jj|d | j	d |  d} j| | q|d
kr| j	d ks|dkr|dkr jj||
 |d d} j|
 | q|dkr@|dkr j	t
 j }|t
 j | |t
 j|  jjdddd	}n+|dkr jt
 j }|t
 j | |t
 j|  jjdddd}|dv r?t jD ]}	 j|	 d q# jd |  jd d nj|dkrWt jD ]}	 j|	 d qJnS|dkr|dv re j	}n j}t|D ]}	 j|	 d qlt|	d  jD ]} j| d qnt jD ]}	 j|	 d  j|	 jg ddd q j|  j| d S )Nr   c                    s6   g | ]}t  j jd  jdd j  jdqS )r   Fr   )r   )_cbaraxes_class_factoryrD   rT   r   rK   rN   r   ).0_rn   r   r   
<listcomp>  s    z,ImageGrid._init_locators.<locals>.<listcomp>r   )r~   r}   r~   r   r9   )rf   rg   Zny1r}   )rf   Znx1rg   FTZaxes)r,   Zref_axr   r   r   r   r   re   )r   r~   )r   r}   )r   r   )      ?r   MbP?r   Zactive)which)r   r   r@   rt   rA   rQ   r=   r   r   r:   r   ZAxesXrX   appendZfrom_anyr   rK   rk   r;   ZAxesYZset_visiblerj   r   rW   rT   rL   rV   rR   Zset_positionrh   ri   )r   Zcb_modeZcb_locationhvZh_ax_posZh_cb_posszr   rb   rc   rd   Zv_ax_posZv_cb_posr$   countr   r   rn   r   rY     s  








 


















zImageGrid._init_locatorsr   )r   r    r!   r   r   rY   r"   r   r   r   r   r     s"    ir   )numbersr   rH   typesr   numpyr?   Z
matplotlibr   r   Zmatplotlib.gridspecr   Zaxes_dividerr   r	   r
   Zmpl_axesr   r   r   Z_make_class_factoryr   r#   r   ZAxesGridr   r   r   r   <module>   s"    
    