a
    Sicf@                 	   @   s  d 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
mZmZmZmZmZmZmZmZmZmZmZ ddlmZmZ eddgd	d
gddgg dddgdgdG dd dejejZ G dd de Z!G dd de!Z"G dd de!Z#G dd de#Z$G dd de!Z%G dd de%Z&G d d! d!e%Z'G d"d# d#e Z(G d$d% d%e(Z)G d&d' d'e!Z*G d(d) d)e Z+G d*d+ d+e Z,G d,d- d-e Z-G d.d/ d/e Z.dS )0ay  
Classes for the efficient drawing of large collections of objects that
share most properties, e.g., a large number of line segments or
polygons.

The classes are not meant to be as flexible as their single element
counterparts (e.g., you may not be able to select all line styles) but
they are meant to be fast for common use cases (e.g., a large set of solid
line segments).
    N)Number   )_api_pathartistcbookcmcolors
_docstringhatchlinespath
transforms)	JoinStyleCapStyleantialiasedsaa
edgecolorsec
facecolorsfc)
linestylesdashesls
linewidthslwtransOffset)antialiased	edgecolor	facecolor	linestyle	linewidthoffset_transformc                   @   s  e Zd ZdZedZdZej	e
jddddjd
dddZdd Zdd Zdd Zdd Ze
ddddd Zdd ZdkddZdd Zejd d! Ze
dd"d#d$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Z d4d5 Z!d6d7 Z"d8d9 Z#d:d; Z$ej	d<d= Z%d>d? Z&ej	d@dA Z'dBdC Z(e)dDdE Z*dFdG Z+dHdI Z,dJdK Z-dLdM Z.dNdO Z/dPdQ Z0dRdS Z1dTdU Z2dVdW Z3dXdY Z4dZd[ Z5d\d] Z6ej7j8je6_d^d_ Z9d`da Z:dbdc Z;ddde Z<dfdg Z=dhdi Z>dS )l
Collectiona  
    Base class for Collections. Must be subclassed to be usable.

    A Collection represents a sequence of `.Patch`\es that can be drawn
    more efficiently together than individually. For example, when a single
    path is being drawn repeatedly at different offsets, the renderer can
    typically execute a ``draw_marker()`` call much more efficiently than a
    series of repeated calls to ``draw_path()`` with the offsets put in
    one-by-one.

    Most properties of a collection can be configured per-element. Therefore,
    Collections have "plural" versions of many of the properties of a `.Patch`
    (e.g. `.Collection.get_paths` instead of `.Patch.get_path`). Exceptions are
    the *zorder*, *hatch*, *pickradius*, *capstyle* and *joinstyle* properties,
    which can only be set globally for the whole collection.

    Besides these exceptions, all properties can be specified as single values
    (applying to all elements) or sequences of values. The property of the
    ``i``\th element of the collection is::

      prop[i % len(prop)]

    Each Collection can optionally be used as its own `.ScalarMappable` by
    passing the *norm* and *cmap* parameters to its constructor. If the
    Collection's `.ScalarMappable` matrix ``_A`` has been set (via a call
    to `.Collection.set_array`), then at draw time this internal scalar
    mappable will be used to set the ``facecolors`` and ``edgecolors``,
    ignoring those that were manually passed in.
    r      r%   F3.6r   nameNsolid      @r   zorderc                K   s>  t j|  tj| |
| dg| _dg| _dg| _dg| _d| _	d| _
d| _ttjd | _| | | | | | | | | | | | | | | | | | |r| | nd| _|r| | nd| _|durt|t }|j!dkr|dddf }|| _"|	| _#d| _$| %| d| _&dS )a'  
        Parameters
        ----------
        edgecolors : color or list of colors, default: :rc:`patch.edgecolor`
            Edge color for each patch making up the collection. The special
            value 'face' can be passed to make the edgecolor match the
            facecolor.
        facecolors : color or list of colors, default: :rc:`patch.facecolor`
            Face color for each patch making up the collection.
        linewidths : float or list of floats, default: :rc:`patch.linewidth`
            Line width for each patch making up the collection.
        linestyles : str or tuple or list thereof, default: 'solid'
            Valid strings are ['solid', 'dashed', 'dashdot', 'dotted', '-',
            '--', '-.', ':']. Dash tuples should be of the form::

                (offset, onoffseq),

            where *onoffseq* is an even length tuple of on and off ink lengths
            in points. For examples, see
            :doc:`/gallery/lines_bars_and_markers/linestyles`.
        capstyle : `.CapStyle`-like, default: :rc:`patch.capstyle`
            Style to use for capping lines for all paths in the collection.
            Allowed values are %(CapStyle)s.
        joinstyle : `.JoinStyle`-like, default: :rc:`patch.joinstyle`
            Style to use for joining lines for all paths in the collection.
            Allowed values are %(JoinStyle)s.
        antialiaseds : bool or list of bool, default: :rc:`patch.antialiased`
            Whether each patch in the collection should be drawn with
            antialiasing.
        offsets : (float, float) or list thereof, default: (0, 0)
            A vector by which to translate each patch after rendering (default
            is no translation). The translation is performed in screen (pixel)
            coordinates (i.e. after the Artist's transform is applied).
        offset_transform : `~.Transform`, default: `.IdentityTransform`
            A single transform which will be applied to each *offsets* vector
            before it is used.
        cmap, norm
            Data normalization and colormapping parameters. See
            `.ScalarMappable` for a detailed description.
        hatch : str, optional
            Hatching pattern to use in filled paths, if any. Valid strings are
            ['/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*']. See
            :doc:`/gallery/shapes_and_collections/hatch_style_reference` for
            the meaning of each hatch type.
        pickradius : float, default: 5.0
            If ``pickradius <= 0``, then `.Collection.contains` will return
            ``True`` whenever the test point is inside of one of the polygons
            formed by the control points of a Path in the Collection. On the
            other hand, if it is greater than 0, then we instead check if the
            test point is contained in a stroke of width ``2*pickradius``
            following any of the Paths in the Collection.
        urls : list of str, default: None
            A URL for each patch to link to once drawn. Currently only works
            for the SVG backend. See :doc:`/gallery/misc/hyperlinks_sgskip` for
            examples.
        zorder : float, default: 1
            The drawing order, shared by all Patches in the Collection. See
            :doc:`/gallery/misc/zorder_demo` for all defaults and examples.
        )r   Nr   Nzhatch.color   )'r   Artist__init__r   ScalarMappable_us_linestyles_linestyles_us_lw_linewidths_face_is_mapped_edge_is_mapped_mapped_colorsmcolorsto_rgbamplrcParams_hatch_colorset_facecolorset_edgecolorset_linewidthset_linestyleset_antialiasedset_pickradiusset_urls	set_hatchZ
set_zorderset_capstyle	_capstyleset_joinstyle
_joinstylenp
asanyarrayfloatshape_offsets_offset_transformZ_path_effects_internal_update_paths)selfr   r   r   r   capstyle	joinstyler   offsetsr"   normcmap
pickradiusr   urlsr,   kwargs r[   R/var/www/html/django/DPS/env/lib/python3.9/site-packages/matplotlib/collections.pyr0   M   sD    P










zCollection.__init__c                 C   s   | j S NrQ   rR   r[   r[   r\   	get_paths   s    zCollection.get_pathsc                 C   s   t d S r]   )NotImplementedErrorrR   pathsr[   r[   r\   	set_paths   s    zCollection.set_pathsc                 C   s   | j S r]   )_transformsr_   r[   r[   r\   get_transforms   s    zCollection.get_transformsc                 C   sF   | j du rt | _ n*t| j tjs@t| j dr@| j | j| _ | j S )z<Return the `.Transform` instance used by this artist offset.N_as_mpl_transform)rO   r   IdentityTransform
isinstance	Transformhasattrrg   axesr_   r[   r[   r\   get_offset_transform   s    

zCollection.get_offset_transformr   r"   c                 C   s
   || _ dS )z
        Set the artist offset transform.

        Parameters
        ----------
        offset_transform : `.Transform`
        N)rO   )rR   r"   r[   r[   r\   set_offset_transform   s    	zCollection.set_offset_transformc                    s  |    |  }t|tjs0||s0tj S |  }| 	 }t
|sRtj S  jsj fdd|D }t |rt|tjjr|tj}t  | ||  |||  S | jd ur|| |}tj|}|j stj }|| |S tj S )Nc                    s   g | ]}  |qS r[   transform_path_non_affine.0p	transformr[   r\   
<listcomp>      z*Collection.get_datalim.<locals>.<listcomp>)get_transformrm   ri   r   rh   contains_branchBboxnullget_offsetsr`   len	is_affineanycontains_branch_seperatelyrJ   maMaskedArrayfillednanmpathget_path_collection_extents
get_affinerf   transform_non_affinefrozenrN   ru   masked_invalidmaskallupdate_from_data_xy)rR   	transData
offset_trfrU   rc   bboxr[   rt   r\   get_datalim   s:    




zCollection.get_datalimc                 C   s   |  t S r]   )r   r   rh   rR   rendererr[   r[   r\   get_window_extent/  s    zCollection.get_window_extentc              	      s0  |    |  }|  }|  }|  rg }|  D ]^}|j}|d d df |d d df  }}| |}| |}|t	
t||g|j q4| |d d df }| |d d df }t||g} js fdd|D }   |js||}| }t|tjjr$|tj} |||fS )Nr   r   c                    s   g | ]}  |qS r[   ro   )rr   r   rt   r[   r\   rv   I  s   z.Collection._prepare_points.<locals>.<listcomp>)rx   rm   r|   r`   
have_unitsverticesconvert_xunitsconvert_yunitsappendr   PathrJ   column_stackcodesr~   r   r   ri   r   r   r   r   )rR   r   rU   rc   r   r   xsysr[   rt   r\   _prepare_points4  s4    "

 

zCollection._prepare_pointsc                 C   s  |   sd S || jj|   |   |  \}}}}| }| | |	| 
  | jrv|| j || j |  d ur|j|    |  rddlm} ||  |}|  }|  }	|  }
d}t|dkrt|dkrt|	dkrt|
dkrt| jdkrtdd | jD rt| jdkrt| jdkr|  d u rt|rxt|d | }n|}|d  |}|j!| j"j#j!k r|j$| j"j#j$k rd}| j%r|&| j% | j'r|(| j' |r^|)t*|
d  |+| jd  |j,| jd   |-| jd  |.| jd  |/||d |0 t12||t*|	d  n:|3||0 ||  |||  |  | j| j| j| jd |4  |5| jj d| _6d S )	Nr   )PathEffectRendererFr   c                 s   s   | ]}|d  du V  qdS )r   Nr[   )rr   r   r[   r[   r\   	<genexpr>~  rw   z"Collection.draw.<locals>.<genexpr>Tscreen)7get_visible
open_group	__class____name__get_gidupdate_scalarmappabler   new_gc_set_gc_clipset_snapget_snap_hatchrE   set_hatch_colorr=   Zget_sketch_paramsZset_sketch_paramsZget_path_effectsZmatplotlib.patheffectsr   rf   get_facecolorget_edgecolorr}   r5   r   r3   _antialiaseds_urls	get_hatchr   Affine2Dget_extentswidthfigurer   heightrI   rH   rG   rF   Zset_foregroundtupler@   Z
set_dashesrB   Zset_urlZdraw_markersr   r   r   Zdraw_path_collectionrestoreclose_groupstale)rR   r   ru   r   rU   rc   gcr   transr   r   Zdo_single_path_optimizationZcombined_transformextentsr[   r[   r\   drawX  s    






zCollection.drawprrX   c                 C   s
   || _ dS )z
        Set the pick radius used for containment tests.

        Parameters
        ----------
        pickradius : float
            Pick radius, in points.
        N_pickradius)rR   rX   r[   r[   r\   rC     s    
zCollection.set_pickradiusc                 C   s   | j S r]   r   r_   r[   r[   r\   get_pickradius  s    zCollection.get_pickradiusc           
      C   s   |  |\}}|dur||fS |  s.di fS t| jtrN| jdurNt| jn| j}| jrd| j  | 	 \}}}}t
|j|j|| ||  |||dk	}	t|	dkt|	dfS )z
        Test whether the mouse event occurred in the collection.

        Returns ``bool, dict(ind=itemlist)``, where every item in itemlist
        contains the event.
        NFTr   )ind)Z_default_containsr   ri   Z_pickerr   rL   r   rl   Z_unstale_viewLimr   r   point_in_path_collectionxyr   rf   r}   dict)
rR   Z
mouseeventinsideinforX   ru   r   rU   rc   r   r[   r[   r\   contains  s(    



zCollection.containsc                 C   s   |dur|ndg| _ d| _dS )z
        Parameters
        ----------
        urls : list of str or None

        Notes
        -----
        URLs are currently only implemented by the SVG backend. They are
        ignored by all other backends.
        NT)r   r   )rR   rY   r[   r[   r\   rD     s    zCollection.set_urlsc                 C   s   | j S )z
        Return a list of URLs, one for each element of the collection.

        The list contains *None* for elements without a URL. See
        :doc:`/gallery/misc/hyperlinks_sgskip` for an example.
        )r   r_   r[   r[   r\   get_urls  s    zCollection.get_urlsc                 C   s   t | || _d| _dS )a  
        Set the hatching pattern

        *hatch* can be one of::

          /   - diagonal hatching
          \   - back diagonal
          |   - vertical
          -   - horizontal
          +   - crossed
          x   - crossed diagonal
          o   - small circle
          O   - large circle
          .   - dots
          *   - stars

        Letters can be combined, in which case all the specified
        hatchings are done.  If same letter repeats, it increases the
        density of hatching of that pattern.

        Hatching is supported in the PostScript, PDF, SVG and Agg
        backends only.

        Unlike other properties such as linewidth and colors, hatching
        can only be specified for the collection as a whole, not separately
        for each member.

        Parameters
        ----------
        hatch : {'/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
        TN)mhatchZ_validate_hatch_patternr   r   )rR   r   r[   r[   r\   rE     s    !
zCollection.set_hatchc                 C   s   | j S )z$Return the current hatching pattern.)r   r_   r[   r[   r\   r     s    zCollection.get_hatchc              
   C   sr   t |}|jdkr$|dddf }t t | |dddf dt | |dddf df| _d| _dS )z
        Set the offsets for the collection.

        Parameters
        ----------
        offsets : (N, 2) or (2,) array-like
        r-   Nr   rL   r   T)	rJ   rK   rM   r   asarrayr   r   rN   r   )rR   rU   r[   r[   r\   set_offsets  s    

zCollection.set_offsetsc                 C   s   | j du rtdS | j S )z&Return the offsets for the collection.N)r   r.   )rN   rJ   zerosr_   r[   r[   r\   r|   *  s    zCollection.get_offsetsc                 C   s
   t jd S )Nzpatch.linewidthr;   r<   r_   r[   r[   r\   _get_default_linewidth/  s    z!Collection._get_default_linewidthc                 C   sD   |du r|   }tt|| _| | j| j\| _| _d| _	dS )z
        Set the linewidth(s) for the collection.  *lw* can be a scalar
        or a sequence; if it is a sequence the patches will cycle
        through the sequence

        Parameters
        ----------
        lw : float or list of floats
        NT)
r   rJ   
atleast_1dr   r4   _bcast_lwlsr2   r5   r3   r   )rR   r   r[   r[   r\   r@   3  s    
zCollection.set_linewidthc              
   C   s   z\t |tr(tj||}t|g}n2zt|g}W n  tyX   dd |D }Y n0 W n4 ty } ztd||W Y d}~n
d}~0 0 || _	| 
| j| j	\| _| _dS )a  
        Set the linestyle(s) for the collection.

        ===========================   =================
        linestyle                     description
        ===========================   =================
        ``'-'`` or ``'solid'``        solid line
        ``'--'`` or  ``'dashed'``     dashed line
        ``'-.'`` or  ``'dashdot'``    dash-dotted line
        ``':'`` or ``'dotted'``       dotted line
        ===========================   =================

        Alternatively a dash tuple of the following form can be provided::

            (offset, onoffseq),

        where ``onoffseq`` is an even length tuple of on and off ink in points.

        Parameters
        ----------
        ls : str or tuple or list thereof
            Valid values for individual linestyles include {'-', '--', '-.',
            ':', '', (offset, on-off-seq)}. See `.Line2D.set_linestyle` for a
            complete description.
        c                 S   s   g | ]}t |qS r[   )mlines_get_dash_patternrr   r   r[   r[   r\   rv   i  rw   z,Collection.set_linestyle.<locals>.<listcomp>z)Do not know how to convert {!r} to dashesN)ri   strr   	ls_mappergetr   r   
ValueErrorformatr2   r   r4   r5   r3   )rR   r   r   errr[   r[   r\   rA   G  s$    
zCollection.set_linestylec                 C   s   t || _dS )z
        Set the `.CapStyle` for the collection (for all its elements).

        Parameters
        ----------
        cs : `.CapStyle` or %(CapStyle)s
        N)r   rG   )rR   csr[   r[   r\   rF   v  s    	zCollection.set_capstylec                 C   s   | j jS r]   )rG   r(   r_   r[   r[   r\   get_capstyle  s    zCollection.get_capstylec                 C   s   t || _dS )z
        Set the `.JoinStyle` for the collection (for all its elements).

        Parameters
        ----------
        js : `.JoinStyle` or %(JoinStyle)s
        N)r   rI   )rR   jsr[   r[   r\   rH     s    	zCollection.set_joinstylec                 C   s   | j jS r]   )rI   r(   r_   r[   r[   r\   get_joinstyle  s    zCollection.get_joinstylec                 C   sz   t jd r| |fS t|t| kr^t|}t| }t||}t|||  }t| ||  } dd t|| D }| |fS )a  
        Internal helper function to broadcast + scale ls/lw

        In the collection drawing code, the linewidth and linestyle are cycled
        through as circular buffers (via ``v[i % len(v)]``).  Thus, if we are
        going to scale the dash pattern at set time (not draw time) we need to
        do the broadcasting now and expand both lists to be the same length.

        Parameters
        ----------
        linewidths : list
            line widths of collection
        dashes : list
            dash specification (offset, (dash pattern tuple))

        Returns
        -------
        linewidths, dashes : list
            Will be the same length, dashes are scaled by paired linewidth
        z_internal.classic_modec                 S   s"   g | ]\\}}}t |||qS r[   )r   Z_scale_dashes)rr   odr   r[   r[   r\   rv     s   
z*Collection._bcast_lwls.<locals>.<listcomp>)r;   r<   r}   mathgcdlistzip)r   r   Zl_dashesZl_lwr   r[   r[   r\   r     s    
zCollection._bcast_lwlsc                 C   s.   |du r|   }tt|t| _d| _dS )z
        Set the antialiasing state for rendering.

        Parameters
        ----------
        aa : bool or list of bools
        NT)_get_default_antialiasedrJ   r   r   boolr   r   )rR   r   r[   r[   r\   rB     s    zCollection.set_antialiasedc                 C   s
   t jd S )Nzpatch.antialiasedr   r_   r[   r[   r\   r     s    z#Collection._get_default_antialiasedc                 C   s   |  | | | dS )a&  
        Set both the edgecolor and the facecolor.

        Parameters
        ----------
        c : color or list of rgba tuples

        See Also
        --------
        Collection.set_facecolor, Collection.set_edgecolor
            For setting the edge or face color individually.
        N)r>   r?   rR   cr[   r[   r\   	set_color  s    
zCollection.set_colorc                 C   s
   t jd S )Nzpatch.facecolorr   r_   r[   r[   r\   _get_default_facecolor  s    z!Collection._get_default_facecolorc                 C   s*   |d u r|   }t|| j| _d| _d S NT)r   r9   to_rgba_array_alpha_facecolorsr   r   r[   r[   r\   _set_facecolor  s    zCollection._set_facecolorc                 C   s2   t |tr| dv r| }|| _| | dS )aY  
        Set the facecolor(s) of the collection. *c* can be a color (all patches
        have same color), or a sequence of colors; if it is a sequence the
        patches will cycle through the sequence.

        If *c* is 'none', the patch will not be filled.

        Parameters
        ----------
        c : color or list of colors
        nonefaceN)ri   r   lower_original_facecolorr   r   r[   r[   r\   r>     s    zCollection.set_facecolorc                 C   s   | j S r]   )r   r_   r[   r[   r\   r     s    zCollection.get_facecolorc                 C   s    t | jdr|  S | jS d S )Nr   )r   
_str_equal_edgecolorsr   r_   r[   r[   r\   r     s    zCollection.get_edgecolorc                 C   s
   t jd S )Nzpatch.edgecolorr   r_   r[   r[   r\   _get_default_edgecolor  s    z!Collection._get_default_edgecolorc                 C   s   d}|d u r<t jd s*| js*t| jdr4|  }nd}d}t|drXd| _d| _	d S t
|| j| _|rt| jrt| jd | _d| _	d S )NTzpatch.force_edgecolorr   Fr   r   )r;   r<   _edge_defaultr   r   r   r   _str_lower_equalr   r   r9   r   r   r}   r   r=   )rR   r   r   r[   r[   r\   _set_edgecolor  s$    

zCollection._set_edgecolorc                 C   s2   t |tr| dv r| }|| _| | dS )a  
        Set the edgecolor(s) of the collection.

        Parameters
        ----------
        c : color or list of colors or 'face'
            The collection edgecolor(s).  If a sequence, the patches cycle
            through it.  If 'face', match the facecolor.
        r   N)ri   r   r   _original_edgecolorr   r   r[   r[   r\   r?     s    zCollection.set_edgecolorc                 C   s*   t j| | | | j | | j dS )a  
        Set the transparency of the collection.

        Parameters
        ----------
        alpha : float or array of float or None
            If not None, *alpha* values must be between 0 and 1, inclusive.
            If an array is provided, its length must match the number of
            elements in the collection.  Masked values and nans are not
            supported.
        N)r   r/   _set_alpha_for_arrayr   r   r   r   )rR   alphar[   r[   r\   	set_alpha'  s    zCollection.set_alphac                 C   s   | j S r]   )r5   r_   r[   r[   r\   get_linewidth9  s    zCollection.get_linewidthc                 C   s   | j S r]   )r3   r_   r[   r[   r\   get_linestyle<  s    zCollection.get_linestylec                 C   s   | j }| j}d| _ d| _| jdur\t| jdsLd| _t| jdr\d| _ n| jdu r\d| _ | jpf| j }|du p|du p| j |kp| j|k}|p|S )aF  
        Determine whether edges and/or faces are color-mapped.

        This is a helper for update_scalarmappable.
        It sets Boolean flags '_edge_is_mapped' and '_face_is_mapped'.

        Returns
        -------
        mapping_change : bool
            True if either flag is True, or if a flag has changed.
        FNr   Tr   )r7   r6   _Ar   r   r   r   )rR   Zedge0Zface0mappedchangedr[   r[   r\   _set_mappable_flags?  s$    

zCollection._set_mappable_flagsc                 C   s   |   sdS | jdur| jjdkr4t| ts4tdt| jr| jj	| jj	krntd| jj
 d| jj
 d| j| jj
| _| | j| j| _| jr| j| _n| | j | jr| j| _n| | j d| _dS )z
        Update colors from the scalar mappable array, if any.

        Assign colors to edges and faces based on the array and/or
        colors that were directly set, as appropriate.
        Nr   z&Collections can only map rank 1 arrayszData array shape, z) is incompatible with alpha array shape, z. This can occur with the deprecated behavior of the "flat" shading option, in which a row and/or column of the data array is dropped.T)r  r  ndimri   QuadMeshr   rJ   iterabler   sizerM   reshaper:   r8   r6   r   r   r   r7   r   r   r   r   r_   r[   r[   r\   r   a  s*    
	

z Collection.update_scalarmappablec                 C   s   t | jd S )zReturn whether face is colored.r   )r   r   r   r_   r[   r[   r\   get_fill  s    zCollection.get_fillc                 C   s   t j| | |j| _|j| _|j| _|j| _|j| _|j| _|j	| _	|j
| _
|j| _|j| _|j| _|j| _|j| _|j| _|j| _|j| _d| _dS )z#Copy properties from other to self.TN)r   r/   update_fromr   r8   r7   r   r   r6   r   r   r5   r3   r2   r   r   r  rV   rW   r   )rR   otherr[   r[   r\   r    s$    zCollection.update_from)NNNr)   NNNNNNNr*   NN)N)?r   
__module____qualname____doc__rJ   emptyre   r   r
   interpdr   make_keyword_onlyr0   r`   rd   rf   rm   rename_parameterrn   r   r   r   r   allow_rasterizationr   rC   r   r   rD   r   rE   r   r   r|   r   r@   rA   rF   r   rH   r   staticmethodr   rB   r   r   r   r   r>   r   r   r   r   r?   r  r/   r   r  r  r  r   r  r  r[   r[   r[   r\   r#      s   	#
              ~


D
$
M
%	%/




%"&r#   c                       s<   e Zd ZdZdZdd Zd
ddZej fdd	Z	  Z
S )_CollectionWithSizeszA
    Base class for collections that have an array of sizes.
          ?c                 C   s   | j S )z
        Return the sizes ('areas') of the elements in the collection.

        Returns
        -------
        array
            The 'area' of each element.
        )_sizesr_   r[   r[   r\   	get_sizes  s    	z_CollectionWithSizes.get_sizes      R@c                 C   s   |du r"t g | _t d| _nzt || _t t| jddf| _t | j| d | j	 }|| jddddf< || jddddf< d| jddddf< d	| _
dS )
aA  
        Set the sizes of each member of the collection.

        Parameters
        ----------
        sizes : ndarray or None
            The size to set for each element of the collection.  The
            value is the 'area' of the element.
        dpi : float, default: 72
            The dpi of the canvas.
        Nr$   r%   r  r   r   r  r.   T)rJ   arrayr  r  re   r   r   r}   sqrt_factorr   )rR   sizesdpiscaler[   r[   r\   	set_sizes  s    z_CollectionWithSizes.set_sizesc                    s"   |  | j| jj t | d S r]   )r%  r  r   r#  superr   r   r   r[   r\   r     s    z_CollectionWithSizes.draw)r  )r   r  r  r  r!  r  r%  r   r  r   __classcell__r[   r[   r'  r\   r    s   
r  c                       sH   e Zd ZdZd fdd	Zdd Zdd Zd	d
ddd fddZ  ZS )PathCollectionzO
    A collection of `~.path.Path`\s, as created by e.g. `~.Axes.scatter`.
    Nc                    s0   t  jf i | | | | | d| _dS )a  
        Parameters
        ----------
        paths : list of `.path.Path`
            The paths that will make up the `.Collection`.
        sizes : array-like
            The factor by which to scale each drawn `~.path.Path`. One unit
            squared in the Path's data space is scaled to be ``sizes**2``
            points when rendered.
        **kwargs
            Forwarded to `.Collection`.
        TN)r&  r0   rd   r%  r   )rR   rc   r"  rZ   r'  r[   r\   r0     s    

zPathCollection.__init__c                 C   s   || _ d| _d S r   rQ   r   rb   r[   r[   r\   rd     s    zPathCollection.set_pathsc                 C   s   | j S r]   r^   r_   r[   r[   r\   r`     s    zPathCollection.get_pathsr	   autoc                 C   s   | S r]   r[   )r   r[   r[   r\   <lambda>  rw   zPathCollection.<lambda>c                 K   s  g }g }|   du}|du r.tjjddd}nt|trDtj|}|  |dkr|sjt	d ||fS t
|   }	|dtjd }
n4|d	krt
|  }	|d
d}ntd| d||	}|j| |  |j| |  |dkrd}t|	|krd}|du r,|	}||}n|dkr@|   }n|d	krR|  }t|tjjrh|}n<t
|rtj|}n"t|}tjj||d g dd}||| || }||| k||| k@ }|| }t
| | d}||}t
|}t
||| || }|  d |   d|}t!||D ]\}}|dkrn| "| #|}n&|d	krt
$|}
t
%|
drqJt&j'dgdgfd||
| ( d d|}|)| t*|dr|+| ||}|)| qJ||fS )a
  
        Create legend handles and labels for a PathCollection.

        Each legend handle is a `.Line2D` representing the Path that was drawn,
        and each label is a string what each Path represents.

        This is useful for obtaining a legend for a `~.Axes.scatter` plot;
        e.g.::

            scatter = plt.scatter([1, 2, 3],  [4, 5, 6],  c=[7, 2, 3])
            plt.legend(*scatter.legend_elements())

        creates three legend elements, one for each color with the numerical
        values passed to *c* as the labels.

        Also see the :ref:`automatedlegendcreation` example.

        Parameters
        ----------
        prop : {"colors", "sizes"}, default: "colors"
            If "colors", the legend handles will show the different colors of
            the collection. If "sizes", the legend will show the different
            sizes. To set both, use *kwargs* to directly edit the `.Line2D`
            properties.
        num : int, None, "auto" (default), array-like, or `~.ticker.Locator`
            Target number of elements to create.
            If None, use all unique elements of the mappable array. If an
            integer, target to use *num* elements in the normed range.
            If *"auto"*, try to determine which option better suits the nature
            of the data.
            The number of created elements may slightly deviate from *num* due
            to a `~.ticker.Locator` being used to find useful locations.
            If a list or array, use exactly those elements for the legend.
            Finally, a `~.ticker.Locator` can be provided.
        fmt : str, `~matplotlib.ticker.Formatter`, or None (default)
            The format or formatter to use for the labels. If a string must be
            a valid input for a `.StrMethodFormatter`. If None (the default),
            use a `.ScalarFormatter`.
        func : function, default: ``lambda x: x``
            Function to calculate the labels.  Often the size (or color)
            argument to `~.Axes.scatter` will have been pre-processed by the
            user using a function ``s = f(x)`` to make the markers visible;
            e.g. ``size = np.log10(x)``.  Providing the inverse of this
            function here allows that pre-processing to be inverted, so that
            the legend labels have the correct values; e.g. ``func = lambda
            x: 10**x``.
        **kwargs
            Allowed keyword arguments are *color* and *size*. E.g. it may be
            useful to set the color of the markers if *prop="sizes"* is used;
            similarly to set the size of the markers if *prop="colors"* is
            used. Any further parameters are passed onto the `.Line2D`
            instance. This may be useful to e.g. specify a different
            *markeredgecolor* or *alpha* for the legend handles.

        Returns
        -------
        handles : list of `.Line2D`
            Visual representation of each element of the legend.
        labels : list of str
            The string labels for elements of the legend.
        NFT)	useOffsetuseMathTextr	   zfCollection without array used. Make sure to specify the values to be colormapped via the `c` argument.r  zlines.markersizer"  colorkz?Valid values for `prop` are 'colors' or 'sizes'. You supplied 'z
' instead.r+  	   r   )r   r.   g      @r%            
   )nbinsmin_n_tickssteps   r   )markeredgewidthr  g         )r   r/  msmarkerset_locs),	get_arrayr;   tickerScalarFormatterri   r   StrMethodFormattercreate_dummy_axiswarningswarnrJ   uniquepopr<   r  r   axisset_view_intervalminmaxset_data_intervalr}   Locatorr  FixedLocatorintMaxNLocatortick_valueslinspaceargsortinterpget_linewidths	get_alphar   rW   rV   r   iscloser   Line2Dr`   r   rk   r>  )rR   propnumfmtfuncrZ   handleslabelsZhasarrayur  r/  Zfuvalueslabel_valuesarrloccondZyarrxarrixkwvallabhlr[   r[   r\   legend_elements  s    ?
















zPathCollection.legend_elements)N)	r   r  r  r  r0   rd   r`   rl  r(  r[   r[   r'  r\   r)    s   r)  c                       sB   e Zd Zejdddd fdd	Zddd	ZeZd
d Z  Z	S )PolyCollectionr&   closedr'   NTc                    s2   t  jf i | | | | || d| _dS )aA  
        Parameters
        ----------
        verts : list of array-like
            The sequence of polygons [*verts0*, *verts1*, ...] where each
            element *verts_i* defines the vertices of polygon *i* as a 2D
            array-like of shape (M, 2).
        sizes : array-like, default: None
            Squared scaling factors for the polygons. The coordinates of each
            polygon *verts_i* are multiplied by the square-root of the
            corresponding entry in *sizes* (i.e., *sizes* specify the scaling
            of areas). The scaling is applied before the Artist master
            transform.
        closed : bool, default: True
            Whether the polygon should be closed by adding a CLOSEPOLY
            connection at the end.
        **kwargs
            Forwarded to `.Collection`.
        TN)r&  r0   r%  	set_vertsr   )rR   vertsr"  rn  rZ   r'  r[   r\   r0     s    
zPolyCollection.__init__c                    s  d| _ t|tjjr&|ttj}|s>dd |D | _	dS t|tj
rt|jdkrtj||ddddf fdd}tj|jd tjjd tjj dd< tjj d	< tjj d
<  fdd|D | _	dS g | _	|D ]4}t|r| j	tj| q| j	t| qdS )a  
        Set the vertices of the polygons.

        Parameters
        ----------
        verts : list of array-like
            The sequence of polygons [*verts0*, *verts1*, ...] where each
            element *verts_i* defines the vertices of polygon *i* as a 2D
            array-like of shape (M, 2).
        closed : bool, default: True
            Whether the polygon should be closed by adding a CLOSEPOLY
            connection at the end.
        Tc                 S   s   g | ]}t |qS r[   r   r   rr   xyr[   r[   r\   rv     rw   z,PolyCollection.set_verts.<locals>.<listcomp>Nr%   r   rH  )dtyper   c                    s   g | ]}t | qS r[   rq  rr  r   r[   r\   rv     rw   )r   ri   rJ   r   r   astyperL   r   r   rQ   ndarrayr}   rM   concatenater  r   r   	code_typeLINETOMOVETO	CLOSEPOLYr   _create_closed)rR   rp  rn  Z	verts_padrs  r[   rw  r\   ro    s&    "zPolyCollection.set_vertsc                 C   s8   t |t |krtddd t||D | _d| _dS )z$Initialize vertices with path codes.zB'codes' must be a 1D list or array with the same length of 'verts'c                 S   s.   g | ]&\}}t |r t||nt|qS r[   )r}   r   r   )rr   rs  Zcdsr[   r[   r\   rv     s   z6PolyCollection.set_verts_and_codes.<locals>.<listcomp>TN)r}   r   r   rQ   r   )rR   rp  r   r[   r[   r\   set_verts_and_codes  s    z"PolyCollection.set_verts_and_codes)NT)T)
r   r  r  r   r  r0   ro  rd   r  r(  r[   r[   r'  r\   rm    s
   
*rm  c                       s,   e Zd ZdZ fddZedd Z  ZS )BrokenBarHCollectionz]
    A collection of horizontal bars spanning *yrange* with a sequence of
    *xranges*.
    c                    s<   |\}|   fdd|D }t  j|fi | dS )a6  
        Parameters
        ----------
        xranges : list of (float, float)
            The sequence of (left-edge-position, width) pairs for each bar.
        yrange : (float, float)
            The (lower-edge, height) common to all bars.
        **kwargs
            Forwarded to `.Collection`.
        c                    s:   g | ]2\}}|f| f||  f|| f|fgqS r[   r[   )rr   xminZxwidthymaxyminr[   r\   rv     s   

z1BrokenBarHCollection.__init__.<locals>.<listcomp>N)r&  r0   )rR   xrangesyrangerZ   Zywidthrp  r'  r  r\   r0     s    zBrokenBarHCollection.__init__c           
      K   sf   g }t |D ]<\}}||| }	t|	s,q||	d |	d |	d  f q| |||| gfi |S )z
        Return a `.BrokenBarHCollection` that plots horizontal bars from
        over the regions in *x* where *where* is True.  The bars range
        on the y-axis from *ymin* to *ymax*

        *kwargs* are passed on to the collection.
        r   rv  )r   contiguous_regionsr}   r   )
clsr   r  r  whererZ   r  ind0ind1xslicer[   r[   r\   
span_where  s    	 zBrokenBarHCollection.span_where)r   r  r  r  r0   classmethodr  r(  r[   r[   r'  r\   r    s   r  c                       s`   e Zd ZdZejjZej	d Z
ejdddd fdd		Zd
d Zdd Zejdd Z  ZS )RegularPolyCollectionz)A collection of n-sided regular polygons.      r&   rotationr'   r   r   c                    sH   t  jf i | | | || _| |g| _|| _| t	  dS )a  
        Parameters
        ----------
        numsides : int
            The number of sides of the polygon.
        rotation : float
            The rotation of the polygon in radians.
        sizes : tuple of float
            The area of the circle circumscribing the polygon in points^2.
        **kwargs
            Forwarded to `.Collection`.

        Examples
        --------
        See :doc:`/gallery/event_handling/lasso_demo` for a complete example::

            offsets = np.random.rand(20, 2)
            facecolors = [cm.jet(x) for x in np.random.rand(20)]

            collection = RegularPolyCollection(
                numsides=5, # a pentagon
                rotation=0, sizes=(50,),
                facecolors=facecolors,
                edgecolors=("black",),
                linewidths=(1,),
                offsets=offsets,
                offset_transform=ax.transData,
                )
        N)
r&  r0   r%  	_numsides_path_generatorrQ   	_rotationset_transformr   rh   )rR   numsidesr  r"  rZ   r'  r[   r\   r0     s    #
zRegularPolyCollection.__init__c                 C   s   | j S r]   )r  r_   r[   r[   r\   get_numsides,  s    z"RegularPolyCollection.get_numsidesc                 C   s   | j S r]   )r  r_   r[   r[   r\   get_rotation/  s    z"RegularPolyCollection.get_rotationc                    s8      j jj  fdd jD  _t | d S )Nc                    s$   g | ]}t | j  qS r[   )r   r   rotater  
get_matrixr   r_   r[   r\   rv   5  s   z.RegularPolyCollection.draw.<locals>.<listcomp>)r%  r  r   r#  re   r#   r   r   r[   r_   r\   r   2  s
    
zRegularPolyCollection.draw)r   r  )r   r  r  r  r   r   unit_regular_polygonr  rJ   pir!  r   r  r0   r  r  r   r  r   r(  r[   r[   r'  r\   r    s   
  )r  c                   @   s   e Zd ZdZejjZdS )StarPolygonCollectionz:Draw a collection of regular stars with *numsides* points.N)r   r  r  r  r   r   unit_regular_starr  r[   r[   r[   r\   r  >  s   r  c                   @   s   e Zd ZdZejjZdS )AsteriskPolygonCollectionz>Draw a collection of regular asterisks with *numsides* points.N)r   r  r  r  r   r   unit_regular_asteriskr  r[   r[   r[   r\   r  C  s   r  c                       sz   e Zd ZdZdZdd fdd
Zdd ZeZeZd	d
 Z	dd Z
dd Zdd Zdd Zdd ZeZdd ZeZ  ZS )LineCollectiona  
    Represents a sequence of `.Line2D`\s that should be drawn together.

    This class extends `.Collection` to represent a sequence of
    `.Line2D`\s instead of just a sequence of `.Patch`\s.
    Just as in `.Collection`, each property of a *LineCollection* may be either
    a single value or a list of values. This list is then used cyclically for
    each element of the LineCollection, so the property of the ``i``\th element
    of the collection is::

      prop[i % len(prop)]

    The properties of each member of a *LineCollection* default to their values
    in :rc:`lines.*` instead of :rc:`patch.*`, and the property *colors* is
    added in place of *edgecolors*.
    Tr.   r+   c                   s0   | dd t jf d|i| | | dS )a  
        Parameters
        ----------
        segments : list of array-like
            A sequence of (*line0*, *line1*, *line2*), where::

                linen = (x0, y0), (x1, y1), ... (xm, ym)

            or the equivalent numpy array with two columns. Each line
            can have a different number of segments.
        linewidths : float or list of float, default: :rc:`lines.linewidth`
            The width of each line in points.
        colors : color or list of color, default: :rc:`lines.color`
            A sequence of RGBA tuples (e.g., arbitrary color strings, etc, not
            allowed).
        antialiaseds : bool or list of bool, default: :rc:`lines.antialiased`
            Whether to use antialiasing for each line.
        zorder : int, default: 2
            zorder of the lines once drawn.

        facecolors : color or list of color, default: 'none'
            When setting *facecolors*, each line is interpreted as a boundary
            for an area, implicitly closing the path from the last point to the
            first point. The enclosed area is filled with *facecolor*.
            In order to manually specify what should count as the "interior" of
            each line, please use `.PathCollection` instead, where the
            "interior" can be specified by appropriate usage of
            `~.path.Path.CLOSEPOLY`.

        **kwargs
            Forwarded to `.Collection`.
        r   r   r,   N)
setdefaultr&  r0   set_segments)rR   segmentsr,   rZ   r'  r[   r\   r0   \  s    &
zLineCollection.__init__c                 C   s&   |d u rd S dd |D | _ d| _d S )Nc                 S   s6   g | ].}t |tjjr t|ntt|tqS r[   )ri   rJ   r   r   r   r   r   rL   )rr   segr[   r[   r\   rv     s   z/LineCollection.set_segments.<locals>.<listcomp>Tr*  )rR   r  r[   r[   r\   r    s    zLineCollection.set_segmentsc                 C   s>   g }| j D ].}dd |jddD }t|}|| q
|S )z
        Returns
        -------
        list
            List of segments in the LineCollection. Each list item contains an
            array of vertices.
        c                 S   s   g | ]\}}|qS r[   r[   )rr   Zvertex_r[   r[   r\   rv     s   z/LineCollection.get_segments.<locals>.<listcomp>F)simplify)rQ   iter_segmentsrJ   r   r   )rR   r  r   r   r[   r[   r\   get_segments  s    


zLineCollection.get_segmentsc                 C   s
   t jd S )Nzlines.linewidthr   r_   r[   r[   r\   r     s    z%LineCollection._get_default_linewidthc                 C   s
   t jd S )Nzlines.antialiasedr   r_   r[   r[   r\   r     s    z'LineCollection._get_default_antialiasedc                 C   s
   t jd S )Nzlines.colorr   r_   r[   r[   r\   r     s    z%LineCollection._get_default_edgecolorc                 C   s   dS )Nr   r[   r_   r[   r[   r\   r     s    z%LineCollection._get_default_facecolorc                 C   s   |  | dS )a3  
        Set the edgecolor(s) of the LineCollection.

        Parameters
        ----------
        c : color or list of colors
            Single color (all lines have same color), or a
            sequence of rgba tuples; if it is a sequence the lines will
            cycle through the sequence.
        N)r?   r   r[   r[   r\   r     s    zLineCollection.set_colorc                 C   s   | j S r]   )r   r_   r[   r[   r\   	get_color  s    zLineCollection.get_color)r   r  r  r  r   r0   r  ro  rd   r  r   r   r   r   r   Z
set_colorsr  
get_colorsr(  r[   r[   r'  r\   r  H  s    ,	r  c                       s   e Zd ZdZdZejdddd) fdd	Zdd Zdd Z	dd Z
e
 Z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 fd#d$Z fd%d&Zd'd( Z  ZS )*EventCollectionz
    A collection of locations along a single axis at which an "event" occurred.

    The events are given by a 1-dimensional array. They do not have an
    amplitude and are displayed as parallel lines.
    Tr&   
lineoffsetr'   
horizontalr   r   Nr)   c	           
         sH   t  jg f||||d|	 d| _|| _|| _| | | | dS )aD  
        Parameters
        ----------
        positions : 1D array-like
            Each value is an event.
        orientation : {'horizontal', 'vertical'}, default: 'horizontal'
            The sequence of events is plotted along this direction.
            The marker lines of the single events are along the orthogonal
            direction.
        lineoffset : float, default: 0
            The offset of the center of the markers from the origin, in the
            direction orthogonal to *orientation*.
        linelength : float, default: 1
            The total height of the marker (i.e. the marker stretches from
            ``lineoffset - linelength/2`` to ``lineoffset + linelength/2``).
        linewidth : float or list thereof, default: :rc:`lines.linewidth`
            The line width of the event lines, in points.
        color : color or list of colors, default: :rc:`lines.color`
            The color of the event lines.
        linestyle : str or tuple or list thereof, default: 'solid'
            Valid strings are ['solid', 'dashed', 'dashdot', 'dotted',
            '-', '--', '-.', ':']. Dash tuples should be of the form::

                (offset, onoffseq),

            where *onoffseq* is an even length tuple of on and off ink
            in points.
        antialiased : bool or list thereof, default: :rc:`lines.antialiased`
            Whether to use antialiasing for drawing the lines.
        **kwargs
            Forwarded to `.LineCollection`.

        Examples
        --------
        .. plot:: gallery/lines_bars_and_markers/eventcollection_demo.py
        )r   r   r	   r   TN)r&  r0   _is_horizontal_linelength_lineoffsetset_orientationset_positions)
rR   	positionsorientationr  
linelengthr!   r/  r    r   rZ   r'  r[   r\   r0     s    0

zEventCollection.__init__c                    s&   |   rdnd  fdd|  D S )zX
        Return an array containing the floating-point values of the positions.
        r   r   c                    s   g | ]}|d  f qS )r   r[   )rr   segmentposr[   r\   rv     rw   z1EventCollection.get_positions.<locals>.<listcomp>)is_horizontalr  r_   r[   r  r\   get_positions  s    zEventCollection.get_positionsc                 C   s   |du rg }t |dkr"td|  }|  }|  r>dnd}t t|ddf}t |dddf |dddd|f< ||d  |dddd| f< ||d  |dddd| f< | 	| dS )z Set the positions of the events.Nr   z!positions must be one-dimensionalr   r.   )
rJ   r	  r   get_lineoffsetget_linelengthr  r  r}   sortr  )rR   r  r  r  Zpos_idxr  r[   r[   r\   r    s    (zEventCollection.set_positionsc                 C   sL   |du st |dr"t|dkr"dS |  }t|t|g}| | dS )z2Add one or more events at the specified positions.Nr}   r   )rk   r}   r  rJ   hstackrK   r  )rR   positionr  r[   r[   r\   add_positions'  s    
zEventCollection.add_positionsc                 C   s   | j S )z=True if the eventcollection is horizontal, False if vertical.)r  r_   r[   r[   r\   r  1  s    zEventCollection.is_horizontalc                 C   s   |   rdS dS )zX
        Return the orientation of the event line ('horizontal' or 'vertical').
        r  vertical)r  r_   r[   r[   r\   get_orientation5  s    zEventCollection.get_orientationc                 C   sH   |   }t|D ]\}}t|||< q| | |   | _d| _dS )zv
        Switch the orientation of the event line, either from vertical to
        horizontal or vice versus.
        TN)r  	enumeraterJ   fliplrr  r  r  r   )rR   r  ir  r[   r[   r\   switch_orientation;  s    
z"EventCollection.switch_orientationc                 C   s0   t jddd|d}||  kr$dS |   dS )z
        Set the orientation of the event line.

        Parameters
        ----------
        orientation : {'horizontal', 'vertical'}
        TF)r  r  )r  N)r   check_getitemr  r  )rR   r  r  r[   r[   r\   r  G  s    zEventCollection.set_orientationc                 C   s   | j S )z7Return the length of the lines used to mark each event.)r  r_   r[   r[   r\   r  V  s    zEventCollection.get_linelengthc                 C   sv   ||   krdS |  }|  }|  r,dnd}|D ],}||d  |d|f< ||d  |d|f< q4| | || _dS )z4Set the length of the lines used to mark each event.Nr   r          @)r  r  r  r  r  r  )rR   r  r  r  r  r  r[   r[   r\   set_linelengthZ  s    
zEventCollection.set_linelengthc                 C   s   | j S )z7Return the offset of the lines used to mark each event.)r  r_   r[   r[   r\   r  g  s    zEventCollection.get_lineoffsetc                 C   sv   ||   krdS |  }|  }|  r,dnd}|D ],}||d  |d|f< ||d  |d|f< q4| | || _dS )z4Set the offset of the lines used to mark each event.Nr   r   r  )r  r  r  r  r  r  )rR   r  r  r  r  r  r[   r[   r\   set_lineoffsetk  s    
zEventCollection.set_lineoffsetc                    s   t   d S )z3Get the width of the lines used to mark each event.r   r&  r  r_   r'  r[   r\   r  x  s    zEventCollection.get_linewidthc                    s
   t   S r]   r  r_   r'  r[   r\   rU  |  s    zEventCollection.get_linewidthsc                 C   s   |   d S )z6Return the color of the lines used to mark each event.r   )r  r_   r[   r[   r\   r    s    zEventCollection.get_color)r  r   r   NNr)   N)r   r  r  r  r   r   r  r0   r  r  r  Zextend_positionsZappend_positionsr  r  r  r  r  r  r  r  r  rU  r  r(  r[   r[   r'  r\   r    s4          9r  c                       s*   e Zd ZdZejd Z fddZ  ZS )CircleCollectionz-A collection of circles, drawn using splines.r  c                    s<   t  jf i | | | | t  tj g| _	dS )z
        Parameters
        ----------
        sizes : float or array-like
            The area of each circle in points^2.
        **kwargs
            Forwarded to `.Collection`.
        N)
r&  r0   r%  r  r   rh   r   r   unit_circlerQ   )rR   r"  rZ   r'  r[   r\   r0     s    	
zCircleCollection.__init__)	r   r  r  r  rJ   r  r!  r0   r(  r[   r[   r'  r\   r    s   
r  c                       sJ   e Zd ZdZejdddd fdd	Zdd	 Zej	 fd
dZ
  ZS )EllipseCollectionz.A collection of ellipses, drawn using splines.r&   unitsr'   pointsc                    s|   t  jf i | dt|  | _dt|  | _t| | _|| _	| 
t  td| _tj g| _dS )a  
        Parameters
        ----------
        widths : array-like
            The lengths of the first axes (e.g., major axis lengths).
        heights : array-like
            The lengths of second axes.
        angles : array-like
            The angles of the first axes, degrees CCW from the x-axis.
        units : {'points', 'inches', 'dots', 'width', 'height', 'x', 'y', 'xy'}
            The units in which majors and minors are given; 'width' and
            'height' refer to the dimensions of the axes, while 'x' and 'y'
            refer to the *offsets* data units. 'xy' differs from all others in
            that the angle as plotted varies with the aspect ratio, and equals
            the specified angle only when the aspect ratio is unity.  Hence
            it behaves the same as the `~.patches.Ellipse` with
            ``axes.transData`` as its transform.
        **kwargs
            Forwarded to `Collection`.
        g      ?r$   N)r&  r0   rJ   r   ravel_widths_heightsdeg2rad_angles_unitsr  r   rh   r  re   r   r   r  rQ   )rR   widthsheightsanglesr  rZ   r'  r[   r\   r0     s    zEllipseCollection.__init__c           
      C   s  | j }| j}| jdkrd}n| jdkr8|jj|jj }n| jdkrT|jj|jj }np| jdkrf|j}n^| jdkr||jd }nH| jdkr|jj}n4| jd	kr|jj}n | jd
krd}ntd| jt	
t| jddf| _| j| }| j| }t	| j}t	| j}|| | jddddf< ||  | jddddf< || | jddddf< || | jddddf< d| jddddf< tj}| jdkr|j   }	d|	ddddf< | ||	 dS )z0Calculate transforms immediately before drawing.rs  r   r   r   inchesr  r  r   r   dotsr  zUnrecognized units: r%   Nr   r.   )rl   r   r  r   r   viewLimr   r#  r   rJ   r   r}   r  re   r  sinr  cosr   r   r   r   r  copyr  )
rR   axfigscr  r  Z	sin_angleZ	cos_angle_affinemr[   r[   r\   _set_transforms  sD    











z!EllipseCollection._set_transformsc                    s   |    t | d S r]   )r  r&  r   r   r'  r[   r\   r     s    zEllipseCollection.draw)r  )r   r  r  r  r   r  r0   r  r   r  r   r(  r[   r[   r'  r\   r    s   *r  c                       s8   e Zd ZdZejdddd
 fdd	Zdd	 Z  ZS )PatchCollectionz
    A generic collection of patches.

    PatchCollection draws faster than a large number of equivalent individual
    Patches. It also makes it easier to assign a colormap to a heterogeneous
    collection of patches.
    r&   match_originalr'   Fc                    s   |rjdd   fdd|D |d< dd |D |d< dd |D |d	< d
d |D |d< dd |D |d< t  jf i | | | dS )a?  
        Parameters
        ----------
        patches : list of `.Patch`
            A sequence of Patch objects.  This list may include
            a heterogeneous assortment of different patch types.

        match_original : bool, default: False
            If True, use the colors and linewidths of the original
            patches.  If False, new colors may be assigned by
            providing the standard collection arguments, facecolor,
            edgecolor, linewidths, norm or cmap.

        **kwargs
            All other parameters are forwarded to `.Collection`.

            If any of *edgecolors*, *facecolors*, *linewidths*, *antialiaseds*
            are None, they default to their `.rcParams` patch setting, in
            sequence form.

        Notes
        -----
        The use of `~matplotlib.cm.ScalarMappable` functionality is optional.
        If the `~matplotlib.cm.ScalarMappable` matrix ``_A`` has been set (via
        a call to `~.ScalarMappable.set_array`), at draw time a call to scalar
        mappable will be made to set the face colors.
        c                 S   s   |   r|  S g dS )N)r   r   r   r   )r  r   )patchr[   r[   r\   determine_facecolor  s    z5PatchCollection.__init__.<locals>.determine_facecolorc                    s   g | ]} |qS r[   r[   rq   r  r[   r\   rv     rw   z,PatchCollection.__init__.<locals>.<listcomp>r   c                 S   s   g | ]}|  qS r[   )r   rq   r[   r[   r\   rv     rw   r   c                 S   s   g | ]}|  qS r[   )r  rq   r[   r[   r\   rv     rw   r   c                 S   s   g | ]}|  qS r[   )r  rq   r[   r[   r\   rv     rw   r   c                 S   s   g | ]}|  qS r[   )Zget_antialiasedrq   r[   r[   r\   rv     rw   r   N)r&  r0   rd   )rR   patchesr  rZ   r'  r  r\   r0     s    zPatchCollection.__init__c                 C   s   dd |D }|| _ d S )Nc                 S   s   g | ]}|  | qS r[   )rx   transform_pathget_pathrq   r[   r[   r\   rv   "  s   z-PatchCollection.set_paths.<locals>.<listcomp>r^   )rR   r  rc   r[   r[   r\   rd   !  s    zPatchCollection.set_paths)F)	r   r  r  r  r   r  r0   rd   r(  r[   r[   r'  r\   r    s   -r  c                       sJ   e Zd ZdZ fddZdd Zdd Zedd	 Ze	j
d
d Z  ZS )TriMeshz
    Class for the efficient drawing of a triangular mesh using Gouraud shading.

    A triangular mesh is a `~matplotlib.tri.Triangulation` object.
    c                    s\   t  jf i | || _d| _tj | _t	|j
dd|jddf}| j| d S )Ngouraudrv  r   )r&  r0   _triangulation_shadingr   rz   unit_bboxrJ   r  r   r  r   r   )rR   ZtriangulationrZ   rs  r'  r[   r\   r0   -  s    zTriMesh.__init__c                 C   s   | j d u r|   | j S r]   rQ   rd   r_   r[   r[   r\   r`   :  s    
zTriMesh.get_pathsc                 C   s   |  | j| _d S r]   )convert_mesh_to_pathsr  rQ   r_   r[   r[   r\   rd   ?  s    zTriMesh.set_pathsc                 C   s4   |   }tj| j| | j| fdd}dd |D S )z
        Convert a given mesh into a sequence of `.Path` objects.

        This function is primarily of use to implementers of backends that do
        not directly support meshes.
        rv  rt  c                 S   s   g | ]}t |qS r[   rq  r   r[   r[   r\   rv   L  rw   z1TriMesh.convert_mesh_to_paths.<locals>.<listcomp>)get_masked_trianglesrJ   stackr   r   )tri	trianglesrp  r[   r[   r\   r  B  s    zTriMesh.convert_mesh_to_pathsc                 C   s   |   sd S |j| jj|  d |  }| j}| }tj	|j
| |j| fdd}|   | j| }| }| | ||  d  |||||  |  || jj d S )N)gidrv  rt  r   )r   r   r   r   r   rx   r  r  rJ   r  r   r   r   r   r   r   r@   r  draw_gouraud_trianglesr   r   r   )rR   r   ru   r  r  rp  r	   r   r[   r[   r\   r   N  s    

zTriMesh.draw)r   r  r  r  r0   r`   rd   r  r  r   r  r   r(  r[   r[   r'  r\   r  '  s   
r  c                       s   e Zd ZdZ fddZedddddd	e_d
d Zdd Z	 fddZ
dd Zdd Zeejddddd Zedd Zeddd Zdd Zejdd  Zd!d" Z  ZS )#r
  a?
  
    Class for the efficient drawing of a quadrilateral mesh.

    A quadrilateral mesh is a grid of M by N adjacent quadrilaterals that are
    defined via a (M+1, N+1) grid of vertices. The quadrilateral (m, n) is
    defined by the vertices ::

               (m+1, n) ----------- (m+1, n+1)
                  /                   /
                 /                 /
                /               /
            (m, n) -------- (m, n+1)

    The mesh need not be regular and the polygons need not be convex.

    Parameters
    ----------
    coordinates : (M+1, N+1, 2) array-like
        The vertices. ``coordinates[m, n]`` specifies the (x, y) coordinates
        of vertex (m, n).

    antialiased : bool, default: True

    shading : {'flat', 'gouraud'}, default: 'flat'

    Notes
    -----
    Unlike other `.Collection`\s, the default *pickradius* of `.QuadMesh` is 0,
    i.e. `~.Artist.contains` checks whether the test point is within any of the
    mesh quadrilaterals.

    There exists a deprecated API version ``QuadMesh(M, N, coords)``, where
    the dimensions are given explicitly and ``coords`` is a (M*N, 2)
    array-like. This has been deprecated in Matplotlib 3.5. The following
    describes the semantics of this deprecated API.

    A quadrilateral mesh consists of a grid of vertices.
    The dimensions of this array are (*meshWidth* + 1, *meshHeight* + 1).
    Each vertex in the mesh has a different set of "mesh coordinates"
    representing its position in the topology of the mesh.
    For any values (*m*, *n*) such that 0 <= *m* <= *meshWidth*
    and 0 <= *n* <= *meshHeight*, the vertices at mesh coordinates
    (*m*, *n*), (*m*, *n* + 1), (*m* + 1, *n* + 1), and (*m* + 1, *n*)
    form one of the quadrilaterals in the mesh. There are thus
    (*meshWidth* * *meshHeight*) quadrilaterals in the mesh.  The mesh
    need not be regular and the polygons need not be convex.

    A quadrilateral mesh is represented by a (2 x ((*meshWidth* + 1) *
    (*meshHeight* + 1))) numpy array *coordinates*, where each row is
    the *x* and *y* coordinates of one of the vertices.  To define the
    function that maps from a data point to its corresponding color,
    use the :meth:`set_cmap` method.  Each of these arrays is indexed in
    row-major order by the mesh coordinates of the vertex (or the mesh
    coordinates of the lower left vertex, in the case of the colors).

    For example, the first entry in *coordinates* is the coordinates of the
    vertex at mesh coordinates (0, 0), then the one at (0, 1), then at (0, 2)
    .. (0, meshWidth), (1, 0), (1, 1), and so on.
    c           
         s   t jddddddgg|R i | }|^ }}}}}|rxt jddd |\}}	t|tj|	d	 |d	 d
f}|dd t j	d|d || _
|| _|| _tj | _| j| j
dd
 t jf i | | d d S )NTflatc                 [   s   t  S r]   locals)	meshWidth
meshHeightcoordinatesr   shadingrZ   r[   r[   r\   r,    s    z#QuadMesh.__init__.<locals>.<lambda>c                 [   s   t  S r]   r   )r  r   r  rZ   r[   r[   r\   r,    s    3.5zThis usage of Quadmesh is deprecated: Parameters meshWidth and meshHeights will be removed; coordinates must be 2D; all parameters except coordinates will be keyword-only.messager   r.   rX   r   )NNr.   )r  rv  F)Tr  )Tr  )r   select_matching_signaturer`  warn_deprecatedrJ   r   float64r  r  check_shape_coordinates_antialiasedr  r   rz   r  r  r   r&  r0   Zset_mouseover)
rR   argsrZ   paramsZold_w_hcoordsr   r  wrj  r'  r[   r\   r0     s8      
"zQuadMesh.__init__Tr  r   )r   r  rX   c                K   s   d S r]   r[   )rR   r  r   r  rX   rZ   r[   r[   r\   r,    s    zQuadMesh.<lambda>c                 C   s   | j d u r|   | j S r]   r  r_   r[   r[   r\   r`     s    
zQuadMesh.get_pathsc                 C   s   |  | j| _d| _d S r   )_convert_mesh_to_pathsr  rQ   r   r_   r[   r[   r\   rd     s    zQuadMesh.set_pathsc           	         s  | j jdd \}}d}d}| jdkr:|d |d  }}n
|| }}|durt|}t|dkrz|d || krd}n(|||fkrt||| krd}nd}|rtjdd	| d
| d| j d| d| d|j dd |rtd|j d| d| dt	 
|S )a  
        Set the data values.

        Parameters
        ----------
        A : (M, N) array-like or M*N array-like
            If the values are provided as a 2D grid, the shape must match the
            coordinates grid. If the values are 1D, they are reshaped to 2D.
            M, N follow from the coordinates grid, where the coordinates grid
            shape is (M, N) for 'gouraud' *shading* and (M+1, N+1) for 'flat'
            shading.
        r   rv  Fr  r   NTr  zFor X (z	) and Y (z) with z& shading, the expected shape of A is (z, z). Passing A (zE) is deprecated since %(since)s and will become an error %(removal)s.r  zDimensions of A z are incompatible with X (z) and/or Y ())r  rM   r  rJ   r}   prodr   r
  	TypeErrorr&  	set_array)	rR   Ar   r   Zmisshapen_dataZfaulty_datarj  r  rM   r'  r[   r\   r    sH    




zQuadMesh.set_arrayc                 C   s   |   | | jS r]   )rx   transform_bboxr  )rR   r   r[   r[   r\   r     s    zQuadMesh.get_datalimc                 C   s   | j S )a  
        Return the vertices of the mesh as an (M+1, N+1, 2) array.

        M, N are the number of quadrilaterals in the rows / columns of the
        mesh, corresponding to (M+1, N+1) vertices.
        The last dimension specifies the components (x, y).
        )r  r_   r[   r[   r\   get_coordinates  s    zQuadMesh.get_coordinatesr  z8`QuadMesh(coordinates).get_paths()<.QuadMesh.get_paths>`)alternativec                 C   s
   t |S r]   )r
  r  )r  r  r  r[   r[   r\   r    s    zQuadMesh.convert_mesh_to_pathsc              	   C   s   t | tjjr| j}n| }tj|ddddf |ddddf |ddddf |ddddf |ddddf gddd}dd |D S )	z
        Convert a given mesh into a sequence of `.Path` objects.

        This function is primarily of use to implementers of backends that do
        not directly support quadmeshes.
        Nrv  r   r.   rt  )rv  r2  r.   c                 S   s   g | ]}t |qS r[   rq  r   r[   r[   r\   rv   *  rw   z3QuadMesh._convert_mesh_to_paths.<locals>.<listcomp>)ri   rJ   r   r   datarz  r  )r  r   r  r[   r[   r\   r    s    zQuadMesh._convert_mesh_to_pathsc                 C   s
   |  |S r]   )_convert_mesh_to_triangles)rR   r  r  r  r[   r[   r\   convert_mesh_to_triangles,  s    z"QuadMesh.convert_mesh_to_trianglesc                 C   sd  t |tjjr|j}n|}|ddddf }|ddddf }|ddddf }|ddddf }|| | | d }tj||||||||||||gddd}|  g |jdd dR }	|	ddddf }
|	ddddf }|	ddddf }|	ddddf }|
| | | d }tj|
||||||||||
|gddd	}||fS )
z
        Convert a given mesh into a sequence of triangles, each point
        with its own color.  The result can be used to construct a call to
        `~.RendererBase.draw_gouraud_triangle`.
        Nrv  r   g      @r.   rt  )rv  r%   r.      )rv  r%   r  )	ri   rJ   r   r   r  rz  r  r   rM   )rR   r  rs   Zp_aZp_bZp_cZp_dZp_centerr  r   Zc_aZc_bc_cc_dZc_centerr	   r[   r[   r\   r  0  sF    "z#QuadMesh._convert_mesh_to_trianglesc                 C   s  |   sd S || jj|   |  }|  }|  }|  rz| 	|d d df }| 
|d d df }t||g}|   |js| jd}||}|| jj}t }n| j}|js||}| }| }||   | | ||  d  | jdkr6| |\}	}
|||	|
|   nJ|!||  |jd d |jd d |||| " d| j#| $ d
 |%  |&| jj d| _'d S )Nr   r   )rv  r.   r  )rv  r  F)(r   r   r   r   r   rx   rm   r|   r   r   r   rJ   r   r   r~   r  r  ru   rM   r   rh   r   r   r   r   r   r   r@   r  r  r  r  r   Zdraw_quad_meshr   r  Zget_edgecolorsr   r   r   )rR   r   ru   r   rU   r   r   r  r   r  r	   r[   r[   r\   r   V  sN    



zQuadMesh.drawc                 C   s6   |  |\}}|r2|  d ur2|   |d  S d S )Nr   )r   r?  r  )rR   event	containedr   r[   r[   r\   get_cursor_data  s    zQuadMesh.get_cursor_data)r   r  r  r  r0   inspect	signature__signature__r`   rd   r  r   r  r  r   
deprecatedr  r  r  r  r   r  r   r$  r(  r[   r[   r'  r\   r
  f  s,   <%
/


&
0r
  )/r  r%  r   numbersr   rD  numpyrJ   
matplotlibr;   r;  r   r   r   r   r   r	   r9   r
   r   r   r   r   r   r   r   _enumsr   r   define_aliasesr/   r1   r#   r  r)  rm  r  r  r  r  r  r  r  r  r  r  r
  r[   r[   r[   r\   <module>   sR   4       / -R+B  8R=?