U
    Evfn                     @   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{Gz?c              	   K   sn  t | }|t|  }dd|  d t|  }dd|  d t|  }|t| ||g ||||||g | |jdddd g }|dkrt| }dD ]}	|| 	 | j
d	d
f| | d|}
|jd|	d}|
| |
j |
j  D ]}|d qz"|
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)ZnxnyF)r   r   ZAxesYZAxesXZset_horizontalZset_verticalZset_axes_locatorZnew_locatortype
get_figure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   D/tmp/pip-unpacked-wheel-7vhvci0g/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)	Znumpyr.   Zaxes_dividerr   r   Zmpl_axesr   r   r    r   r   r   r   <module>   s   
5