B
    ]t\                 @   s   d dl mZm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
Z
ddlmZmZmZ ddlmZ ddlmZmZmZmZmZmZ dd	 Zd
d ZeddZG dd deZG dd deZdddZeZdd Z dd Z!ej"j#e!ed dS )    )OrderedDict
namedtuple)wrapsN   )cbook	docstringrcParams)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|   r|  |  d k	r&|   | |f||S |  d k	rR||   |   rb|  X d S )N)get_rasterizedZstart_rasterizingget_agg_filterZstart_filterZstop_filterZstop_rasterizing)artistrendererargskwargs)draw 0lib/python3.7/site-packages/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_callback=   s    r    _XYPairzx yc               @   s  e Zd ZdZd ZdZed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ed'd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Z d2d3 Z!d4d5 Z"d6d7 Z#d8d9 Z$ed'd:d;d< Z%d=d> Z&d?d@ Z'dAdB Z(dCdD Z)dEdF Z*dGdH Z+dIdJ Z,ddLdMZ-dNdO Z.dPdQ Z/dRdS Z0dTdU Z1dVdW Z2ddXdYZ3dZd[ Z4d\d] Z5d^d_ Z6d`da Z7dbdc Z8ddde Z9dfdg Z:dhdi Z;djdk Z<dldm Z=dndo Z>dpdq Z?drds Z@dtdu ZAdvdw ZBdxdy ZCdzd{ ZDd|d} ZEd~d ZFdd ZGdd ZHdd ZIdd ZJdd ZKedd ZLdd ZMdd ZNdd ZOdddZPdd ZQdd ZRedd ZSeSjdd ZSdKS )ArtistzW
    Abstract base class for someone who renders into a
    :class:`FigureCanvas`.
    r   )Zcolorc             C   s   d| _ d | _d | _d | _d | _d| _d| _d| _d | _d | _	d | _
d| _d| _d | _d | _d | _d | _d| _d| _d| _i | _y
d | _W n tk
r   Y nX d | _d | _d | _d | _td | _t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
_mouseovereventson_oid_propobserversr   AttributeError_remove_method_url_gid_snapr   _sketch_path_effectsr!   _sticky_edges
_in_layout)r   r   r   r   __init__R   sB    


zArtist.__init__c             C   s   | j  }d |d< |S )Nr&   )__dict__copy)r   dr   r   r   __getstate__w   s    
zArtist.__getstate__c             C   sr   | j dk	rf|  |  d| _d}t| drN| jrN| 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
        :meth:`matplotlib.axes.Axes.draw_idle`.  Call
        :meth:`matplotlib.axes.Axes.relim` to update the axes limits
        if desired.

        Note: :meth:`~matplotlib.axes.Axes.relim` will not see
        collections even if the collection was added to 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   remove~   s    

zArtist.removec             C   s0   | j }|dks|jdkrdS |j p.|j S )z5Return *True* if units are set on the *x* or *y* axesNF)r   xaxis
have_unitsyaxis)r   axr   r   r   rN      s    zArtist.have_unitsc             C   s.   t | dd}|dks|jdkr"|S |j|S )zjFor artists in an axes, if the xaxis has units support,
        convert *x* using xaxis unit type
        r   N)getattrrM   convert_units)r   xrP   r   r   r   convert_xunits   s    zArtist.convert_xunitsc             C   s.   t | dd}|dks|jdkr"|S |j|S )zjFor artists in an axes, if the yaxis has units support,
        convert *y* using yaxis unit type
        r   N)rQ   rO   rR   )r   yrP   r   r   r   convert_yunits   s    zArtist.convert_yunitsc             C   s   | j S )zg
        The :class:`~matplotlib.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| _|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
        If 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   || _ |  rd S |r,| jd k	r,| | | 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.
        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   sb   |  |}|  r^|  }|dk	r.t||}|  }|dk	r^|dk	r^| }t|| }|S )a  
        Like `Artist.get_window_extent`, but includes any clipping.

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

        Returns
        -------
        bbox : `.BboxBase`
            containing the bounding box (in figure pixel co-ordinates).
        N)rY   get_clip_onget_clip_boxr
   intersectionget_clip_pathZget_fully_transformed_pathZget_extents)r   r   ZbboxZclip_boxZ	clip_pathr   r   r   get_tightbbox   s    
zArtist.get_tightbboxc             C   s"   | j }|| j|< |  j d7  _ |S )z
        Adds a callback function that will be called whenever one of
        the :class:`Artist`'s properties changes.

        Returns an *id* that is useful for removing the callback with
        :meth:`remove_callback` later.
        r   )r8   r9   )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 )z
        Remove a callback based on its *id*.

        .. seealso::

            :meth:`add_callback`
               For adding callbacks

        N)r9   KeyError)r   r`   r   r   r   remove_callback'  s    
zArtist.remove_callbackc             C   s$   x| j  D ]\}}||  qW dS )zg
        Fire an event when property changed, calling all of the
        registered callbacks.
        N)r9   items)r   r`   r_   r   r   r   pchanged6  s    zArtist.pchangedc             C   s   | j S )z[
        Returns *True* if :class:`Artist` has a transform explicitly
        set.
        )r*   )r   r   r   r   is_transform_set>  s    zArtist.is_transform_setc             C   s   || _ d| _|   d| _dS )zk
        Set the artist transform.

        Parameters
        ----------
        t : `.Transform`
        TN)r)   r*   re   r   )r   tr   r   r   set_transformE  s    zArtist.set_transformc             C   sB   | j dkrt | _ n(t| j ts<t| j dr<| j | j| _ | j S )zl
        Return the :class:`~matplotlib.transforms.Transform`
        instance used by this artist.
        N_as_mpl_transform)r)   r   
isinstancer   rH   ri   r   )r   r   r   r   get_transformR  s    

zArtist.get_transformz2.2c             C   st   g }y |  |\}}|r"||  W n(   ddl}|  td| j Y nX x |  D ]}||| qXW |S )zX
        List the children of the artist which contain the mouse event *event*.
        r   Nzwhile checking)	containsappend	traceback	print_excprint	__class__get_childrenextendhitlist)r   eventLZ	hascursorinforn   ar   r   r   rt   ^  s    zArtist.hitlistc             C   s   g S )zd
        Return a list of the child :class:`Artist`s this
        :class:`Artist` contains.
        r   )r   r   r   r   rr   q  s    zArtist.get_childrenc             C   s0   t | jr| | |S td| jj  di fS )a  Test whether the artist contains the mouse event.

        Returns the truth value and a dictionary of artist specific details of
        selection, such as which points are contained in the pick radius.  See
        individual artists for details.
        z'%s' needs 'contains' methodF)callabler3   warningswarnrq   __name__)r   
mouseeventr   r   r   rl   x  s    
zArtist.containsc             C   s
   || _ dS )a  
        Replace the contains test used by this artist. The new picker
        should be a callable function which determines whether the
        artist is hit by the mouse event::

            hit, props = picker(artist, mouseevent)

        If the mouse event is over the artist, return *hit* = *True*
        and *props* is a dictionary of properties you want returned
        with the contains test.

        Parameters
        ----------
        picker : callable
        N)r3   )r   pickerr   r   r   set_contains  s    zArtist.set_containsc             C   s   | j S )zV
        Return the _contains test used by the artist, or *None* for default.
        )r3   )r   r   r   r   get_contains  s    zArtist.get_containsc             C   s    | j dk	o| j jdk	o| jdk	S )z-Return *True* if :class:`Artist` is pickable.N)r(   canvasr2   )r   r   r   r   pickable  s    
zArtist.pickablec             C   s   |   rN|  }t|r(|| |\}}n| |\}}|rN| jjj|| f| xB|  D ]6}t|dd}|j	dks|dks|j	|krX|
| qXW dS )z
        Process pick event

        each child artist will fire a pick event if *mouseevent* is over
        the artist and the artist has picker set
        r   N)r   
get_pickerry   rl   r(   r   Z
pick_eventrr   rQ   Zinaxespick)r   r}   r~   Zinsideproprx   rP   r   r   r   r     s    
zArtist.pickc             C   s
   || _ dS )a  
        Set the epsilon for picking used by this artist

        *picker* 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 float: if picker is a number it is interpreted as an
            epsilon tolerance in points and the artist will fire
            off an event if it's data is within epsilon of the mouse
            event.  For some artists like lines and patch collections,
            the artist may provide additional data to the pick event
            that is generated, e.g., the indices of the data within
            epsilon of the pick event

          * 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.

        Parameters
        ----------
        picker : None or bool or float or callable
        N)r2   )r   r~   r   r   r   
set_picker  s    "zArtist.set_pickerc             C   s   | j S )z-Return the picker object used by this artist.)r2   )r   r   r   r   r     s    zArtist.get_pickerzartist.figure is not Nonec             C   s
   | j dk	S )z6Returns whether the artist is assigned to a `.Figure`.N)r(   )r   r   r   r   is_figure_set  s    zArtist.is_figure_setc             C   s   | j S )zReturns the url.)r<   )r   r   r   r   get_url  s    zArtist.get_urlc             C   s
   || _ dS )zg
        Sets the url for the artist.

        Parameters
        ----------
        url : str
        N)r<   )r   Zurlr   r   r   set_url  s    zArtist.set_urlc             C   s   | j S )zReturns the group id.)r=   )r   r   r   r   get_gid  s    zArtist.get_gidc             C   s
   || _ dS )zn
        Sets 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 d r| jS dS dS )aS  
        Returns the snap setting which may be:

          * True: snap vertices to the nearest pixel center

          * False: leave vertices as-is

          * None: (auto) If the path contains only rectilinear line
            segments, round to the nearest pixel center

        Only supported by the Agg and MacOSX backends.
        z	path.snapFN)r   r>   )r   r   r   r   get_snap
  s    zArtist.get_snapc             C   s   || _ d| _dS )a  
        Sets the snap setting which may be:

          * True: snap vertices to the nearest pixel center

          * False: leave vertices as-is

          * None: (auto) If the path contains only rectilinear line
            segments, round to the nearest pixel center

        Only supported by the Agg and MacOSX backends.

        Parameters
        ----------
        snap : bool or None
        TN)r>   r   )r   Zsnapr   r   r   set_snap  s    zArtist.set_snapc             C   s   | j S )a  
        Returns the sketch parameters for the artist.

        Returns
        -------
        sketch_params : 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.

            May return `None` if no sketch parameters were set.
        )r?   )r   r   r   r   get_sketch_params0  s    zArtist.get_sketch_paramsNc             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)r?   r   )r   ZscalelengthZ
randomnessr   r   r   set_sketch_paramsF  s    zArtist.set_sketch_paramsc             C   s   || _ d| _dS )zrSet the path effects.

        Parameters
        ----------
        path_effects : `.AbstractPathEffect`
        TN)r@   r   )r   Zpath_effectsr   r   r   set_path_effectsb  s    zArtist.set_path_effectsc             C   s   | j S )N)r@   )r   r   r   r   get_path_effectsl  s    zArtist.get_path_effectsc             C   s   | j S )z4Return the `.Figure` instance the artist belongs to.)r(   )r   r   r   r   
get_figureo  s    zArtist.get_figurec             C   sH   | j |krdS | j dk	r td|| _ | j r>| j | k	r>|   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(   RuntimeErrorre   r   )r   Zfigr   r   r   
set_figures  s    	

zArtist.set_figurec             C   s   || _ |   d| _dS )zq
        Set the artist's clip `.Bbox`.

        Parameters
        ----------
        clipbox : `.Bbox`
        TN)r.   re   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 | | _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t|jt|j|   d| _dS )a  
        Set the artist's clip path, which may be:

        - a :class:`~matplotlib.patches.Patch` (or subclass) instance; or
        - a :class:`~matplotlib.path.Path` instance, in which case a
          :class:`~matplotlib.transforms.Transform` instance, which will be
          applied to the path before using it for clipping, must be provided;
          or
        - ``None``, to remove a previously set clipping path.

        For efficiency, if the path happens to be an axis-aligned rectangle,
        this method will set the clipping box to the corresponding rectangle
        and set the clipping path to ``None``.

        ACCEPTS: [(`~matplotlib.path.Path`, `.Transform`) | `.Patch` | None]
        r   )Patch	RectangleFNTz5Invalid arguments to set_clip_path, of type {} and {})Zmatplotlib.patchesr   r   rj   r   r
   Zunitrk   r.   r/   r   tupler	   r   	TypeErrorformattyper|   re   r   )r   pathZ	transformr   r   Zsuccessr   r   r   set_clip_path  s>    






zArtist.set_clip_pathc             C   s   | j S )zb
        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 artist's visiblity)r+   )r   r   r   r   get_visible  s    zArtist.get_visiblec             C   s   | j S )z"Return the artist's animated state)r,   )r   r   r   r   rX     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')``.
        )rB   )r   r   r   r   get_in_layout  s    	zArtist.get_in_layoutc             C   s   | j S )z#Return whether artist uses clipping)r0   )r   r   r   r   rZ     s    zArtist.get_clip_onc             C   s   | j S )zReturn artist clipbox)r.   )r   r   r   r   r[     s    zArtist.get_clip_boxc             C   s   | j S )zReturn artist clip path)r/   )r   r   r   r   r]     s    zArtist.get_clip_pathc             C   s   | j dk	r| 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_affine  s    

z+Artist.get_transformed_clip_path_and_affinec             C   s   || _ |   d| _dS )z
        Set whether artist uses clipping.

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

        Parameters
        ----------
        b : bool
        TN)r0   re   r   )r   br   r   r   set_clip_on  s    zArtist.set_clip_onc             C   sB   | j r*| jdk	r|| j || j n|d |d dS )z Set the clip properly for the gcN)r0   r.   Zset_clip_rectangler   r/   )r   gcr   r   r   _set_gc_clip  s    

zArtist._set_gc_clipc             C   s   | j S )z.Return whether the artist is to be rasterized.)r4   )r   r   r   r   r     s    zArtist.get_rasterizedc             C   s(   |rt | jdst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)rH   r   rz   r{   r4   )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.)r5   )r   r   r   r   r   +  s    zArtist.get_agg_filterc             C   s   || _ d| _dS )ap  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)r5   r   )r   Zfilter_funcr   r   r   set_agg_filter/  s    zArtist.set_agg_filterc             O   s   |   sdS d| _dS )zDerived classes drawing methodNF)r   r   )r   r   r   r   r   r   r   r   >  s    zArtist.drawc             C   s   || _ |   d| _dS )z
        Set the alpha value used for blending - not supported on all backends.

        Parameters
        ----------
        alpha : float
        TN)r-   re   r   )r   Zalphar   r   r   	set_alphaD  s    zArtist.set_alphac             C   s   || _ |   d| _dS )zf
        Set the artist's visibility.

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

        Parameters
        ----------
        b : bool
        N)r,   re   )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)rB   )r   Z	in_layoutr   r   r   set_in_layouth  s    zArtist.set_in_layoutc          	      sT   dd  t jdd  fdd| D }W dQ R X t|rP  d_|S )	zM
        Update this artist's properties from the dictionary *prop*.
        c             S   sL   |  }|dkrt| ||S t| d| d}t|s@td| ||S dS )a  Sorting out how to update property (setter or setattr).

            Parameters
            ----------
            k : str
                The name of property to update
            v : obj
                The value to assign to the property

            Returns
            -------
            ret : obj or None
                If using a `set_*` method return it's return, else None.
            >   r   set_NzUnknown property %s)lowersetattrrQ   ry   r:   )r   kvr_   r   r   r   _update_propertyy  s    z'Artist.update.<locals>._update_propertyF)r7   c                s   g | ]\}} ||qS r   r   ).0r   r   )r   r   r   r   
<listcomp>  s    z!Artist.update.<locals>.<listcomp>NT)r   Z_setattr_cmrd   lenre   r   )r   propsretr   )r   r   r   updateu  s    "zArtist.updatec             C   s   | j S )z1Get the label used for this artist in the legend.)r1   )r   r   r   r   	get_label  s    zArtist.get_labelc             C   s,   |dk	rt || _nd| _|   d| _dS )z
        Set the label to *s* for auto legend.

        Parameters
        ----------
        s : object
            *s* will be converted to a string by calling `str`.
        NT)strr1   re   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}|| _|   d| _dS )z
        Set the zorder for the artist.  Artists with lower zorder
        values are drawn first.

        Parameters
        ----------
        level : float
        NT)rq   r   re   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 usecase 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)

        )rA   )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dd | j
jdd< |j
jdd | j
jdd< |   d| _dS )z'Copy properties from *other* to *self*.NT)r)   r*   r+   r-   r.   r0   r/   r1   r?   r@   r   rS   rU   re   r   )r   otherr   r   r   update_from  s    zArtist.update_fromc             C   s   t |  S )zY
        return a dictionary mapping property name -> value for all Artist props
        )ArtistInspector
properties)r   r   r   r   r     s    zArtist.propertiesc                s(   t t| d fddd} |S )zBA property batch setter. Pass *kwargs* to set properties.
        Tc                s    j | d d| d fS )Nr   )_prop_orderget)rS   )r   r   r   <lambda>  s    zArtist.set.<locals>.<lambda>)reversekey)r   sortedrd   r   )r   r   r   r   )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|  D g }|r|| r|||  |S )a  
        Find artist objects.

        Recursively find all :class:`~matplotlib.artist.Artist` instances
        contained in self.

        *match* can be

          - None: return all objects contained in artist.

          - function with signature ``boolean = match(artist)``
            used to filter matches

          - class instance: e.g., Line2D.  Only return artists of class type.

        If *include_self* is True (default), include self in the list to be
        checked for a match.

        Nc             S   s   dS )NTr   )rS   r   r   r   	matchfunc  s    z!Artist.findobj.<locals>.matchfuncc                s
   t |  S )N)rj   )rS   )matchr   r   r     s    zFmatch must be None, a matplotlib.artist.Artist subclass, or a callablec                s   g | ]}|  qS r   )findobj)r   c)r   r   r   r     s    z"Artist.findobj.<locals>.<listcomp>)	rj   r   
issubclassr"   ry   rW   sumrr   rm   )r   r   Zinclude_selfZartistsr   )r   r   r   r     s    

zArtist.findobjc             C   s   dS )z8
        Get the cursor data for a given event.
        Nr   )r   ru   r   r   r   get_cursor_data  s    zArtist.get_cursor_datac          	   C   sL   y|d  W n t tfk
r*   |g}Y nX ddd |D }d| d S )z8
        Return *cursor data* string formatted.
        r   z, c             s   s.   | ]&}t |tjtjttfrd |V  qdS )z{:0.3g}N)rj   npZfloatingZintegerintfloatr   )r   itemr   r   r   	<genexpr>,  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 )N)r6   )r   r   r   r   	mouseover0  s    zArtist.mouseoverc             C   s:   t |}|| _| j}|r6|r*|j|  n|j|  d S )N)boolr6   r   rI   addrJ   )r   r   rP   r   r   r   r   4  s    )NNN)N)NT)Tr|   
__module____qualname____doc__Zanamer   dictr   rC   rG   rL   rN   rT   rV   propertyr   setterr   rY   r^   ra   rc   re   rf   rh   rk   r   Z
deprecatedrt   rr   rl   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rX   r   rZ   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"   E   s   
%.		$




6

&	
%r"   c               @   s   e Zd ZdZdd Zdd Ze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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|r,t|}t|r,|d }|| _t|sDt	|}|| _
|  | _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 `Artists` are of the same type) and it is your
        responsibility to make sure this is so.
        r   N)rj   r"   r   iterablelistr   ooriginspectZisclassr   oget_aliasesaliasd)r   r   r   r   r   rC   F  s    


zArtistInspector.__init__c                s    fddt  jD }i }xb|D ]Z}t j|} |s>q"td|dd |jd}|	|t
 |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 | ]"}| d rtt j|r|qS ))r   get_)
startswithry   rQ   r   )r   name)r   r   r   r   e  s    
z/ArtistInspector.get_aliases.<locals>.<listcomp>z`({}.*)`N   r   )dirr   rQ   is_aliasresearchr   r   group
setdefaultr   r   )r   namesaliasesr   r_   Zpropnamer   )r   r   r   Z  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|}|j}|dkrDdS |drRdS | j|}|dk	rzt	dd|
dS |jjd }td	||}|r|
dS dS )
a_  
        Get the legal arguments for the setter associated with *attr*.

        This is done by querying the docstring of the function *set_attr*
        for a line that begins with "ACCEPTS" or ".. ACCEPTS":

        e.g., for a line linestyle, return
        "[ ``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'steps'`` | ``'None'``
        ]"
        zset_%sz%s has no function %sNunknownz
alias for z
 * r   z(?m)^ *{} : (.+))rH   r   r:   rQ   r   r   _get_valid_values_regexr   r   subr   __code__co_varnamesr   )r   attrr   r_   r   r   Z
param_namer   r   r   get_valid_valuesv  s"    

z ArtistInspector.get_valid_valuesc             C   s   g }xt | jD ]}|ds qt| j|}t|s6qtt|j}|dk s| 	|rZq| jj
d | jj }x.| j D ] }||jkrz|j
d |j }P qzW | |}||dd |d | f qW |S )z
        Get the attribute strings and a full path to where the setter
        is defined for all setters in an object.
        r      .r   N)r   r   r   rQ   ry   r   r   Zgetfullargspecr   r   r   r|   mrorD   _replace_pathrm   )r   Zsettersr   r_   nargssource_classclsr   r   r   _get_setters_and_targets  s$    


"z(ArtistInspector._get_setters_and_targetsc             C   s0   ddd}x |  D ]\}}|||}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.
        ZAxes)z_base._AxesBasez
_axes.Axes)rd   replace)r   r	  Zreplace_dictr   valuer   r   r   r    s
    zArtistInspector._replace_pathc             C   s   dd |   D S )z
        Get the attribute strings with setters for object.  e.g., for a line,
        return ``['markerfacecolor', 'linewidth', ....]``.
        c             S   s   g | ]\}}|qS r   r   )r   r   targetr   r   r   r     s    z/ArtistInspector.get_setters.<locals>.<listcomp>)r  )r   r   r   r   get_setters  s    zArtistInspector.get_settersc             C   s   |j }|dkrdS |dS )z^
        Return *True* if method object *o* is an alias for another
        function.
        NFz
alias for )r   r   )r   r   Zdsr   r   r   r     s    zArtistInspector.is_aliasc             C   s4   || j kr,|ddd t| j | D  S |S 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   g | ]}d | qS )z or %sr   )r   rS   r   r   r   r     s   z0ArtistInspector.aliased_name.<locals>.<listcomp>N)r   r   r   )r   r   r   r   r   aliased_name  s    

zArtistInspector.aliased_namec             C   s<   || j kr*ddd t| j | D }nd}d|||f S )a.  
        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   g | ]}d | qS )z or %sr   )r   rS   r   r   r   r     s   z5ArtistInspector.aliased_name_rest.<locals>.<listcomp>z:meth:`%s <%s>`%s)r   r   r   )r   r   r  r   r   r   r   aliased_name_rest  s
    


z!ArtistInspector.aliased_name_restNr  c       	      C   s   |rd| }nd}|dk	r2|  |}d|||f S |  }|  g }x8|D ]0\}}|  |}| |}|d|||f  qLW |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  sortr  rm   )	r   r   leadingspacepadacceptsattrslinesr   r   r   r   r   pprint_setters  s    	



zArtistInspector.pprint_settersr   c                sN  |rd| nd|dk	r2 |}d||f S  }|  g }fdd|D }fdd|D }tdd	 |D  td
d	 |D |d |d  |d  d7 d   d d  }|d || |d d  d  || | fddt||D  || |d |S )a/  
        If *prop* is *None*, return a list of strings of all settable
        properties and their valid values.  Format the output for ReST

        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: %sc                s   g | ]\}}  ||qS r   )r  )r   r   r  )r   r   r   r   &  s   z7ArtistInspector.pprint_setters_rest.<locals>.<listcomp>c                s   g | ]\}}  |qS r   )r  )r   r   r  )r   r   r   r   (  s    c             s   s   | ]}t |V  qd S )N)r   )r   nr   r   r   r   *  s    z6ArtistInspector.pprint_setters_rest.<locals>.<genexpr>c             s   s   | ]}t |V  qd S )N)r   )r   rx   r   r   r   r   +  s    z
.. table::z   :class: property-tablez   =ZProperty   ZDescriptionc                s,   g | ]$\}}|  d   |  qS )r  )ljust)r   r  rx   )col0_lencol1_lenr  r   r   r   :  s   )r  r  r  maxrm   r  rs   zip)r   r   r  r  r  r  r   Ztable_formatstrr   )r  r  r  r   r   pprint_setters_rest  s:    	








z#ArtistInspector.pprint_setters_restc          
      s   | j   fddt D }|  t }xj|D ]b}t |}| |rJq0y(t  td | }W dQ R X W n   w0Y q0X |||dd < q0W |S )zD
        return a dictionary mapping property name -> value
        c                s(   g | ] }| d rtt |r|qS )r   )r   ry   rQ   )r   r   )r   r   r   r   F  s    z.ArtistInspector.properties.<locals>.<listcomp>ignoreNr   )	r   r   r  r   rQ   r   rz   catch_warningssimplefilter)r   ZgettersrF   r   r_   r   r   )r   r   r   A  s     




zArtistInspector.propertiesc             C   s   g }xt |   D ]\}}t|dddkrPt|dkrPt|dd d }nt|}|dd}t|dkr|dd d }| |}|d	||f  qW |S )
zJ
        Return the getters and actual values as list of strings.
        shaper      Nz...
r   2   z    %s = %s)	r   r   rd   rQ   r   r   r  r  rm   )r   r  r   r   r   r   r   r   pprint_gettersZ  s    
zArtistInspector.pprint_getters)Nr  )Nr   )r|   r   r   r   rC   r   r   compiler   r  r  r  r  r   r  r  r  r!  r   r)  r   r   r   r   r   @  s    %


1r   c             C   s>   |dkr*t | }| }td| dS t| d| }| S )aJ  
    Return the value of object's property.  *property* is an optional string
    for the property you want to return

    Example usage::

        getp(obj)  # get all the object properties
        getp(obj, 'linestyle')  # get the linestyle property

    *obj* is a :class:`Artist` instance, e.g.,
    :class:`~matplotllib.lines.Line2D` or an instance of a
    :class:`~matplotlib.axes.Axes` or :class:`matplotlib.text.Text`.
    If the *property* is 'somename', this function returns

      obj.get_somename()

    :func:`getp` can be used to query all the gettable properties with
    ``getp(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
    Nr'  r   )r   r)  rp   r   rQ   )objr   inspr   r_   r   r   r   getpm  s    r-  c                s  t | tr| g}ntt| }|s(dS t|d }i }dkrNd|d< st|dk r|r|t|j	|d df| ntd
|	 f| 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|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: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' ]

    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

    You may specify another output file to `setp` if `sys.stdout` is not
    acceptable for some reason 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,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   filer  )r   r'  z(The set args must be string, value pairsc             s   s   | ]\}}||fV  qd S )Nr   )r   r   r   r   r   r   r     s    zsetp.<locals>.<genexpr>r   c                s   g | ]}|  qS r   )r   )r   r   )funcvalsr   r   r     s    zsetp.<locals>.<listcomp>c                s   g | ]}|j f  qS r   )r   )r   r   )r   r   r   r     s    )rj   r"   r   r   Zflattenr   popr   rp   r  r   rW   r   r   )r+  r   r   Zobjsr,  Z	printArgsr   r   )r/  r   r   setp  s&    2
,$r1  c             C   s>   t jd }|r$dt| jddS dt| jddS dS )a  
    Inspect an `~matplotlib.artist.Artist` class and return
    information about its settable properties and their current values.

    It use the class `.ArtistInspector`.

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

    Returns
    -------
    string
        Returns a string with a list or rst table with the settable properties
        of the *artist*. The formating depends on the value of
        :rc:`docstring.hardcopy`. False result in a list that is intended for
        easy reading as a docstring and True result in a rst table intended
        for rendering the documentation with sphinx.
    zdocstring.hardcopyr'  r   )r  r  N)
matplotlibr   r   r   r!  r  )r   Zhardcopyr   r   r   kwdoc  s    

r3  )r"   )N)$collectionsr   r   	functoolsr   r   r   rz   Znumpyr   r2  r$   r   r   r   r   r	   Z
transformsr
   r   r   r   r   r   r   r    r!   objectr"   r   r-  r   r1  r3  Zinterpdr   r   r   r   r   <module>   s:    
          /
&Q