U
    \	a$M                     @   s   d dl mZ d dlmZmZmZmZmZ d dlm	Z	m
Z
mZmZmZ d dlmZ ddddd	gZG d
d deZG dd deZG dd deZG dd deZG dd	 d	eZdS )    )
transforms)AnchoredOffsetboxAuxTransformBoxDrawingAreaTextAreaVPacker)	RectangleEllipse
ArrowStyleFancyArrowPatch	PathPatch)TextPathAnchoredDrawingAreaAnchoredAuxTransformBoxAnchoredEllipseAnchoredSizeBarAnchoredDirectionArrowsc                       s   e Zd Zd fdd	Z  ZS )r   皙?      ?NTc
                    s>   t ||||| _| j| _t j|f||| jd|	d|
 dS )a  
        An anchored container with a fixed size and fillable DrawingArea.

        Artists added to the *drawing_area* will have their coordinates
        interpreted as pixels. Any transformations set on the artists will be
        overridden.

        Parameters
        ----------
        width, height : float
            width and height of the container, in pixels.

        xdescent, ydescent : float
            descent of the container in the x- and y- direction, in pixels.

        loc : int
            Location of this artist. Valid location codes are::

                'upper right'  : 1,
                'upper left'   : 2,
                'lower left'   : 3,
                'lower right'  : 4,
                'right'        : 5,
                'center left'  : 6,
                'center right' : 7,
                'lower center' : 8,
                'upper center' : 9,
                'center'       : 10

        pad : float, default: 0.4
            Padding around the child objects, in fraction of the font size.

        borderpad : float, default: 0.5
            Border padding, in fraction of the font size.

        prop : `matplotlib.font_manager.FontProperties`, optional
            Font property used as a reference for paddings.

        frameon : bool, default: True
            If True, draw a box around this artists.

        **kwargs
            Keyworded arguments to pass to
            :class:`matplotlib.offsetbox.AnchoredOffsetbox`.

        Attributes
        ----------
        drawing_area : `matplotlib.offsetbox.DrawingArea`
            A container for artists to display.

        Examples
        --------
        To display blue and red circles of different sizes in the upper right
        of an axes *ax*:

        >>> ada = AnchoredDrawingArea(20, 20, 0, 0,
        ...                           loc='upper right', frameon=False)
        >>> ada.drawing_area.add_artist(Circle((10, 10), 10, fc="b"))
        >>> ada.drawing_area.add_artist(Circle((30, 10), 5, fc="r"))
        >>> ax.add_artist(ada)
        Npad	borderpadchildpropframeon)r   dadrawing_areasuper__init__)selfwidthheightZxdescentZydescentlocr   r   r   r   kwargs	__class__ L/tmp/pip-unpacked-wheel-wjyw_3jo/mpl_toolkits/axes_grid1/anchored_artists.pyr      s    @   zAnchoredDrawingArea.__init__)r   r   NT__name__
__module____qualname__r   __classcell__r&   r&   r$   r'   r      s
          c                       s   e Zd Zd fdd	Z  ZS )r   r   r   NTc                    s0   t || _t j|f||| j||d| dS )a  
        An anchored container with transformed coordinates.

        Artists added to the *drawing_area* are scaled according to the
        coordinates of the transformation used. The dimensions of this artist
        will scale to contain the artists added.

        Parameters
        ----------
        transform : `matplotlib.transforms.Transform`
            The transformation object for the coordinate system in use, i.e.,
            :attr:`matplotlib.axes.Axes.transData`.

        loc : int
            Location of this artist. Valid location codes are::

                'upper right'  : 1,
                'upper left'   : 2,
                'lower left'   : 3,
                'lower right'  : 4,
                'right'        : 5,
                'center left'  : 6,
                'center right' : 7,
                'lower center' : 8,
                'upper center' : 9,
                'center'       : 10

        pad : float, default: 0.4
            Padding around the child objects, in fraction of the font size.

        borderpad : float, default: 0.5
            Border padding, in fraction of the font size.

        prop : `matplotlib.font_manager.FontProperties`, optional
            Font property used as a reference for paddings.

        frameon : bool, default: True
            If True, draw a box around this artists.

        **kwargs
            Keyworded arguments to pass to
            :class:`matplotlib.offsetbox.AnchoredOffsetbox`.

        Attributes
        ----------
        drawing_area : `matplotlib.offsetbox.AuxTransformBox`
            A container for artists to display.

        Examples
        --------
        To display an ellipse in the upper left, with a width of 0.1 and
        height of 0.4 in data coordinates:

        >>> box = AnchoredAuxTransformBox(ax.transData, loc='upper left')
        >>> el = Ellipse((0, 0), width=0.1, height=0.4, angle=30)
        >>> box.drawing_area.add_artist(el)
        >>> ax.add_artist(box)
        r   N)r   r   r   r   )r   	transformr"   r   r   r   r   r#   r$   r&   r'   r   W   s    <
  z AnchoredAuxTransformBox.__init__)r   r   NTr(   r&   r&   r$   r'   r   V   s
          c                       s   e Zd Zd fdd	Z  ZS )r   皙?NTc
                    sN   t || _td|||| _| j| j t j|f||| j||	d|
 dS )a]  
        Draw an anchored ellipse of a given size.

        Parameters
        ----------
        transform : `matplotlib.transforms.Transform`
            The transformation object for the coordinate system in use, i.e.,
            :attr:`matplotlib.axes.Axes.transData`.

        width, height : float
            Width and height of the ellipse, given in coordinates of
            *transform*.

        angle : float
            Rotation of the ellipse, in degrees, anti-clockwise.

        loc : int
            Location of this size bar. Valid location codes are::

                'upper right'  : 1,
                'upper left'   : 2,
                'lower left'   : 3,
                'lower right'  : 4,
                'right'        : 5,
                'center left'  : 6,
                'center right' : 7,
                'lower center' : 8,
                'upper center' : 9,
                'center'       : 10

        pad : float, optional
            Padding around the ellipse, in fraction of the font size. Defaults
            to 0.1.

        borderpad : float, default: 0.1
            Border padding, in fraction of the font size.

        frameon : bool, default: True
            If True, draw a box around the ellipse.

        prop : `matplotlib.font_manager.FontProperties`, optional
            Font property used as a reference for paddings.

        **kwargs
            Keyworded arguments to pass to
            :class:`matplotlib.offsetbox.AnchoredOffsetbox`.

        Attributes
        ----------
        ellipse : `matplotlib.patches.Ellipse`
            Ellipse patch drawn.
        r   r   r   N)r   _boxr	   Zellipse
add_artistr   r   )r   r-   r    r!   angler"   r   r   r   r   r#   r$   r&   r'   r      s    6
 zAnchoredEllipse.__init__)r.   r.   NTr(   r&   r&   r$   r'   r      s
          c                	       s   e Zd Zd
 fdd		Z  ZS )r   r.      Tr   blackFNc              
      s   |dkr|	dk}t || _| jtd||	||
|
d |dkrPd|krP|d}|dkrbd|
i}n
|
|d}t||d| _|r| j| jg}n| j| jg}t|d	d|d
| _t	 j
|f||| j||d| dS )a  
        Draw a horizontal scale bar with a center-aligned label underneath.

        Parameters
        ----------
        transform : `matplotlib.transforms.Transform`
            The transformation object for the coordinate system in use, i.e.,
            :attr:`matplotlib.axes.Axes.transData`.

        size : float
            Horizontal length of the size bar, given in coordinates of
            *transform*.

        label : str
            Label to display.

        loc : int
            Location of this size bar. Valid location codes are::

                'upper right'  : 1,
                'upper left'   : 2,
                'lower left'   : 3,
                'lower right'  : 4,
                'right'        : 5,
                'center left'  : 6,
                'center right' : 7,
                'lower center' : 8,
                'upper center' : 9,
                'center'       : 10

        pad : float, default: 0.1
            Padding around the label and size bar, in fraction of the font
            size.

        borderpad : float, default: 0.1
            Border padding, in fraction of the font size.

        sep : float, default: 2
            Separation between the label and the size bar, in points.

        frameon : bool, default: True
            If True, draw a box around the horizontal bar and label.

        size_vertical : float, default: 0
            Vertical length of the size bar, given in coordinates of
            *transform*.

        color : str, default: 'black'
            Color for the size bar and label.

        label_top : bool, default: False
            If True, the label will be over the size bar.

        fontproperties : `matplotlib.font_manager.FontProperties`, optional
            Font properties for the label text.

        fill_bar : bool, optional
            If True and if size_vertical is nonzero, the size bar will
            be filled in with the color specified by the size bar.
            Defaults to True if *size_vertical* is greater than
            zero and False otherwise.

        **kwargs
            Keyworded arguments to pass to
            :class:`matplotlib.offsetbox.AnchoredOffsetbox`.

        Attributes
        ----------
        size_bar : `matplotlib.offsetbox.AuxTransformBox`
            Container for the size bar.

        txt_label : `matplotlib.offsetbox.TextArea`
            Container for the label of the size bar.

        Notes
        -----
        If *prop* is passed as a keyworded argument, but *fontproperties* is
        not, then *prop* is be assumed to be the intended *fontproperties*.
        Using both *prop* and *fontproperties* is not supported.

        Examples
        --------
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from mpl_toolkits.axes_grid1.anchored_artists import (
        ...     AnchoredSizeBar)
        >>> fig, ax = plt.subplots()
        >>> ax.imshow(np.random.random((10, 10)))
        >>> bar = AnchoredSizeBar(ax.transData, 3, '3 data units', 4)
        >>> ax.add_artist(bar)
        >>> fig.show()

        Using all the optional parameters

        >>> import matplotlib.font_manager as fm
        >>> fontprops = fm.FontProperties(size=14, family='monospace')
        >>> bar = AnchoredSizeBar(ax.transData, 3, '3 units', 4, pad=0.5,
        ...                       sep=5, borderpad=0.5, frameon=False,
        ...                       size_vertical=0.5, color='white',
        ...                       fontproperties=fontprops)
        Nr   r/   )fillZ	facecolorZ	edgecolorr   color)r6   fontproperties)	textpropscenter)childrenZalignr   sepr   )r   Zsize_barr1   r   popr   Z	txt_labelr   r0   r   r   )r   r-   sizelabelr"   r   r   r;   r   Zsize_verticalr6   Z	label_topr7   Zfill_barr#   r8   Z_box_childrenr$   r&   r'   r      s8    j
 


  zAnchoredSizeBar.__init__)	r.   r.   r3   Tr   r4   FNNr(   r&   r&   r$   r'   r      s                  c                       s   e Zd Zd fdd	Z  ZS )r   333333?{Gz?r3   r      r   Fw{Gz?N
      c                    s  |dkri }|dkri }t d|||d}|dkrBd|krB|d}d|krR||d< d|krb||d< d|krr||d< d|kr||d< |}|t | }t|| _|}|| }td|| f||| ff|ddd	|| _t|| df|| |ff|ddd	|| _	| j
| j | j
| j	 t|| || | f|||d
}t|fd|i|| _| j
| j t|| | |d|  | f|||d
}t|f|| _| j
| j t j|f|	|
| j|d| dS )a  
        Draw two perpendicular arrows to indicate directions.

        Parameters
        ----------
        transform : `matplotlib.transforms.Transform`
            The transformation object for the coordinate system in use, i.e.,
            :attr:`matplotlib.axes.Axes.transAxes`.

        label_x, label_y : str
            Label text for the x and y arrows

        length : float, default: 0.15
            Length of the arrow, given in coordinates of *transform*.

        fontsize : float, default: 0.08
            Size of label strings, given in coordinates of *transform*.

        loc : int, default: 2
            Location of the direction arrows. Valid location codes are::

                'upper right'  : 1,
                'upper left'   : 2,
                'lower left'   : 3,
                'lower right'  : 4,
                'right'        : 5,
                'center left'  : 6,
                'center right' : 7,
                'lower center' : 8,
                'upper center' : 9,
                'center'       : 10

        angle : float, default: 0
            The angle of the arrows in degrees.

        aspect_ratio : float, default: 1
            The ratio of the length of arrow_x and arrow_y.
            Negative numbers can be used to change the direction.

        pad : float, default: 0.4
            Padding around the labels and arrows, in fraction of the font size.

        borderpad : float, default: 0.4
            Border padding, in fraction of the font size.

        frameon : bool, default: False
            If True, draw a box around the arrows and labels.

        color : str, default: 'white'
            Color for the arrows and labels.

        alpha : float, default: 1
            Alpha values of the arrows and labels

        sep_x, sep_y : float, default: 0.01 and 0 respectively
            Separation between the arrows and labels in coordinates of
            *transform*.

        fontproperties : `matplotlib.font_manager.FontProperties`, optional
            Font properties for the label text.

        back_length : float, default: 0.15
            Fraction of the arrow behind the arrow crossing.

        head_width : float, default: 10
            Width of arrow head, sent to ArrowStyle.

        head_length : float, default: 15
            Length of arrow head, sent to ArrowStyle.

        tail_width : float, default: 2
            Width of arrow tail, sent to ArrowStyle.

        text_props, arrow_props : dict
            Properties of the text and arrows, passed to
            `.textpath.TextPath` and `.patches.FancyArrowPatch`.

        **kwargs
            Keyworded arguments to pass to
            :class:`matplotlib.offsetbox.AnchoredOffsetbox`.

        Attributes
        ----------
        arrow_x, arrow_y : `matplotlib.patches.FancyArrowPatch`
            Arrow x and y

        text_path_x, text_path_y : `matplotlib.textpath.TextPath`
            Path for arrow labels

        p_x, p_y : `matplotlib.patches.PathPatch`
            Patch for arrow labels

        box : `matplotlib.offsetbox.AuxTransformBox`
            Container for the arrows and labels.

        Notes
        -----
        If *prop* is passed as a keyword argument, but *fontproperties* is
        not, then *prop* is be assumed to be the intended *fontproperties*.
        Using both *prop* and *fontproperties* is not supported.

        Examples
        --------
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from mpl_toolkits.axes_grid1.anchored_artists import (
        ...     AnchoredDirectionArrows)
        >>> fig, ax = plt.subplots()
        >>> ax.imshow(np.random.random((10, 10)))
        >>> arrows = AnchoredDirectionArrows(ax.transAxes, '111', '110')
        >>> ax.add_artist(arrows)
        >>> fig.show()

        Using several of the optional parameters, creating downward pointing
        arrow and high contrast text labels.

        >>> import matplotlib.font_manager as fm
        >>> fontprops = fm.FontProperties(family='monospace')
        >>> arrows = AnchoredDirectionArrows(ax.transAxes, 'East', 'South',
        ...                                  loc='lower left', color='k',
        ...                                  aspect_ratio=-1, sep_x=0.02,
        ...                                  sep_y=-0.01,
        ...                                  text_props={'ec':'w', 'fc':'k'},
        ...                                  fontproperties=fontprops)
        NZSimple)
head_widthhead_length
tail_widthr   r6   alphar   g        )
arrowstyleZshrinkAZshrinkB)r=   r   r-   rA   )r   r   r   r   )r
   r<   r   ZAffine2DZ
rotate_degr   Zboxr   Zarrow_xZarrow_yr1   r   r   Zp_xZp_yr   r   )r   r-   Zlabel_xZlabel_ylengthZfontsizer"   r2   Zaspect_ratior   r   r   r6   rI   Zsep_xZsep_yr7   Zback_lengthrF   rG   rH   Z
text_propsZarrow_propsr#   rJ   Zt_startZt_endZlength_xZlength_yZtext_path_xZtext_path_yr$   r&   r'   r   d  s     





 
 
   z AnchoredDirectionArrows.__init__)r?   r@   r3   r   rA   r   r   FrB   rA   rC   r   Nr?   rD   rE   r3   NNr(   r&   r&   r$   r'   r   c  s(                                   N)Z
matplotlibr   Zmatplotlib.offsetboxr   r   r   r   r   Zmatplotlib.patchesr   r	   r
   r   r   Zmatplotlib.textr   __all__r   r   r   r   r   r&   r&   r&   r'   <module>   s     JD? 