a
    Sicz                     @   s  d Z ddlZddlZddlmZmZmZm	Z	m
ZmZ ddlmZmZmZmZ ddlmZ ddlmZ ddlmZ d	d
 Zdd Zdd ZG dd dejZd?ddZG dd de	jZ d@ddZ!dAddZ"dBddZ#dCddZ$dDddZ%G d d! d!eZ&dEd"d#Z'G d$d% d%eZ(G d&d' d'e(Z)d(d) Z*dFd*d+Z+dGd,d-Z,G d.d/ d/eZ-G d0d1 d1eZ.dHd3d4Z/G d5d6 d6eZ0dId7d8Z1d9d: Z2d;d< Z3d=d> Z4dS )Jzx
Module containing 3D artist code and functions to convert 2D
artists into 3D versions which can be added to an Axes3D.
    N)artistcbookcolorslinestextpath)LineCollectionPolyCollectionPatchCollectionPathCollection)	Normalize)Patch   )proj3dc                 C   s    | d d } | dkr| d } | S )z?Return the given angle normalized to -180 < *a* <= 180 degrees.ih      ar   r   V/var/www/html/django/DPS/env/lib/python3.9/site-packages/mpl_toolkits/mplot3d/art3d.py_norm_angle   s    r   c                 C   s    | d d } | dkr| d } | S )z=Return the given angle normalized to -90 < *a* <= 90 degrees.r   Z   r   r   r   r   r   _norm_text_angle   s    r   c                 C   st   | dkrt dS | dkr$t dS | dkr6t dS | du rHt dS t | rht| d	krht | S td
dS )a  
    Return a direction vector.

    Parameters
    ----------
    zdir : {'x', 'y', 'z', None, 3-tuple}
        The direction. Possible values are:

        - 'x': equivalent to (1, 0, 0)
        - 'y': equivalent to (0, 1, 0)
        - 'z': equivalent to (0, 0, 1)
        - *None*: equivalent to (0, 0, 0)
        - an iterable (x, y, z) is converted to a NumPy array, if not already

    Returns
    -------
    x, y, z : array-like
        The direction vector.
    x)r   r   r   y)r   r   r   z)r   r   r   N)r   r   r      z2'x', 'y', 'z', None or vector of length 3 expected)nparrayiterablelen
ValueErrorzdirr   r   r   get_dir_vector'   s    




r#   c                       s^   e Zd ZdZdddZdd Zd fd
d	Zdd ZdddZe	j
dd ZdddZ  ZS )Text3Da  
    Text object with 3D position and direction.

    Parameters
    ----------
    x, y, z
        The position of the text.
    text : str
        The text string to display.
    zdir : {'x', 'y', 'z', None, 3-tuple}
        The direction of the text. See `.get_dir_vector` for a description of
        the values.

    Other Parameters
    ----------------
    **kwargs
         All other parameters are passed on to `~matplotlib.text.Text`.
   r    r   c                 K   s*   t jj| |||fi | | || d S N)mtextText__init__set_3d_properties)selfr   r   r   r   r"   kwargsr   r   r   r)   ]   s    zText3D.__init__c                 C   s   | j | j| jfS )z*Return the (x, y, z) position of the text.)_x_y_zr+   r   r   r   get_position_3da   s    zText3D.get_position_3dNc                    s8   t  |dd  | |d  |dur4t|| _dS )a?  
        Set the (*x*, *y*, *z*) position of the text.

        Parameters
        ----------
        xyz : (float, float, float)
            The position in 3D space.
        zdir : {'x', 'y', 'z', None, 3-tuple}
            The direction of the text. If unspecified, the zdir will not be
            changed.
        N   )superset_positionset_zr#   _dir_vec)r+   xyzr"   	__class__r   r   set_position_3de   s    zText3D.set_position_3dc                 C   s   || _ d| _dS )zl
        Set the *z* position of the text.

        Parameters
        ----------
        z : float
        TN)r/   stale)r+   r   r   r   r   r5   v   s    zText3D.set_zc                 C   s   || _ t|| _d| _d S NT)r/   r#   r6   r;   )r+   r   r"   r   r   r   r*      s    
zText3D.set_3d_propertiesc                 C   s   t | j| j| jf}t||| j g| jj	}|d d |d d  }|d d |d d  }t
t
||}tj| |d d |d d t|d tj| | W d    n1 s0    Y  d| _d S )Nr   r   )r-   r.   	_rotationF)r   r   r-   r.   r/   r   proj_trans_pointsr6   axesMmathdegreesatan2r   _setattr_cmr   r'   r(   drawr;   )r+   rendererZ
position3dZprojdxdyangler   r   r   rE      s    ,zText3D.drawc                 C   s   d S r&   r   r+   rF   r   r   r   get_tightbbox   s    zText3D.get_tightbbox)r   r   r   r%   r   )N)r   r   )N)__name__
__module____qualname____doc__r)   r1   r:   r5   r*   r   allow_rasterizationrE   rK   __classcell__r   r   r8   r   r$   I   s   


r$   r   c                 C   s   t | _| || dS )z"Convert a Text to a Text3D object.N)r$   r9   r*   )objr   r"   r   r   r   text_2d_to_3d   s    rS   c                       sL   e Zd ZdZ fddZdddZdd	 Zd
d Zej	 fddZ
  ZS )Line3Dz
    3D line object.
    c                    s,   t  jg g g|R i | |||f| _dS )zU
        Keyword arguments are passed onto :func:`~matplotlib.lines.Line2D`.
        N)r3   r)   _verts3d)r+   xsyszsargsr,   r8   r   r   r)      s    zLine3D.__init__r   r   c                 C   sH   |   }|  }t| }t|t|}t||||| _	d| _
d S r<   )	get_xdata	get_ydatar   _to_unmasked_float_arrayravelr   broadcast_tor   juggle_axesrU   r;   )r+   rX   r"   rV   rW   r   r   r   r*      s    zLine3D.set_3d_propertiesc                 G   s(   t |dkr|d | _n|| _d| _dS )ag  
        Set the x, y and z data

        Parameters
        ----------
        x : array-like
            The x-data to be plotted.
        y : array-like
            The y-data to be plotted.
        z : array-like
            The z-data to be plotted.

        Notes
        -----
        Accepts x, y, z arguments or a single array-like (x, y, z)
        r   r   TN)r   rU   r;   )r+   rY   r   r   r   set_data_3d   s    zLine3D.set_data_3dc                 C   s   | j S )z
        Get the current data

        Returns
        -------
        verts3d : length-3 tuple or array-like
            The current data as a tuple or array-like.
        )rU   r0   r   r   r   get_data_3d   s    	zLine3D.get_data_3dc                    sH   | j \}}}t|||| jj\}}}| || t | d| _d S )NF)	rU   r   Zproj_transformr?   r@   set_datar3   rE   r;   )r+   rF   Zxs3dZys3dZzs3drV   rW   rX   r8   r   r   rE      s
    zLine3D.draw)r   r   )rL   rM   rN   rO   r)   r*   r`   ra   r   rP   rE   rQ   r   r   r8   r   rT      s   
rT   c                 C   s   t | _| || dS )zConvert a 2D line to 3D.N)rT   r9   r*   )linerX   r"   r   r   r   line_2d_to_3d   s    rd   c                    sH   t |t| }| jddd}dd t||D } fdd|D }|S )zConvert a path to a 3D segment.Fsimplifycurvesc                 S   s"   g | ]\\\}}}}|||fqS r   r   .0r   r   coder   r   r   r   
<listcomp>       z'_path_to_3d_segment.<locals>.<listcomp>c                    s    g | ]\}}}t ||| qS r   r_   ri   r   r   r   r!   r   r   rk      rl   )r   r^   r   iter_segmentszip)r   rX   r"   pathsegssegseg3dr   r!   r   _path_to_3d_segment   s
    rt   c                    sP   t |st |t| }nt|t| kr4td fddt| |D }|S )z6Convert paths from a collection object to 3D segments.z-Number of z-coordinates does not match paths.c                    s   g | ]\}}t || qS r   )rt   ri   r   Zpathzr!   r   r   rk      s   z)_paths_to_3d_segments.<locals>.<listcomp>)r   r   r^   r   r    rp   )pathsrX   r"   segsr   r!   r   _paths_to_3d_segments   s    

rx   c                    sj   t |t| }| jddd}dd t||D }|rVt| \}} fdd|D }ng }g }|t|fS )z/Convert a path to a 3D segment with path codes.Fre   c                 S   s&   g | ]\\\}}}}|||f|fqS r   r   rh   r   r   r   rk     rl   z2_path_to_3d_segment_with_codes.<locals>.<listcomp>c                    s    g | ]\}}}t ||| qS r   rm   rn   r!   r   r   rk     rl   )r   r^   r   ro   rp   list)r   rX   r"   rq   Z	seg_codesrr   codesrs   r   r!   r   _path_to_3d_segment_with_codes   s    r{   c                    sT   t |t| } fddt| |D }|r:t| \}}n
g g  }}t|t|fS )zP
    Convert paths from a collection object to 3D segments with path codes.
    c                    s   g | ]\}}t || qS r   )r{   ru   r!   r   r   rk     s   z4_paths_to_3d_segments_with_codes.<locals>.<listcomp>)r   r^   r   rp   ry   )rv   rX   r"   Zsegments_codessegmentsrz   r   r!   r    _paths_to_3d_segments_with_codes  s    

r}   c                       s0   e Zd ZdZdd Z fddZdd Z  ZS )Line3DCollectionz#
    A collection of 3D lines.
    c                 C   s   || _ d| _dS z&Set the position to use for z-sorting.TN
_sort_zposr;   r+   valr   r   r   set_sort_zpos   s    zLine3DCollection.set_sort_zposc                    s   || _ t g  dS )z"
        Set 3D segments.
        N)_segments3dr3   set_segments)r+   r|   r8   r   r   r   %  s    zLine3DCollection.set_segmentsc                    sT    fdd j D }dd |D }t | d}|D ]\}}}t|t|}q6|S )zB
        Project the points according to renderer matrix.
        c                    s   g | ]}t | jjqS r   )r   r>   r?   r@   )ri   pointsr0   r   r   rk   0  s   z5Line3DCollection.do_3d_projection.<locals>.<listcomp>c                 S   s    g | ]\}}}t ||gqS r   )r   column_stack)ri   rV   rW   rX   r   r   r   rk   2  rl   g    eA)r   r   r   min)r+   Zxyslistsegments_2dminzrV   rW   rX   r   r0   r   do_3d_projection,  s    
z!Line3DCollection.do_3d_projection)rL   rM   rN   rO   r   r   r   rQ   r   r   r8   r   r~     s   r~   c                 C   s$   t |  ||}t| _| | dS )z6Convert a LineCollection to a Line3DCollection object.N)rx   	get_pathsr~   r9   r   )colrX   r"   
segments3dr   r   r   line_collection_2d_to_3d<  s    r   c                       sB   e Zd ZdZddd fdd
Zddd	Zd
d Zdd Z  ZS )Patch3Dz
    3D patch object.
    r   r   rX   r"   c                   s"   t  j|i | | || d S r&   )r3   r)   r*   )r+   rX   r"   rY   r,   r8   r   r   r)   H  s    zPatch3D.__init__r   c                    s.   t |t|} fddt||D | _d S )Nc                    s"   g | ]\\}}}t ||| qS r   rm   rn   r!   r   r   rk   N  s   
z-Patch3D.set_3d_properties.<locals>.<listcomp>)r   r^   r   rp   
_segment3d)r+   vertsrX   r"   r   r!   r   r*   L  s    
zPatch3D.set_3d_propertiesc                 C   s   | j S r&   )_path2dr0   r   r   r   get_pathQ  s    zPatch3D.get_pathc           	      C   sN   | j }t| \}}}t|||| jj\}}}}tt	||g| _
t|S r&   )r   rp   r   proj_transform_clipr?   r@   mpathPathr   r   r   r   	r+   srV   rW   rX   vxsvysvzsvisr   r   r   r   T  s    
zPatch3D.do_3d_projection)r   r   )	rL   rM   rN   rO   r)   r*   r   r   rQ   r   r   r8   r   r   C  s
   
r   c                   @   s2   e Zd ZdZdddddZddd	Zd
d ZdS )PathPatch3Dz
    3D PathPatch object.
    r   r   r   c                K   s$   t j| fi | | ||| d S r&   )r   r)   r*   )r+   r   rX   r"   r,   r   r   r   r)   b  s    zPathPatch3D.__init__r   c                 C   s    t j| |j||d |j| _d S )Nr   )r   r*   verticesrz   _code3d)r+   r   rX   r"   r   r   r   r*   g  s    zPathPatch3D.set_3d_propertiesc           	      C   sR   | j }t| \}}}t|||| jj\}}}}tt	||g| j
| _t|S r&   )r   rp   r   r   r?   r@   r   r   r   r   r   r   r   r   r   r   r   r   k  s    
zPathPatch3D.do_3d_projectionN)r   r   )rL   rM   rN   rO   r)   r*   r   r   r   r   r   r   ]  s   
r   c                 C   s4   |   }|  }||}t|r*|d S tg S )z2Return a list of vertices for the path of a patch.r   )get_patch_transformr   to_polygonsr   r   r   )patchtransr   polygonsr   r   r   _get_patch_vertst  s    
r   c                 C   s    t | }t| _| ||| dS )z$Convert a Patch to a Patch3D object.N)r   r   r9   r*   )r   r   r"   r   r   r   r   patch_2d_to_3d|  s    r   c                 C   s2   |   }|  }||}t| _| ||| dS )z,Convert a PathPatch to a PathPatch3D object.N)r   r   transform_pathr   r9   r*   )Z	pathpatchr   r"   r   r   r   r   r   r   pathpatch_2d_to_3d  s
    
r   c                       sv   e Zd ZdZdddd fdd
Zdd	 Zd
d Zdd Zdd Z fddZ	dd Z
 fddZ fddZ  ZS )Patch3DCollectionz%
    A collection of 3D patches.
    r   r   TrX   r"   
depthshadec                   s(   || _ t j|i | | || dS )a  
        Create a collection of flat 3D patches with its normal vector
        pointed in *zdir* direction, and located at *zs* on the *zdir*
        axis. 'zs' can be a scalar or an array-like of the same length as
        the number of patches in the collection.

        Constructor arguments are the same as for
        :class:`~matplotlib.collections.PatchCollection`. In addition,
        keywords *zs=0* and *zdir='z'* are available.

        Also, the keyword argument *depthshade* is available to
        indicate whether or not to shade the patches in order to
        give the appearance of depth (default is *True*).
        This is typically desired in scatter plots.
        N)_depthshader3   r)   r*   r+   rX   r"   r   rY   r,   r8   r   r   r)     s    zPatch3DCollection.__init__c                 C   s   | j S r&   r   r0   r   r   r   get_depthshade  s    z Patch3DCollection.get_depthshadec                 C   s   || _ d| _dS z
        Set whether depth shading is performed on collection members.

        Parameters
        ----------
        depthshade : bool
            Whether to shade the patches in order to give the appearance of
            depth.
        TNr   r;   r+   r   r   r   r   set_depthshade  s    
z Patch3DCollection.set_depthshadec                 C   s   || _ d| _dS r   r   r   r   r   r   r     s    zPatch3DCollection.set_sort_zposc                 C   s`   |    |  }t|dkr(|j\}}ng }g }t||t||| _td| _	d | _
d| _d S Nr   T)update_scalarmappableget_offsetsr   Tr_   r   
atleast_1d
_offsets3dslice_z_markers_idx_vzsr;   r+   rX   r"   offsetsrV   rW   r   r   r   r*     s    
z#Patch3DCollection.set_3d_propertiesc                    s`   | j \}}}t|||| jj\}}}}|| _t t	||g |j
dkrVt|S tjS d S Nr   )r   r   r   r?   r@   r   r3   set_offsetsr   r   sizer   nan)r+   rV   rW   rX   r   r   r   r   r8   r   r   r     s    

z"Patch3DCollection.do_3d_projectionc                 C   sD   | j d ur| jrt|| j n|}t|dkr6|| j }t|| jS Nr   r   r   _zalphar   r   mcolorsto_rgba_array_alphar+   Zcolor_arrayr   r   r   "_maybe_depth_shade_and_sort_colors  s    
z4Patch3DCollection._maybe_depth_shade_and_sort_colorsc                    s   |  t  S r&   r   r3   get_facecolorr0   r8   r   r   r     s    zPatch3DCollection.get_facecolorc                    s&   t | jdr|  S | t  S Nfacer   
_str_equal_edgecolorsr   r   r3   get_edgecolorr0   r8   r   r   r     s    zPatch3DCollection.get_edgecolor)rL   rM   rN   rO   r)   r   r   r   r*   r   r   r   r   rQ   r   r   r8   r   r     s   
r   c                       s   e Zd ZdZdddd fdd
Z fdd	Zd
d Zdd Zd fdd	Z fddZ	dd Z
dd Zdd Zdd Z fddZ fddZ  ZS ) Path3DCollectionz#
    A collection of 3D paths.
    r   r   Tr   c                   s.   || _ d| _t j|i | | || dS )a  
        Create a collection of flat 3D paths with its normal vector
        pointed in *zdir* direction, and located at *zs* on the *zdir*
        axis. 'zs' can be a scalar or an array-like of the same length as
        the number of paths in the collection.

        Constructor arguments are the same as for
        :class:`~matplotlib.collections.PathCollection`. In addition,
        keywords *zs=0* and *zdir='z'* are available.

        Also, the keyword argument *depthshade* is available to
        indicate whether or not to shade the patches in order to
        give the appearance of depth (default is *True*).
        This is typically desired in scatter plots.
        FN)r   _in_drawr3   r)   r*   r   r8   r   r   r)     s    zPath3DCollection.__init__c                    s>   t j| dd t | W d    n1 s00    Y  d S )NT)r   )r   rD   r3   rE   rJ   r8   r   r   rE     s    zPath3DCollection.drawc                 C   s   || _ d| _dS r   r   r   r   r   r   r   
  s    zPath3DCollection.set_sort_zposc                 C   s   |    |  }t|dkr(|j\}}ng }g }t||t||| _| j| _	t
| j| _| j\}}}td| _d | _d| _d S r   )r   r   r   r   r_   r   r   r   _sizes_sizes3dr   _linewidths_linewidths3dr   r   r   r;   r   r   r   r   r*     s    
z"Path3DCollection.set_3d_properties      R@c                    s   t  || | js|| _d S r&   )r3   	set_sizesr   r   )r+   sizesdpir8   r   r   r   /  s    zPath3DCollection.set_sizesc                    s$   t  | | js t| j| _d S r&   )r3   set_linewidthr   r   r   r   r   )r+   lwr8   r   r   r   4  s    zPath3DCollection.set_linewidthc                 C   s   | j S r&   r   r0   r   r   r   r   9  s    zPath3DCollection.get_depthshadec                 C   s   || _ d| _dS r   r   r   r   r   r   r   <  s    
zPath3DCollection.set_depthshadec           	      C   s   | j \}}}t|||| jj\}}}}t|d d d  }| _|| _t	| j
dkrb| j
| | _t	| jdkr|| j| | _|| }|| }|| }t| t||f |jrt|S tjS )Nr   r   )r   r   r   r?   r@   r   argsortr   r   r   r   r   r   r   r   r   r   r   r   r   )	r+   rV   rW   rX   r   r   r   r   Zz_markers_idxr   r   r   r   I  s    
z!Path3DCollection.do_3d_projectionc                 C   sD   | j d ur| jrt|| j n|}t|dkr6|| j }t|| jS r   r   r   r   r   r   r   g  s    
z3Path3DCollection._maybe_depth_shade_and_sort_colorsc                    s   |  t  S r&   r   r0   r8   r   r   r   q  s    zPath3DCollection.get_facecolorc                    s&   t | jdr|  S | t  S r   r   r0   r8   r   r   r   t  s    zPath3DCollection.get_edgecolor)r   )rL   rM   rN   rO   r)   rE   r   r*   r   r   r   r   r   r   r   r   rQ   r   r   r8   r   r     s    
r   Tc                 C   s>   t | trt| _nt | tr"t| _|| _d| _| || dS )a  
    Convert a :class:`~matplotlib.collections.PatchCollection` into a
    :class:`Patch3DCollection` object
    (or a :class:`~matplotlib.collections.PathCollection` into a
    :class:`Path3DCollection` object).

    Parameters
    ----------
    za
        The location or locations to place the patches in the collection along
        the *zdir* axis. Default: 0.
    zdir
        The axis in which to place the patches. Default: "z".
    depthshade
        Whether to shade the patches to give a sense of depth. Default: *True*.

    FN)	
isinstancer   r   r9   r
   r   r   r   r*   )r   rX   r"   r   r   r   r   patch_collection_2d_to_3d}  s    

r   c                       s   e Zd ZdZdd fdd
ZejejejdZ	dd Z
d	d
 Zd  f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dd Zdd Z  ZS )!Poly3DCollectiona  
    A collection of 3D polygons.

    .. note::
        **Filling of 3D polygons**

        There is no simple definition of the enclosed surface of a 3D polygon
        unless the polygon is planar.

        In practice, Matplotlib fills the 2D projection of the polygon. This
        gives a correct filling appearance only for planar polygons. For all
        other polygons, you'll find orientations in which the edges of the
        polygon intersect in the projection. This will lead to an incorrect
        visualization of the 3D area.

        If you need filled areas, it is recommended to create them via
        `~mpl_toolkits.mplot3d.axes3d.Axes3D.plot_trisurf`, which creates a
        triangulation and thus generates consistent surfaces.
    average)zsortc                   sh   t  j|g|R i | t|tjr:|jdkrTtdntdd |D rTtd| | d| _	dS )aS  
        Parameters
        ----------
        verts : list of (N, 3) array-like
            Each element describes a polygon as a sequence of ``N_i`` points
            ``(x, y, z)``.
        zsort : {'average', 'min', 'max'}, default: 'average'
            The calculation method for the z-order.
            See `~.Poly3DCollection.set_zsort` for details.
        *args, **kwargs
            All other parameters are forwarded to `.PolyCollection`.

        Notes
        -----
        Note that this class does a bit of magic with the _facecolors
        and _edgecolors properties.
        r   z)verts must be a list of (N, 3) array-likec                 s   s    | ]}t t|d kV  qdS )r2   N)r   r   shape)ri   vertr   r   r   	<genexpr>  rl   z,Poly3DCollection.__init__.<locals>.<genexpr>N)
r3   r)   r   r   ndarrayndimr    any	set_zsort_codes3d)r+   r   r   rY   r,   r8   r   r   r)     s    


zPoly3DCollection.__init__)r   r   maxc                 C   s   | j | | _d| _d| _dS )a  
        Set the calculation method for the z-order.

        Parameters
        ----------
        zsort : {'average', 'min', 'max'}
            The function applied on the z-coordinates of the vertices in the
            viewer's coordinate system, to determine the z-order.
        NT)_zsort_functions
_zsortfuncr   r;   )r+   r   r   r   r   r     s    
zPoly3DCollection.set_zsortc                 C   s   t |rt|j\}}}ng g g   }}}tt |}t||||g| _dgtdd |D }g tt	|dd |dd | _
dS )zOptimize points for projection.r   c                 S   s   g | ]}t |qS r   )r   )ri   segmentr   r   r   rk     rl   z/Poly3DCollection.get_vector.<locals>.<listcomp>Nr   r   )r   r   	row_stackr   onesr   _veccumsummapr   
_segslices)r+   r   rV   rW   rX   r   indicesr   r   r   
get_vector  s    zPoly3DCollection.get_vectorTc                    s"   |  | t g d || _dS )zSet 3D vertices.FN)r   r3   	set_verts_closed)r+   r   closedr8   r   r   r     s    
zPoly3DCollection.set_vertsc                 C   s   | j |dd || _dS )z Set 3D vertices with path codes.F)r   N)r   r   )r+   r   rz   r   r   r   set_verts_and_codes  s    z$Poly3DCollection.set_verts_and_codesc                 C   sF   |    d | _| d t| | _t| | _t| | _	d| _
d S )Nr   T)r   r   r   r	   r   _facecolor3dr   _edgecolor3d	get_alphaZ_alpha3dr;   r0   r   r   r   r*     s    
z"Poly3DCollection.set_3d_propertiesc                 C   s   || _ d| _dS r   r   r   r   r   r   r     s    zPoly3DCollection.set_sort_zposc                    s   j dur.    jr  j _ jr. j _t	 j
 jj\fdd jD } j} j}t|t|kr|jt|dd}t|t|krt|dkr|}n|jt|dd}|r
t fddtt|||D dd	 d
d}t| \}} _ _}n g }td _td _g } jdurX fdd|D }t || nt | j t jt|kr j _ jdurtdgdg jgdgg}	t	|	 jj}
|
d d S jdkrtS tj S dS )z<
        Perform the 3D projection for this object.
        Nc                    s"   g | ]} | | | fqS r   r   )ri   sl)txstystzsr   r   rk     rl   z5Poly3DCollection.do_3d_projection.<locals>.<listcomp>r   )axisc                 3   s<   | ]4\}\\}}}}}  |t||g|||fV  qd S r&   )r   r   r   )ri   idxrV   rW   rX   fcecr0   r   r   r   *  s   z4Poly3DCollection.do_3d_projection.<locals>.<genexpr>c                 S   s   | d S r   r   )r   r   r   r   <lambda>-  rl   z3Poly3DCollection.do_3d_projection.<locals>.<lambda>T)keyreverser      c                    s   g | ]} j | qS r   )r   )ri   r	  r0   r   r   rk   8  rl   r   r2   )!_Ar   _face_is_mapped_facecolorsr  _edge_is_mappedr   r  r   Z_proj_transform_vecr   r?   r@   r   r   repeatsorted	enumeraterp   _facecolors2d_edgecolors2dr   emptyr   r	   r   r   r   r   r   r   r   r   )r+   ZxyzlistZcfaceZcedgeZz_segments_2d_r   idxsrz   ZzvecZztransr   )r+   r  r  r  r   r     sT    


z!Poly3DCollection.do_3d_projectionc                    s   t  | t| | _d S r&   )r3   set_facecolorr	   r   r  r+   r   r8   r   r   r  M  s    zPoly3DCollection.set_facecolorc                    s   t  | t| | _d S r&   )r3   set_edgecolorr	   r   r  r  r8   r   r   r  R  s    zPoly3DCollection.set_edgecolorc              
   C   sx   t j| | zt| j| j| _W n ttt	fy<   Y n0 zt| j
| j| _W n ttt	fyl   Y n0 d| _d S r<   )r   Artist	set_alphar   r   r  r   AttributeError	TypeError
IndexErrorr  r   r;   )r+   alphar   r   r   r!  W  s    

zPoly3DCollection.set_alphac                 C   s&   t | ds | j | j_|   | jS )Nr  )hasattrr?   get_projr@   r   r  r0   r   r   r   r   f  s    
zPoly3DCollection.get_facecolorc                 C   s&   t | ds | j | j_|   | jS )Nr  )r&  r?   r'  r@   r   r  r0   r   r   r   r   n  s    
zPoly3DCollection.get_edgecolor)T)rL   rM   rN   rO   r)   r   r   r   r   r   r   r   r   r   r*   r   r   r  r  r!  r   r   rQ   r   r   r8   r   r     s$   Er   c                 C   s2   t |  ||\}}t| _| || |   dS )z6Convert a PolyCollection to a Poly3DCollection object.N)r}   r   r   r9   r   r*   )r   rX   r"   Zsegments_3drz   r   r   r   poly_collection_2d_to_3dw  s    
r(  c                 C   sL   |dkr|| |fS |dkr$| ||fS |d dkr>t | |||S | ||fS dS )z
    Reorder coordinates so that 2D xs, ys can be plotted in the plane
    orthogonal to zdir. zdir is normally x, y or z. However, if zdir
    starts with a '-' it is interpreted as a compensation for rotate_axes.
    r   r   r   -N)rotate_axesrV   rW   rX   r"   r   r   r   r_     s    

r_   c                 C   sV   |dkr||| fS |dkr$|| |fS |dkr6|| |fS |dkrH||| fS | ||fS dS )z
    Reorder coordinates so that the axes are rotated with zdir along
    the original z axis. Prepending the axis with a '-' does the
    inverse transform, so zdir can be x, -x, y, -y, z or -z
    r   z-xr   z-yNr   r+  r   r   r   r*    s    



r*  c                 C   s   t | dkst |dkr"tdS tt|t|}d||d  }tt| t |df}t	|ddddf |dddf | gS )z7Modify the alphas of the color list according to depth.r   r  r   gffffff?r  Nr   )
r   r   zerosr   r   r   r^   r   r   r   )r   rX   normZsatsrgbar   r   r   r     s    
r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   T)r   r   )5rO   rA   numpyr   
matplotlibr   r   r   r   r   r   r'   r   r   matplotlib.collectionsr   r	   r
   r   matplotlib.colorsr   matplotlib.patchesr   r%   r   r   r   r#   r(   r$   rS   Line2DrT   rd   rt   rx   r{   r}   r~   r   r   r   r   r   r   r   r   r   r   r(  r_   r*  r   r   r   r   r   <module>   sF    "P
?





!



_ 
 `
	