U
    Âmœdn  ã                   @   s@   d dl ZddlmZmZ ddlmZ d
dd„ZG dd	„ d	ƒZdS )é    Né   )Úmake_axes_locatableÚSize)ÚAxesç{®Gáz„?c              	   K   sn  t | ƒ}|t | ¡ }dd|  d t | ¡ }dd|  d t | ¡ }| t | ¡||g¡ | |||||g¡ |  |jdddd�¡ g }|dkržt| ƒ}dD ]¨}	||  	¡ | j
d	d
�f| | dœ|—Ž}
|jd|	d�}|
 |¡ |
j ¡ |
j ¡  D ]}| d¡ qöz"|
j ¡ D ]}|j d¡ �qW n tk
�r>   Y nX | |
¡ q¢|  	¡ }|D ]}
| |
¡ �qX|S )a¦  
    Parameters
    ----------
    ax : `~matplotlib.axes.Axes`
        Axes instance to create the RGB Axes in.
    pad : float, optional
        Fraction of the Axes height to pad.
    axes_class : `matplotlib.axes.Axes` or None, optional
        Axes class to use for the R, G, and B Axes. If None, use
        the same class as *ax*.
    **kwargs :
        Forwarded to *axes_class* init for the R, G, and B Axes.
    r   é   é   r   éÿÿÿÿ)Zny1N)é   r   r   T)Úoriginal)ZsharexZsharey)ÚnxÚnyF)r   r   ZAxesYZAxesXZset_horizontalZset_verticalZset_axes_locatorZnew_locatorÚtypeÚ
get_figureZget_positionZyaxisZget_ticklabelsZxaxisZset_visibleÚaxisÚvaluesZmajor_ticklabelsÚAttributeErrorÚappendÚadd_axes)ÚaxÚpadÚ
axes_classÚkwargsÚdividerZpad_sizeZxsizeZysizeZax_rgbr   Úax1ÚlocatorÚtr   Zfig© r   úY/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/mpl_toolkits/axes_grid1/axes_rgb.pyÚmake_rgb_axes   s>     ÿÿ
r   c                   @   s*   e Zd ZdZeZddœdd„Zdd„ ZdS )	ÚRGBAxesu°  
    4-panel `~.Axes.imshow` (RGB, R, G, B).

    Layout::

        â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”¬â”€â”€â”€â”€â”€â”�
        â”‚               â”‚  R  â”‚
        â”‚               â”œâ”€â”€â”€â”€â”€â”¤
        â”‚      RGB      â”‚  G  â”‚
        â”‚               â”œâ”€â”€â”€â”€â”€â”¤
        â”‚               â”‚  B  â”‚
        â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”´â”€â”€â”€â”€â”€â”˜

    Subclasses can override the ``_defaultAxesClass`` attribute.
    By default RGBAxes uses `.mpl_axes.Axes`.

    Attributes
    ----------
    RGB : ``_defaultAxesClass``
        The Axes object for the three-channel `~.Axes.imshow`.
    R : ``_defaultAxesClass``
        The Axes object for the red channel `~.Axes.imshow`.
    G : ``_defaultAxesClass``
        The Axes object for the green channel `~.Axes.imshow`.
    B : ``_defaultAxesClass``
        The Axes object for the blue channel `~.Axes.imshow`.
    r   )r   c                O   s˜   |  d| j¡}|||Ž | _}| ¡  |¡ t|f||dœ|—Ž\| _| _| _| j| j| j| jfD ]0}|j	dd… j
 d¡ |j	dd… j d¡ qbdS )aª  
        Parameters
        ----------
        pad : float, default: 0
            Fraction of the Axes height to put as padding.
        axes_class : `~matplotlib.axes.Axes`
            Axes class to use. If not provided, ``_defaultAxesClass`` is used.
        *args
            Forwarded to *axes_class* init for the RGB Axes
        **kwargs
            Forwarded to *axes_class* init for the RGB, R, G, and B Axes
        r   )r   r   NÚw)ÚpopÚ_defaultAxesClassÚRGBr   r   r   ÚRÚGÚBr   ÚlineZ	set_colorZmajor_ticksZset_markeredgecolor)Úselfr   Úargsr   r   r   r   r   r   r   Ú__init__[   s    ÿ ÿÿzRGBAxes.__init__c                 K   sú   |j |j   kr|j ks>n td|j › d|j › d|j › d�ƒ‚t |||g¡}t |¡}||dd…dd…df< t |¡}||dd…dd…df< t |¡}||dd…dd…df< | jj|f|Ž}	| jj|f|Ž}
| jj|f|Ž}| j	j|f|Ž}|	|
||fS )aË  
        Create the four images {rgb, r, g, b}.

        Parameters
        ----------
        r, g, b : array-like
            The red, green, and blue arrays.
        **kwargs :
            Forwarded to `~.Axes.imshow` calls for the four images.

        Returns
        -------
        rgb : `~matplotlib.image.AxesImage`
        r : `~matplotlib.image.AxesImage`
        g : `~matplotlib.image.AxesImage`
        b : `~matplotlib.image.AxesImage`
        zInput shapes (z, z) do not matchNr   r   r   )
ÚshapeÚ
ValueErrorÚnpZdstackZ
zeros_liker$   Zimshowr%   r&   r'   )r)   ÚrÚgÚbr   r$   r%   r&   r'   Zim_rgbZim_rZim_gZim_br   r   r   Ú
imshow_rgbr   s     ÿ


zRGBAxes.imshow_rgbN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r#   r+   r2   r   r   r   r   r    <   s   r    )r   N)	Únumpyr.   Zaxes_dividerr   r   Zmpl_axesr   r   r    r   r   r   r   Ú<module>   s   
5