o
    i2\                     @   s   d dl mZ d dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ ddlmZmZmZ ddlmZ dd	 ZG d
d dZG dd deeZG dd dZG dd deZeZdS )    )NumberN)cbook)SubplotSpec   )SizeSubplotDividerDivider)Axesc                 C   s8   | }| }| j d j||d | j d j||d d S )Nbottom
ticklabelslabelleft)axistoggle)ax	bottom_onleft_on
bottom_offleft_off r   \/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/mpl_toolkits/axes_grid1/axes_grid.py
_tick_only   s   r   c                       sp   e Zd Z fddZeddddddd	Zejd
ddZejd
ddZ	dd Z
dd Z fddZ  ZS )CbarAxesBasec                   s(   || _ d| _d | _t j|i | d S )NT)orientation_default_label_on_locatorsuper__init__)selfr   argskwargs	__class__r   r   r      s   zCbarAxesBase.__init__3.2locatorticksN)r&   c                K   s   | j dv rd}nd}tjd rDtjddd |d u rtd}d	d
lm} || |f||d|}|j	
d|j| _||_|j | _ntjj| |f||d|}|j| _|j| _|   |S )Ntopr
   
horizontalverticalzmpl_toolkits.legacy_colorbarr$   zSince %(since)s, mpl_toolkits's own colorbar implementation is deprecated; it will be removed %(removal)s.  Set the 'mpl_toolkits.legacy_colorbar' rcParam to False to use Matplotlib's default colorbar implementation and suppress this deprecation warning.)message   r   )Colorbar)r   r&   changed)r   mplrcParamsr   warn_deprecatedtickerMaxNLocatorcolorbarr-   callbacksSMconnectupdate_normal_cbid	cbar_axisget_major_locatorr   colorbar_factorycolorbar_cidr%   _config_axes)r   mappabler&   r!   r   r-   cbr   r   r   r4      sB   


zCbarAxesBase.colorbar3.3zmappable.colorbar_cid)alternativez.colorbar().locatorc                 C   sB   | }| d |jdd jdd | j}|j| j j|d dS )zMake an axes patch and outline.FN)all)set_navigater   r   r   r   )r   r   br   r   r   r=   C   s
   
zCbarAxesBase._config_axesc                 C   s$   || _ | j| j }|j||d d S )Nr   )r   r   r   r   )r   rD   r   r   r   r   toggle_labelK   s   zCbarAxesBase.toggle_labelc                    s   t    |   d S N)r   clar=   r   r"   r   r   rG   P   s   
zCbarAxesBase.cla)__name__
__module____qualname__r   r   _rename_parameterr4   _deprecate_privatize_attributecbidr%   r=   rE   rG   __classcell__r   r   r"   r   r      s     r   c                   @   s   e Zd ZdS )CbarAxesN)rI   rJ   rK   r   r   r   r   rP   U   s    rP   c                   @   s   e Zd ZdZeZe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'd( ZdS )*Gridaq  
    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.
    r@   add_allNrow{Gz?TFL)aspectc                C   s>  |\| _ | _|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tfrzt||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 d | _'| (  |r| j#D ]}|)| q| *| dS )ai  
        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").
        axes_pad : float or (float, float), default: 0.02
            Padding or (horizontal padding, vertical padding) between axes, in
            inches.
        add_all : bool, default: True
            Whether to add the axes to the figure using `.Figure.add_axes`.
            This parameter is deprecated.
        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"}, 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.

        axes_class : subclass of `matplotlib.axes.Axes`, default: None
        aspect : bool, default: False
            Whether the axes aspect ratio follows the aspect ratio of the data
            limits.
        Nr       columnrS   )	direction)r)   r*   rV         )dtype)r   r   )sharexsharey)+_nrows_ncols	Exceptionngridsmapr   Fixednpbroadcast_to_horiz_pad_size_vert_pad_sizer   _check_in_list
_direction_defaultAxesClass
isinstancelisttuple	functoolspartialdictstrr   r   r   _dividerlenr   get_positionfullobjectrange_get_col_rowraveltolistaxes_allTaxes_columnaxes_rowaxes_llc_init_locatorsadd_axesset_label_mode)r   figrectnrows_ncolsrd   rZ   axes_padrR   	share_allshare_xshare_y
label_mode
axes_classrV   clsr!   kw
axes_arrayicolrS   r^   r_   r   r   r   r   r   f   s\   9


zGrid.__init__c                 C   s   g }g }t | jD ]}|r|| j |t| td}|| q	g }g }t | jD ]}|r8|| j |t| td}|| q.t | j	D ]"}| 
|\}}	| jj|| || jd |	  d}
| j| |
 qO| j| | j| d S )Nr   nxny)rz   rb   appendri   rv   r   Scaledra   rj   rd   r{   ru   new_locatorr~   set_axes_locatorset_horizontalset_vertical)r   hh_ax_pos_szvv_ax_posr   r   rS   r%   r   r   r   r      s0   

zGrid._init_locatorsc                 C   s:   | j dkrt|| j\}}||fS t|| j\}}||fS )NrY   )rl   divmodra   rb   )r   nr   rS   r   r   r   r{      s
   
zGrid._get_col_rowc                 C   s
   t | jS rF   )rv   r~   rH   r   r   r   __len__      
zGrid.__len__c                 C   s
   | j | S rF   )r~   )r   r   r   r   r   __getitem__  r   zGrid.__getitem__c                 C   s   | j | jfS )zV
        Return the number of rows and columns of the grid as (nrows, ncols).
        )ra   rb   rH   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ri   
fixed_sizerj   )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.
        r   rH   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)ru   
set_aspect)r   rV   r   r   r   r   "  s   zGrid.set_aspectc                 C   
   | j  S )z(Return the aspect of the SubplotDivider.)ru   
get_aspectrH   r   r   r   r   &  s   
zGrid.get_aspectc                 C   s   |dkr| j D ]}t|dd qdS |dkr^| jd dd D ]	}t|ddd q| jd d }t|ddd | jd	d D ]}|dd D ]	}t|ddd qF|d }t|ddd q>dS |d
kr{| j D ]	}t|ddd qe| j}t|ddd dS dS )a  
        Define which axes have tick labels.

        Parameters
        ----------
        mode : {"L", "1", "all"}
            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.
        rB   FrU   r   Nr`   T)r   r   r   1)r~   r   r   r   )r   moder   r   r   r   r   r   *  s*   
	
zGrid.set_label_modec                 C   s   | j S rF   )ru   rH   r   r   r   get_dividerS  s   zGrid.get_dividerc                 C   s   | j | d S rF   )ru   set_locator)r   r%   r   r   r   r   V  s   zGrid.set_axes_locatorc                 C   r   rF   )ru   get_locatorrH   r   r   r   get_axes_locatorY  r   zGrid.get_axes_locatorc                 C   r   rF   )ru   get_vsize_hsizerH   r   r   r   r   \  r   zGrid.get_vsize_hsize)	NrS   rT   TFTTrU   N)rI   rJ   rK   __doc__r	   rm   r   _delete_parameterr   r   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rQ   Y   s<    

q	)rQ   c                       sP   e Zd ZeZedd												
		d fdd	Zdd Z  Z	S )	ImageGridr@   rR   NrS   rT   TFrU   right5%c                    s&  || _ || _|| _|| _|r!t j|||||||dd|	|
|d nt j||||||||dd|	|
|d |rA| jD ]}|| q9|r| j dkrV| jD ]}| jd |_	qKdS | j dkrt
| jD ]\}}| |\}}| jdv rw| j| |_	q`| j| |_	q`d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.
        add_all : bool, default: True
            Whether to add the axes to the figure using `.Figure.add_axes`.
            This parameter is deprecated.
        share_all : bool, default: False
            Whether all axes share their x- and 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.
        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
        T)rZ   r   r   r   r   rV   r   r   )	rZ   r   rR   r   r   r   rV   r   r   singler   edger   r   N)_colorbar_mode_colorbar_location_colorbar_pad_colorbar_sizer   r   	cbar_axesr   r~   cax	enumerater{   zip)r   r   r   r   rd   rZ   r   rR   r   rV   r   	cbar_modecbar_locationcbar_pad	cbar_sizecbar_set_caxr   r   indexr   rS   r   r"   r   r   r   e  sH   D




zImageGrid.__init__c                    sh   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 ]\}
}|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rH|dks-|dkrH|
 jd krH|t
 j | |t| |t
 j| qg }g }t jd d d d D ]\}}|rf| j |rut
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| qYt jD ]}	 |	\}
} jj||
 | j	d |  d} j|	 | |dkrU|dv r5 jj||
 | j	d |  d}n|dv rK jj||
 | j	d |  d} j|	 | q|dkr|dkrd|
dksq|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rSt jD ]}	 j|	 d qFnS|dkr|dv ra j	}n j}t|D ]}	 j|	 d qht|	d  jD ]} j| d q|nt jD ]}	 j|	 d  j|	 jg ddd q j|  j| d S )Nr   c                    s,   g | ]} j  jd  j j  jdqS )r   )r   )_defaultCbarAxesClassr~   figureru   rw   r   ).0r   rH   r   r   
<listcomp>  s    z,ImageGrid._init_locators.<locals>.<listcomp>r   )r   r
   r   r   r`   )r   r   ny1r
   )r   nx1r   FTaxes)rV   ref_axeachr   r   r   r(   r   )r   r   r'   )r   r(   )      ?r   MbP?r   active)which)r   r   ri   r   rj   rz   rd   r   r   ra   r   AxesXr   r   from_anyr   ru   r   rb   AxesYset_visibler   r   r   r~   rv   r   r{   set_positionr   r   )r   cb_modecb_locationr   r   r   h_cb_posr   r%   r   r   r   r   v_cb_posrS   countjr   rH   r   r     s  








 

















zImageGrid._init_locators)NrS   rT   TFTrU   Nr   Nr   TN)
rI   rJ   rK   rP   r   r   r   r   r   rO   r   r   r"   r   r   `  s$    
ir   )numbersr   rq   numpyrg   
matplotlibr/   r   matplotlib.tickerr2   matplotlib.gridspecr   axes_dividerr   r   r   mpl_axesr	   r   r   rP   rQ   r   AxesGridr   r   r   r   <module>   s&    ?  	  