3
ƽh                 @   s  d dl mZmZ d dlmZ d dlZd dlZd dlmZ d dl	Z	d dl
Z
d dl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mZmZmZ ejeZd	d
 Zdd ZeddZ G dd dZ!G dd dZ"dddZ#e#Z$ddddZ%dd Z&ej'j(e&e!d dS )    )OrderedDict
namedtuple)wrapsN)Number   )cbook	docstring)Path)BboxIdentityTransform	TransformTransformedBboxTransformedPatchPathTransformedPathc                s   t   fdd}d|_|S )a-  
    Decorator for Artist.draw method. Provides routines
    that run before and after the draw call. The before and after functions
    are useful for changing artist-dependent renderer attributes or making
    other setup function calls, such as starting and flushing a mixed-mode
    renderer.
    c                sh   z6| j  r|j  | j d k	r&|j   | |f||S | j d k	rR|j| j  | j  rb|j  X d S )N)get_rasterizedZstart_rasterizingget_agg_filterZstart_filterZstop_filterZstop_rasterizing)artistrendererargskwargs)draw 7/tmp/pip-build-7iwl8md4/matplotlib/matplotlib/artist.pydraw_wrapper!   s    z)allow_rasterization.<locals>.draw_wrapperT)r   _supports_rasterization)r   r   r   )r   r   allow_rasterization   s    r   c             C   s   | j r|| j _d S )N)axesstale)selfvalr   r   r   _stale_axes_callback4   s    r    _XYPairzx yc               @   s  e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
edd Zejdd Zedd Zej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dd*d+Zd,d- Zejd.d/d0d1d2 Zejd.d3d0d4d5 Zd6d7 Zd8d9 Z d:d; Z!d<d= Z"d>d? Z#d@dA Z$dBdC Z%dDdE Z&dFdG Z'dHdI Z(dJdK Z)ddLdMZ*dNdO Z+dPdQ Z,dRdS Z-dTdU Z.dVdW Z/ddXdYZ0dZd[ Z1d\d] Z2d^d_ Z3d`da Z4dbdc Z5ddde Z6dfdg Z7dhdi Z8djdk Z9dldm Z:dndo Z;dpdq Z<drds Z=dtdu Z>ej?d.dvej?d.dwdxdy Z@dzd{ ZAd|d} ZBd~d ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIedd ZJdd ZKdd ZLdd ZMdddZNdd ZOdd ZPedd ZQeQjdd ZQd)S )Artistz
    Abstract base class for objects that render into a FigureCanvas.

    Typically, all visible elements in a figure are subclasses of Artist.
    r   c             C   s   d| _ d | _d | _d | _d | _d| _d| _d| _d | _d | _	d | _
d| _d| _d | _d | _d | _d | _t| jtjk| _d| _d| _i | _y
d | _W n tk
r   Y nX d | _d | _d | _d | _tjd | _ tjd | _!t"g g | _#d| _$d S )NTF r   zpath.sketchzpath.effects)%_stalestale_callback_axesfigure
_transform_transformSet_visible	_animated_alphaclipbox	_clippath_clipon_label_picker	_contains_rasterized_agg_filtertypeget_cursor_datar"   
_mouseovereventson_oid_propobserversr   AttributeError_remove_method_url_gid_snapmplrcParams_sketch_path_effectsr!   _sticky_edges
_in_layout)r   r   r   r   __init__E   sB    
zArtist.__init__c             C   s   | j j }d |d< |S )Nr%   )__dict__copy)r   dr   r   r   __getstate__l   s    
zArtist.__getstate__c             C   sr   | j dk	rf| j |  d| _d}t| drN| jrN| jjj|  d| j_d| _d}| jrnd| _|snd| _ntddS )a  
        Remove the artist from the figure if possible.

        The effect will not be visible until the figure is redrawn, e.g.,
        with `.FigureCanvasBase.draw_idle`.  Call `~.axes.Axes.relim` to
        update the axes limits if desired.

        Note: `~.axes.Axes.relim` will not see collections even if the
        collection was added to the axes with *autolim* = True.

        Note: there is no support for removing the artist's legend entry.
        NFr   Tzcannot remove artist)	r<   r%   hasattrr   _mouseover_setdiscardr   r'   NotImplementedError)r   Z_ax_flagr   r   r   removes   s    

zArtist.removec             C   s    | j }|otdd |j D S )z+Return *True* if units are set on any axis.c             s   s   | ]}|j  V  qd S )N)
have_units).0Zaxisr   r   r   	<genexpr>   s    z$Artist.have_units.<locals>.<genexpr>)r   anyZ_get_axis_list)r   axr   r   r   rP      s    zArtist.have_unitsc             C   s.   t | dd}|dks|jdkr"|S |jj|S )z
        Convert *x* using the unit type of the xaxis.

        If the artist is not in contained in an Axes or if the xaxis does not
        have units, *x* itself is returned.
        r   N)getattrZxaxisconvert_units)r   xrT   r   r   r   convert_xunits   s    zArtist.convert_xunitsc             C   s.   t | dd}|dks|jdkr"|S |jj|S )z
        Convert *y* using the unit type of the yaxis.

        If the artist is not in contained in an Axes or if the yaxis does not
        have units, *y* itself is returned.
        r   N)rU   ZyaxisrV   )r   yrT   r   r   r   convert_yunits   s    zArtist.convert_yunitsc             C   s   | j S )z<The `~.axes.Axes` instance the artist resides in, or *None*.)r&   )r   r   r   r   r      s    zArtist.axesc             C   sD   |d k	r$| j d k	r$|| j kr$td|| _ |d k	r@|| k	r@t| _d S )NzqCan not reset the axes.  You are probably trying to re-use an artist in more than one Axes which is not supported)r&   
ValueErrorr    r%   )r   Znew_axesr   r   r   r      s    
c             C   s   | j S )z
        Whether the artist is 'stale' and needs to be re-drawn for the output
        to match the internal state of the artist.
        )r$   )r   r   r   r   r      s    zArtist.stalec             C   s0   || _ | j rd S |r,| jd k	r,| j| | d S )N)r$   get_animatedr%   )r   r   r   r   r   r      s
    c             C   s   t ddgddggS )a  
        Get the axes bounding box in display space.

        The bounding box' width and height are nonnegative.

        Subclasses should override for inclusion in the bounding box
        "tight" calculation. Default is to return an empty bounding
        box at 0, 0.

        Be careful when using this function, the results will not update
        if the artist window extent of the artist changes.  The extent
        can change due to any changes in the transform stack, such as
        changing the axes limits, the figure size, or the canvas used
        (as is done when saving a figure).  This can lead to unexpected
        behavior where interactive figures will look fine on the screen,
        but will save incorrectly.
        r   )r
   )r   r   r   r   r   get_window_extent   s    zArtist.get_window_extentc             C   sT   d}| j  rP| j }|dk	r |}| j }|dk	rP|dk	rP|j }tj||j }|S )z
        Return a bbox with the extents of the intersection of the clip_path
        and clip_box for this artist, or None if both of these are
        None, or ``get_clip_on`` is False.
        N)get_clip_onget_clip_boxget_clip_pathget_fully_transformed_pathr
   intersectionget_extents)r   bboxclip_box	clip_pathr   r   r   _get_clipping_extent_bbox   s    z Artist._get_clipping_extent_bboxc             C   sb   | j |}| j r^| j }|dk	r.tj||}| j }|dk	r^|dk	r^|j }tj||j }|S )a  
        Like `.Artist.get_window_extent`, but includes any clipping.

        Parameters
        ----------
        renderer : `.RendererBase` subclass
            renderer that will be used to draw the figures (i.e.
            ``fig.canvas.get_renderer()``)

        Returns
        -------
        `.Bbox`
            The enclosing bounding box (in figure pixel coordinates).
        N)r]   r^   r_   r
   rb   r`   ra   rc   )r   r   rd   re   rf   r   r   r   get_tightbbox  s    
zArtist.get_tightbboxc             C   s"   | j }|| j|< |  j d7  _ |S )a  
        Add a callback function that will be called whenever one of the
        `.Artist`'s properties changes.

        Parameters
        ----------
        func : callable
            The callback function. It must have the signature::

                def func(artist: Artist) -> Any

            where *artist* is the calling `.Artist`. Return values may exist
            but are ignored.

        Returns
        -------
        int
            The observer id associated with the callback. This id can be
            used for removing the callback with `.remove_callback` later.

        See Also
        --------
        remove_callback
        r   )r9   r:   )r   funcoidr   r   r   add_callback!  s    
zArtist.add_callbackc             C   s&   y| j |= W n tk
r    Y nX dS )zu
        Remove a callback based on its observer id.

        See Also
        --------
        add_callback
        N)r:   KeyError)r   rj   r   r   r   remove_callback?  s    zArtist.remove_callbackc             C   s$   x| j j D ]\}}||  qW dS )z
        Call all of the registered callbacks.

        This function is triggered internally when a property is changed.

        See Also
        --------
        add_callback
        remove_callback
        N)r:   items)r   rj   ri   r   r   r   pchangedL  s    zArtist.pchangedc             C   s   | j S )z
        Return whether the Artist has an explicitly set transform.

        This is *True* after `.set_transform` has been called.
        )r)   )r   r   r   r   is_transform_setZ  s    zArtist.is_transform_setc             C   s   || _ d| _| j  d| _dS )zk
        Set the artist transform.

        Parameters
        ----------
        t : `.Transform`
        TN)r(   r)   ro   r   )r   tr   r   r   set_transformb  s    zArtist.set_transformc             C   sD   | j dkrt | _ n*t| j t r>t| j dr>| j j| j| _ | j S )z5Return the `.Transform` instance used by this artist.N_as_mpl_transform)r(   r   
isinstancer   rK   rs   r   )r   r   r   r   get_transformo  s    

zArtist.get_transformc             C   s   g S )z9Return a list of the child `.Artist`\s of this `.Artist`.r   )r   r   r   r   get_childrenx  s    zArtist.get_childrenNc             C   s:   t | jr| j| |S |dk	r2|j|jk	r2di fS di fS )a  
        Base impl. for checking whether a mouseevent happened in an artist.

        1. If the artist defines a custom checker, use it (deprecated).
        2. If the artist figure is known and the event did not occur in that
           figure (by checking its ``canvas`` attribute), reject it.
        3. Otherwise, return `None, {}`, indicating that the subclass'
           implementation should be used.

        Subclasses should start their definition of `contains` as follows:

            inside, info = self._default_contains(mouseevent)
            if inside is not None:
                return inside, info
            # subclass-specific implementation follows

        The *figure* kwarg is provided for the implementation of
        `.Figure.contains`.
        NF)callabler2   canvas)r   
mouseeventr'   r   r   r   _default_contains|  s
    
zArtist._default_containsc             C   s6   | j |\}}|dk	r||fS tjd| jj di fS )a  
        Test whether the artist contains the mouse event.

        Parameters
        ----------
        mouseevent : `matplotlib.backend_bases.MouseEvent`

        Returns
        -------
        contains : bool
            Whether any values are within the radius.
        details : dict
            An artist-specific dictionary of details of the event context,
            such as which points are contained in the pick radius. See the
            individual Artist subclasses for details.
        Nz%r needs 'contains' methodF)rz   _logwarning	__class____name__)r   ry   insideinfor   r   r   contains  s
    zArtist.containsz3.3
set_picker)alternativec             C   s   t |std|| _dS )a  
        Define a custom contains test for the artist.

        The provided callable replaces the default `.contains` method
        of the artist.

        Parameters
        ----------
        picker : callable
            A custom picker function to evaluate if an event is within the
            artist. The function must have the signature::

                def contains(artist: Artist, event: MouseEvent) -> bool, dict

            that returns:

            - a bool indicating if the event is within the artist
            - a dict of additional information. The dict should at least
              return the same information as the default ``contains()``
              implementation of the respective artist, but may provide
              additional information.
        zpicker is not a callableN)rw   	TypeErrorr2   )r   pickerr   r   r   set_contains  s    zArtist.set_contains
get_pickerc             C   s   | j S )z
        Return the custom contains function of the artist if set, or *None*.

        See Also
        --------
        set_contains
        )r2   )r   r   r   r   get_contains  s    	zArtist.get_containsc             C   s   | j dk	o| jdk	S )z
        Return whether the artist is pickable.

        See Also
        --------
        set_picker, get_picker, pick
        N)r'   r1   )r   r   r   r   pickable  s    zArtist.pickablec             C   s   | j  rN| j }t|r(|| |\}}n| j|\}}|rN| jjj|| f| xB| j D ]6}t|dd}|j	dks|dks|j	|krX|j
| qXW dS )z
        Process a pick event.

        Each child artist will fire a pick event if *mouseevent* is over
        the artist and the artist has picker set.

        See Also
        --------
        set_picker, get_picker, pickable
        r   N)r   r   rw   r   r'   rx   Z
pick_eventrv   rU   Zinaxespick)r   ry   r   r   proparT   r   r   r   r     s    
zArtist.pickc             C   s
   || _ dS )af  
        Define the picking behavior of the artist.

        Parameters
        ----------
        picker : None or bool or callable
            This can be one of the following:

            - *None*: Picking is disabled for this artist (default).

            - A boolean: If *True* then picking will be enabled and the
              artist will fire a pick event if the mouse event is over
              the artist.

            - A function: If picker is callable, it is a user supplied
              function which determines whether the artist is hit by the
              mouse event::

                hit, props = picker(artist, mouseevent)

              to determine the hit test.  if the mouse event is over the
              artist, return *hit=True* and props is a dictionary of
              properties you want added to the PickEvent attributes.

            - *deprecated*: For `.Line2D` only, *picker* can also be a float
              that sets the tolerance for checking whether an event occurred
              "on" the line; this is deprecated.  Use `.Line2D.set_pickradius`
              instead.
        N)r1   )r   r   r   r   r   r     s    zArtist.set_pickerc             C   s   | j S )z
        Return the picking behavior of the artist.

        The possible values are described in `.set_picker`.

        See Also
        --------
        set_picker, pickable, pick
        )r1   )r   r   r   r   r   !  s    
zArtist.get_pickerc             C   s   | j S )zReturn the url.)r=   )r   r   r   r   get_url-  s    zArtist.get_urlc             C   s
   || _ dS )zf
        Set the url for the artist.

        Parameters
        ----------
        url : str
        N)r=   )r   urlr   r   r   set_url1  s    zArtist.set_urlc             C   s   | j S )zReturn the group id.)r>   )r   r   r   r   get_gid;  s    zArtist.get_gidc             C   s
   || _ dS )zm
        Set the (group) id for the artist.

        Parameters
        ----------
        gid : str
        N)r>   )r   gidr   r   r   set_gid?  s    zArtist.set_gidc             C   s   t jd r| jS dS dS )zP
        Return the snap setting.

        See `.set_snap` for details.
        z	path.snapFN)r@   rA   r?   )r   r   r   r   get_snapI  s    
zArtist.get_snapc             C   s   || _ d| _dS )a  
        Set the snapping behavior.

        Snapping aligns positions with the pixel grid, which results in
        clearer images. For example, if a black line of 1px width was
        defined at a position in between two pixels, the resulting image
        would contain the interpolated value of that line in the pixel grid,
        which would be a grey value on both adjacent pixel positions. In
        contrast, snapping will move the line to the nearest integer pixel
        value, so that the resulting image will really contain a 1px wide
        black line.

        Snapping is currently only supported by the Agg and MacOSX backends.

        Parameters
        ----------
        snap : bool or None
            Possible values:

            - *True*: Snap vertices to the nearest pixel center.
            - *False*: Do not modify vertex positions.
            - *None*: (auto) If the path contains only rectilinear line
              segments, round to the nearest pixel center.
        TN)r?   r   )r   Zsnapr   r   r   set_snapT  s    zArtist.set_snapc             C   s   | j S )a  
        Return the sketch parameters for the artist.

        Returns
        -------
        tuple or None

            A 3-tuple with the following elements:

            - *scale*: The amplitude of the wiggle perpendicular to the
              source line.
            - *length*: The length of the wiggle along the line.
            - *randomness*: The scale factor by which the length is
              shrunken or expanded.

            Returns *None* if no sketch parameters were set.
        )rB   )r   r   r   r   get_sketch_paramsp  s    zArtist.get_sketch_paramsc             C   s.   |dkrd| _ n||pd|pdf| _ d| _dS )a{  
        Sets the sketch parameters.

        Parameters
        ----------
        scale : float, optional
            The amplitude of the wiggle perpendicular to the source
            line, in pixels.  If scale is `None`, or not provided, no
            sketch filter will be provided.
        length : float, optional
             The length of the wiggle along the line, in pixels
             (default 128.0)
        randomness : float, optional
            The scale factor by which the length is shrunken or
            expanded (default 16.0)

            .. ACCEPTS: (scale: float, length: float, randomness: float)
        Ng      `@g      0@T)rB   r   )r   ZscalelengthZ
randomnessr   r   r   set_sketch_params  s    zArtist.set_sketch_paramsc             C   s   || _ d| _dS )z{
        Set the path effects.

        Parameters
        ----------
        path_effects : `.AbstractPathEffect`
        TN)rC   r   )r   Zpath_effectsr   r   r   set_path_effects  s    zArtist.set_path_effectsc             C   s   | j S )N)rC   )r   r   r   r   get_path_effects  s    zArtist.get_path_effectsc             C   s   | j S )z4Return the `.Figure` instance the artist belongs to.)r'   )r   r   r   r   
get_figure  s    zArtist.get_figurec             C   sH   | j |krdS | j dk	r td|| _ | j r>| j | k	r>| j  d| _dS )z
        Set the `.Figure` instance the artist belongs to.

        Parameters
        ----------
        fig : `.Figure`
        Nz1Can not put single artist in more than one figureT)r'   RuntimeErrorro   r   )r   Zfigr   r   r   
set_figure  s    	

zArtist.set_figurec             C   s   || _ | j  d| _dS )zq
        Set the artist's clip `.Bbox`.

        Parameters
        ----------
        clipbox : `.Bbox`
        TN)r-   ro   r   )r   r-   r   r   r   set_clip_box  s    zArtist.set_clip_boxc             C   s   ddl m}m} d}|dkrrt||rFttj |j | _d| _	d}n,t||r`t
|| _	d}nt|trr|\}}|dkrd| _	d}nFt|trt||| _	d}n*t|t
r|| _	d}nt|tr|| _	d}|stdjt|jt|j| j  d| _dS )a  
        Set the artist's clip path.

        Parameters
        ----------
        path : `.Patch` or `.Path` or `.TransformedPath` or None
            The clip path. If given a `.Path`, *transform* must be provided as
            well. If *None*, a previously set clip path is removed.
        transform : `~matplotlib.transforms.Transform`, optional
            Only used if *path* is a `.Path`, in which case the given `.Path`
            is converted to a `.TransformedPath` using *transform*.

        Notes
        -----
        For efficiency, if *path* is a `.Rectangle` this method will set the
        clipping box to the corresponding rectangle and set the clipping path
        to ``None``.

        For technical reasons (support of `~.Artist.set`), a tuple
        (*path*, *transform*) is also accepted as a single positional
        parameter.

        .. ACCEPTS: Patch or (Path, Transform) or None
        r   )Patch	RectangleFNTz5Invalid arguments to set_clip_path, of type {} and {})Zmatplotlib.patchesr   r   rt   r   r
   unitru   r-   r.   r   tupler	   r   r   formatr5   r~   ro   r   )r   pathZ	transformr   r   successr   r   r   set_clip_path  s>    






zArtist.set_clip_pathc             C   s   | j S )zc
        Return the alpha value used for blending - not supported on all
        backends.
        )r,   )r   r   r   r   	get_alpha  s    zArtist.get_alphac             C   s   | j S )zReturn the visibility.)r*   )r   r   r   r   get_visible  s    zArtist.get_visiblec             C   s   | j S )z&Return whether the artist is animated.)r+   )r   r   r   r   r\     s    zArtist.get_animatedc             C   s   | j S )a  
        Return boolean flag, ``True`` if artist is included in layout
        calculations.

        E.g. :doc:`/tutorials/intermediate/constrainedlayout_guide`,
        `.Figure.tight_layout()`, and
        ``fig.savefig(fname, bbox_inches='tight')``.
        )rE   )r   r   r   r   get_in_layout   s    	zArtist.get_in_layoutc             C   s   | j S )z(Return whether the artist uses clipping.)r/   )r   r   r   r   r^   +  s    zArtist.get_clip_onc             C   s   | j S )zReturn the clipbox.)r-   )r   r   r   r   r_   /  s    zArtist.get_clip_boxc             C   s   | j S )zReturn the clip path.)r.   )r   r   r   r   r`   3  s    zArtist.get_clip_pathc             C   s   | j dk	r| j j S dS )z
        Return the clip path with the non-affine part of its
        transformation applied, and the remaining affine part of its
        transformation.
        N)NN)r.   Zget_transformed_path_and_affine)r   r   r   r   $get_transformed_clip_path_and_affine7  s    

z+Artist.get_transformed_clip_path_and_affinec             C   s   || _ | j  d| _dS )z
        Set whether the artist uses clipping.

        When False artists will be visible outside of the axes which
        can lead to unexpected results.

        Parameters
        ----------
        b : bool
        TN)r/   ro   r   )r   br   r   r   set_clip_onA  s    zArtist.set_clip_onc             C   sB   | j r*| jdk	r|j| j |j| j n|jd |jd dS )z!Set the clip properly for the gc.N)r/   r-   Zset_clip_rectangler   r.   )r   gcr   r   r   _set_gc_clipR  s    

zArtist._set_gc_clipc             C   s   | j S )z.Return whether the artist is to be rasterized.)r3   )r   r   r   r   r   \  s    zArtist.get_rasterizedc             C   s*   |r t | jd r tjd|   || _dS )z
        Force rasterized (bitmap) drawing in vector backend output.

        Defaults to None, which implies the backend's default behavior.

        Parameters
        ----------
        rasterized : bool or None
        r   z%Rasterization of '%s' will be ignoredN)rK   r   r   Z_warn_externalr3   )r   Z
rasterizedr   r   r   set_rasterized`  s    

zArtist.set_rasterizedc             C   s   | j S )z1Return filter function to be used for agg filter.)r4   )r   r   r   r   r   p  s    zArtist.get_agg_filterc             C   s   || _ d| _dS )ay  
        Set the agg filter.

        Parameters
        ----------
        filter_func : callable
            A filter function, which takes a (m, n, 3) float array and a dpi
            value, and returns a (m, n, 3) array.

            .. ACCEPTS: a filter function, which takes a (m, n, 3) float array
                and a dpi value, and returns a (m, n, 3) array
        TN)r4   r   )r   Zfilter_funcr   r   r   set_agg_filtert  s    zArtist.set_agg_filterr   r   c             O   s   | j  sdS d| _dS )ac  
        Draw the Artist (and its children) using the given renderer.

        This has no effect if the artist is not visible (`.Artist.get_visible`
        returns False).

        Parameters
        ----------
        renderer : `.RendererBase` subclass.

        Notes
        -----
        This method is overridden in the Artist subclasses.
        NF)r   r   )r   r   r   r   r   r   r   r     s    zArtist.drawc             C   s4   |dk	rt |t rtd|| _| j  d| _dS )z
        Set the alpha value used for blending - not supported on all backends.

        Parameters
        ----------
        alpha : float or None
        Nzalpha must be a float or NoneT)rt   r   r   r,   ro   r   )r   alphar   r   r   	set_alpha  s
    zArtist.set_alphac             C   s   || _ | j  d| _dS )zf
        Set the artist's visibility.

        Parameters
        ----------
        b : bool
        TN)r*   ro   r   )r   r   r   r   r   set_visible  s    zArtist.set_visiblec             C   s   | j |kr|| _ | j  dS )zk
        Set the artist's animation state.

        Parameters
        ----------
        b : bool
        N)r+   ro   )r   r   r   r   r   set_animated  s    
zArtist.set_animatedc             C   s
   || _ dS )a)  
        Set if artist is to be included in layout calculations,
        E.g. :doc:`/tutorials/intermediate/constrainedlayout_guide`,
        `.Figure.tight_layout()`, and
        ``fig.savefig(fname, bbox_inches='tight')``.

        Parameters
        ----------
        in_layout : bool
        N)rE   )r   Z	in_layoutr   r   r   set_in_layout  s    zArtist.set_in_layoutc             C   s   g }t j| dd x|j D ]\}}||j krHt jddd |j }|dkrd|jt| || qt| d| d}t|st	t
| jd	||j|| qW W dQ R X |r| j  d
| _|S )z
        Update this artist's properties from the dict *props*.

        Parameters
        ----------
        props : dict
        F)r8   z3.3z`Case-insensitive properties were deprecated in %(since)s and support will be removed %(removal)s)messager   set_Nz object has no property T)r   Z_setattr_cmrn   lowerwarn_deprecatedappendsetattrrU   rw   r;   r5   r~   ro   r   )r   propsretkvri   r   r   r   update  s"    
zArtist.updatec             C   s   | j S )z4Return the label used for this artist in the legend.)r0   )r   r   r   r   	get_label  s    zArtist.get_labelc             C   s,   |dk	rt || _nd| _| j  d| _dS )z
        Set a label that will be displayed in the legend.

        Parameters
        ----------
        s : object
            *s* will be converted to a string by calling `str`.
        NT)strr0   ro   r   )r   sr   r   r   	set_label  s
    	zArtist.set_labelc             C   s   | j S )zReturn the artist's zorder.)zorder)r   r   r   r   
get_zorder   s    zArtist.get_zorderc             C   s(   |dkr| j j}|| _| j  d| _dS )z
        Set the zorder for the artist.  Artists with lower zorder
        values are drawn first.

        Parameters
        ----------
        level : float
        NT)r}   r   ro   r   )r   levelr   r   r   
set_zorder  s
    	zArtist.set_zorderc             C   s   | j S )a  
        ``x`` and ``y`` sticky edge lists for autoscaling.

        When performing autoscaling, if a data limit coincides with a value in
        the corresponding sticky_edges list, then no margin will be added--the
        view limit "sticks" to the edge. A typical use case is histograms,
        where one usually expects no margin on the bottom edge (0) of the
        histogram.

        This attribute cannot be assigned to; however, the ``x`` and ``y``
        lists can be modified in place as needed.

        Examples
        --------
        >>> artist.sticky_edges.x[:] = (xmin, xmax)
        >>> artist.sticky_edges.y[:] = (ymin, ymax)

        )rD   )r   r   r   r   sticky_edges  s    zArtist.sticky_edgesc             C   s   |j | _ |j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j	| _	|j
jj | j
jdd< |j
jj | j
jdd< | j  d| _dS )z'Copy properties from *other* to *self*.NT)r(   r)   r*   r,   r-   r/   r.   r0   rB   rC   r   rW   rH   rY   ro   r   )r   otherr   r   r   update_from)  s    zArtist.update_fromc             C   s   t | j S )z8Return a dictionary of all the properties of the artist.)ArtistInspector
properties)r   r   r   r   r   :  s    zArtist.propertiesc             K   s   t j|| }d}d|kr|}|jd}ddg}tdd t| jD rR|jd xB|D ]:}||krfqX|j|}||k rXd}t jd	d
|dd qXW |rd|jdi|}| j	|S )z:A property batch setter.  Pass *kwargs* to set properties.FcolorZ	edgecolorZ	facecolorc             s   s"   | ]}|j d ko|jdkV  qdS )zmatplotlib.collections
CollectionN)
__module__r~   )rQ   tpr   r   r   rR   F  s   zArtist.set.<locals>.<genexpr>r   Tz3.3zYou have passed the z kwarg before the 'color' kwarg.  Artist.set() currently reorders the properties to apply 'color' first, but this is deprecated since %(since)s and will be removed %(removal)s; please pass 'color' first instead.)r   )
r   Znormalize_kwargsindexrS   r5   __mro__r   r   popr   )r   r   Zmove_color_to_startkeysZi_colorr   r   Zi_otherr   r   r   set>  s(    



z
Artist.setTc                s    dkrdd n8t  tr4t tr4 fddnt rB ntdtfdd| j D g }|r|| r||j|  |S )a  
        Find artist objects.

        Recursively find all `.Artist` instances contained in the artist.

        Parameters
        ----------
        match
            A filter criterion for the matches. This can be

            - *None*: Return all objects contained in artist.
            - A function with signature ``def match(artist: Artist) -> bool``.
              The result will only contain artists for which the function
              returns *True*.
            - A class instance: e.g., `.Line2D`. The result will only contain
              artists of this class or its subclasses (``isinstance`` check).

        include_self : bool
            Include *self* in the list to be checked for a match.

        Returns
        -------
        list of `.Artist`

        Nc             S   s   dS )NTr   )rW   r   r   r   	matchfuncv  s    z!Artist.findobj.<locals>.matchfuncc                s
   t |  S )N)rt   )rW   )matchr   r   r   y  s    zFmatch must be None, a matplotlib.artist.Artist subclass, or a callablec                s   g | ]}|j  qS r   )findobj)rQ   c)r   r   r   
<listcomp>  s    z"Artist.findobj.<locals>.<listcomp>)	rt   r5   
issubclassr"   rw   r[   sumrv   r   )r   r   Zinclude_selfZartistsr   )r   r   r   r   [  s    

zArtist.findobjc             C   s   dS )a  
        Return the cursor data for a given event.

        .. note::
            This method is intended to be overridden by artist subclasses.
            As an end-user of Matplotlib you will most likely not call this
            method yourself.

        Cursor data can be used by Artists to provide additional context
        information for a given event. The default implementation just returns
        *None*.

        Subclasses can override the method and return arbitrary data. However,
        when doing so, they must ensure that `.format_cursor_data` can convert
        the data to a string representation.

        The only current use case is displaying the z-value of an `.AxesImage`
        in the status bar of a plot window, while moving the mouse.

        Parameters
        ----------
        event : `matplotlib.backend_bases.MouseEvent`

        See Also
        --------
        format_cursor_data

        Nr   )r   eventr   r   r   r6     s    zArtist.get_cursor_datac             C   sL   y|d  W n t tfk
r*   |g}Y nX djdd |D }d| d S )a  
        Return a string representation of *data*.

        .. note::
            This method is intended to be overridden by artist subclasses.
            As an end-user of Matplotlib you will most likely not call this
            method yourself.

        The default implementation converts ints and floats and arrays of ints
        and floats into a comma-separated string enclosed in square brackets.

        See Also
        --------
        get_cursor_data
        r   z, c             s   s"   | ]}t |trd j|V  qdS )z{:0.3g}N)rt   r   r   )rQ   itemr   r   r   rR     s    z,Artist.format_cursor_data.<locals>.<genexpr>[])r   
IndexErrorjoin)r   dataZdata_strr   r   r   format_cursor_data  s    zArtist.format_cursor_datac             C   s   | j S )a  
        If this property is set to *True*, the artist will be queried for
        custom context information when the mouse cursor moves over it.

        See also :meth:`get_cursor_data`, :class:`.ToolCursorPosition` and
        :class:`.NavigationToolbar2`.
        )r7   )r   r   r   r   	mouseover  s    	zArtist.mouseoverc             C   s:   t |}|| _| j}|r6|r*|jj|  n|jj|  d S )N)boolr7   r   rL   addrM   )r   r   rT   r   r   r   r     s    )N)NNN)N)NT)Rr~   r   __qualname____doc__r   rF   rJ   rO   rP   rX   rZ   propertyr   setterr   r]   rg   rh   rk   rm   ro   rp   rr   ru   rv   rz   r   r   Z
deprecatedr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r\   r   r^   r_   r`   r   r   r   r   r   r   r   Z_delete_parameterr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r6   r   r   r   r   r   r   r"   <   s   '-	

# 



>


 
+r"   c               @   s~   e Zd ZdZdd Zdd ZejdZdd Z	d	d
 Z
dd Zdd Zdd Zdd ZdddZdddZdd Zdd ZdS ) r   z
    A helper class to inspect an `~matplotlib.artist.Artist` and return
    information about its settable properties and their current values.
    c             C   sX   t |ts,tj|r,t|}t|r,|d }|| _t |tsDt|}|| _| j	 | _
dS )a  
        Initialize the artist inspector with an `Artist` or an iterable of
        `Artist`\s.  If an iterable is used, we assume it is a homogeneous
        sequence (all `Artist`\s are of the same type) and it is your
        responsibility to make sure this is so.
        r   N)rt   r"   npiterablelistlenoorigr5   oget_aliasesaliasd)r   r   r   r   r   rF     s    


zArtistInspector.__init__c                s    fddt  jD }i }xn|D ]f}t j|} j|s>q"tjdj|dd tj|j	d}|j
|dd t j|dd  q"W |S )a
  
        Get a dict mapping property fullnames to sets of aliases for each alias
        in the :class:`~matplotlib.artist.ArtistInspector`.

        e.g., for lines::

          {'markerfacecolor': {'mfc'},
           'linewidth'      : {'lw'},
          }
        c                s*   g | ]"}|j drtt j|r|qS )r   get_)r   r   )
startswithrw   rU   r   )rQ   name)r   r   r   r     s    
z/ArtistInspector.get_aliases.<locals>.<listcomp>z`({}.*)`N   r   )dirr   rU   is_aliasresearchr   inspectgetdocgroup
setdefaultr   r   )r   namesaliasesr   ri   Zpropnamer   )r   r   r     s    

(zArtistInspector.get_aliasesz6\n\s*(?:\.\.\s+)?ACCEPTS:\s*((?:.|\n)*?)(?:$|(?:\n\n))c             C   s   d| }t | j|s&td| j|f t| j|}tj|}|dkrHdS |jdrVdS | jj|}|dk	r~t	j
dd|jdS |jjd }t	jd	j||}|r|jdS dS )
a/  
        Get the legal arguments for the setter associated with *attr*.

        This is done by querying the docstring of the setter for a line that
        begins with "ACCEPTS:" or ".. ACCEPTS:", and then by looking for a
        numpydoc-style documentation for the setter's first argument.
        zset_%sz%s has no function %sNunknownz
Alias for z
 * r   z(?m)^ *\*?{} : (.+))rK   r   r;   rU   r   r   r   _get_valid_values_regexr   r   subr   __code__co_varnamesr   )r   attrr   ri   r   r   
param_namer   r   r   get_valid_values
  s"    	


z ArtistInspector.get_valid_valuesc             C   s0   ddd}x |j  D ]\}}|j||}qW |S )z
        Changes the full path to the public API path that is used
        in sphinx. This is needed for links to work.
        Axes)z_base._AxesBasez
_axes.Axes)rn   replace)r   Zsource_classZreplace_dictkeyvaluer   r   r   _replace_path.  s
    zArtistInspector._replace_pathc             C   sp   g }xft | jD ]X}|jds qt| j|}t| sttj|jdk s| j	|rVq|j
|dd  qW |S )z
        Get the attribute strings with setters for object.

        For example, for a line, return ``['markerfacecolor', 'linewidth',
        ....]``.
        r      r   N)r   r   r   rU   rw   r   r   	signature
parametersr   r   )r   Zsettersr   ri   r   r   r   get_setters9  s    


zArtistInspector.get_settersc             C   s    t j|}|dkrdS |jdS )z@Return whether method object *o* is an alias for another method.NFz
Alias for )r   r   r   )r   r   Zdsr   r   r   r   L  s    
zArtistInspector.is_aliasc             C   s*   dj dd t| jj|g D }|| S )a  
        Return 'PROPNAME or alias' if *s* has an alias, else return 'PROPNAME'.

        e.g., for the line markerfacecolor property, which has an
        alias, return 'markerfacecolor or mfc' and for the transform
        property, which does not, return 'transform'.
        r#   c             s   s   | ]}d | V  qdS )z or %sNr   )rQ   rW   r   r   r   rR   [  s    z/ArtistInspector.aliased_name.<locals>.<genexpr>)r   sortedr   get)r   r   r  r   r   r   aliased_nameS  s    "zArtistInspector.aliased_namec             C   s0   dj dd t| jj|g D }d|||f S )a3  
        Return 'PROPNAME or alias' if *s* has an alias, else return 'PROPNAME',
        formatted for reST.

        e.g., for the line markerfacecolor property, which has an
        alias, return 'markerfacecolor or mfc' and for the transform
        property, which does not, return 'transform'.
        r#   c             s   s   | ]}d | V  qdS )z or %sNr   )rQ   rW   r   r   r   rR   g  s    z4ArtistInspector.aliased_name_rest.<locals>.<genexpr>z:meth:`%s <%s>`%s)r   r  r   r  )r   r   targetr  r   r   r   aliased_name_rest^  s    	"z!ArtistInspector.aliased_name_restNr  c             C   sx   |rd| }nd}|dk	r2| j |}d|||f S g }x<t| j D ],}| j |}| j|}|jd|||f  qDW |S )a  
        If *prop* is *None*, return a list of strings of all settable
        properties and their valid values.

        If *prop* is not *None*, it is a valid property name and that
        property will be returned as a string of property : valid
        values.
        r  r#   Nz%s%s: %s)r
  r  r  r  r   )r   r   leadingspacepadacceptslinesr   r   r   r   pprint_settersj  s    	



zArtistInspector.pprint_settersr   c       	         sj  |rd| nd|dk	r2j |}d||f S g }xvtj D ]f}xDjjD ]&}t|d| d}|rR|jdk	rRP qRW tjd| }|j||j d|j	 f qDW fdd|D }fd	d|D }t
d
d |D  t
dd |D d d   d d  }dd d d|d dj  d dj |f fddt||D |dfS )a$  
        If *prop* is *None*, return a list of reST-formatted strings of all
        settable properties and their valid values.

        If *prop* is not *None*, it is a valid property name and that
        property will be returned as a string of "property : valid"
        values.
        r  r#   Nz%s%s: %sr   .c                s,   g | ]$\}} j ||jd djddqS )z_base._AxesBaser  z
_axes.Axes)r  r  )rQ   r   r  )r   r   r   r     s   z7ArtistInspector.pprint_setters_rest.<locals>.<listcomp>c                s   g | ]\}} j |qS r   )r
  )rQ   r   _)r   r   r   r     s   c             s   s   | ]}t |V  qd S )N)r   )rQ   nr   r   r   rR     s    z6ArtistInspector.pprint_setters_rest.<locals>.<genexpr>c             s   s   | ]}t |V  qd S )N)r   )rQ   r   r   r   r   rR     s    z   =z
.. table::z   :class: property-tableZPropertyDescriptionc                s0   g | ](\}}d  |j   d  |j  qS )z   )ljust)rQ   r   r   )col0_lencol1_lenr  r   r   r     s   )r
  r  r  r   r   rU   r   r   r   r   maxr#  zip)	r   r   r  r  Zprop_and_qualnamesclsmethodr   Ztable_formatstrr   )r$  r%  r  r   r   pprint_setters_rest  sB    	



z#ArtistInspector.pprint_setters_restc                s   | j   fddt D }|j  i }xr|D ]j}t |}| j|rHq.y(tj  tjd | }W dQ R X W n tk
r   w.Y q.X |||dd < q.W |S )z3Return a dictionary mapping property name -> value.c                s(   g | ] }|j d rtt |r|qS )r   )r   rw   rU   )rQ   r   )r   r   r   r     s    z.ArtistInspector.properties.<locals>.<listcomp>ignoreNr   )	r   r   sortrU   r   warningscatch_warningssimplefilter	Exception)r   gettersrI   r   ri   r   r   )r   r   r     s     




zArtistInspector.propertiesc             C   s   g }xt | j j D ]\}}t|df f krPt|dkrPt|dd d }nt|}|jdd}t|dkr|dd d }| j|}|jd||f  qW |S )	z8Return the getters and actual values as list of strings.shape   Nz...
r  2   z    %s = %s)	r  r   rn   rU   r   r   r  r  r   )r   r  r   r   r   r   r   r   pprint_getters  s    
zArtistInspector.pprint_getters)Nr  )Nr   )r~   r   r   r   rF   r   r   compiler  r
  r  r  r   r  r  r  r*  r   r6  r   r   r   r   r     s   $

7r   c             C   s:   |dkr*t | }|j }tdj| dS t| d|  S )a  
    Return the value of an object's *property*, or print all of them.

    Parameters
    ----------
    obj : `.Artist`
        The queried artist; e.g., a `.Line2D`, a `.Text`, or an `~.axes.Axes`.

    property : str or None, default: None
        If *property* is 'somename', this function returns
        ``obj.get_somename()``.

        If is is None (or unset), it *prints* all gettable properties from
        *obj*.  Many properties have aliases for shorter typing, e.g. 'lw' is
        an alias for 'linewidth'.  In the output, aliases and full property
        names will be listed as:

          property or alias = value

        e.g.:

          linewidth or lw = 2
    Nr4  r   )r   r6  printr   rU   )objr   inspr   r   r   r   getp  s    r;  )filec               s   t | tr| g}nttj| }|s(dS t|d } r~t|dk r~|rdt|j|d d|d ntdj	|j |d dS t|d rt
dtdd	 t|ddd |d
dd D   fdd|D fdd|D  }ttj|S )a  
    Set a property on an artist object.

    matplotlib supports the use of :func:`setp` ("set property") and
    :func:`getp` to set and get object properties, as well as to do
    introspection on the object.  For example, to set the linestyle of a
    line to be dashed, you can do::

      >>> line, = plot([1, 2, 3])
      >>> setp(line, linestyle='--')

    If you want to know the valid types of arguments, you can provide
    the name of the property you want to set without a value::

      >>> setp(line, 'linestyle')
          linestyle: {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}

    If you want to see all the properties that can be set, and their
    possible values, you can do::

      >>> setp(line)
          ... long output listing omitted

    By default `setp` prints to `sys.stdout`, but this can be modified using
    the *file* keyword-only argument::

      >>> with fopen('output.log') as f:
      >>>     setp(line, file=f)

    :func:`setp` operates on a single instance or a iterable of
    instances. If you are in query mode introspecting the possible
    values, only the first instance in the sequence is used. When
    actually setting values, all the instances will be set.  e.g.,
    suppose you have a list of two lines, the following will make both
    lines thicker and red::

      >>> x = arange(0, 1, 0.01)
      >>> y1 = sin(2*pi*x)
      >>> y2 = sin(4*pi*x)
      >>> lines = plot(x, y1, x, y2)
      >>> setp(lines, linewidth=2, color='r')

    :func:`setp` works with the MATLAB style string/value pairs or
    with python kwargs.  For example, the following are equivalent::

      >>> setp(lines, 'linewidth', 2, 'color', 'r')  # MATLAB style
      >>> setp(lines, linewidth=2, color='r')        # python style
    Nr   r  )r   )r<  r4  z(The set args must be string, value pairsc             s   s   | ]\}}||fV  qd S )Nr   )rQ   r   r   r   r   r   rR   H  s    zsetp.<locals>.<genexpr>r   c                s   g | ]}|j  qS r   )r   )rQ   r   )funcvalsr   r   r   I  s    zsetp.<locals>.<listcomp>c                s   g | ]}|j f  qS r   )r   )rQ   r   )r   r   r   r   I  s    )rt   r"   r   r   flattenr   r   r8  r  r   r[   r   r'  )r9  r<  r   r   objsr:  r   r   )r=  r   r   setp  s     2
,$r@  c             C   s:   t | }tjd r$dj|jddS ddj|jdd S )a  
    Inspect an `~matplotlib.artist.Artist` class (using `.ArtistInspector`) and
    return information about its settable properties and their current values.

    Parameters
    ----------
    artist : `~matplotlib.artist.Artist` or an iterable of `Artist`\s

    Returns
    -------
    str
        The settable properties of *artist*, as plain text if
        :rc:`docstring.hardcopy` is False and as a rst table (intended for
        use in Sphinx) if it is True.
    zdocstring.hardcopyr4  r   )r  zProperties:
)r   r@   rA   r   r*  r  )r   Zair   r   r   kwdocM  s    rA  )r"   )N))collectionsr   r   	functoolsr   r   loggingnumbersr   r   r-  numpyr   Z
matplotlibr@   r#   r   r   r   r	   Z
transformsr
   r   r   r   r   r   	getLoggerr~   r{   r   r    r!   r"   r   r;  r  r@  rA  Zinterpdr   r   r   r   r   <module>   sB    
 
         !  
 L