3
#ßL]�i  ã               @   sP  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ejdƒdd„ ƒZdd„ Zejdƒdd„ ƒZdd„ ZG dd„ dejƒZ dTdd„Z!G dd„ de	j"ƒZ#dUdd„Z$dVdd„Z%ejdƒdWdd „ƒZ&dXd!d"„Z'ejdƒdYd#d$„ƒZ(dZd%d&„Z)ejdƒd[d'd(„ƒZ*d\d)d*„Z+ejdƒd]d+d,„ƒZ,G d-d.„ d.eƒZ-d^d/d0„Z.G d1d2„ d2eƒZ/G d3d4„ d4e/ƒZ0d5d6„ Z1ejdƒd7d8„ ƒZ2d_d9d:„Z3d`d;d<„Z4G d=d>„ d>eƒZ5G d?d@„ d@eƒZ6dadBdC„Z7G dDdE„ dEeƒZ8dbdFdG„Z9dHdI„ Z:dJdK„ Z;dLdM„ Z<ejdƒdNdO„ ƒZ=dPdQ„ Z>ejdƒdRdS„ ƒZ?dS )czx
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   úB/tmp/pip-install-edjban26/matplotlib/mpl_toolkits/mplot3d/art3d.pyÚ_norm_angle   s    r   z3.1c             C   s   t | ƒS )z?Return the given angle normalized to -180 < *a* <= 180 degrees.)r   )r   r   r   r   Ú
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   s   t | ƒS )z=Return the given angle normalized to -90 < *a* <= 90 degrees.)r   )r   r   r   r   Únorm_text_angle-   s    r   c             C   sn   | dkrt jd	ƒS | dkr$t jd
ƒS | dkr6t jdƒS | dkrHt jdƒS t j| ƒrbt| ƒdkrb| 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 returned unchanged.

    Returns
    -------
    x, y, z : array-like
        The direction vector. This is either a numpy.array or *zdir* itself if
        *zdir* is already a length-3 iterable.

    Úxr   r   ÚyÚzNé   z2'x', 'y', 'z', None or vector of length 3 expected)r   r   r   )r   r   r   )r   r   r   )r   r   r   )ÚnpÚarrayÚiterableÚlenÚ
ValueError)Úzdirr   r   r   Úget_dir_vector3   s    



r#   c               @   s:   e Zd ZdZddd„Zddd„Zejd	d
„ ƒZdd„ Z	d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|Ž | j||ƒ d S )N)ÚmtextÚTextÚ__init__Úset_3d_properties)Úselfr   r   r   r   r"   Úkwargsr   r   r   r(   j   s    zText3D.__init__c             C   s2   | j ƒ \}}tj|||fƒ| _t|ƒ| _d| _d S )NT)Úget_positionr   r   Ú_position3dr#   Ú_dir_vecÚstale)r*   r   r"   r   r   r   r   r   r)   n   s    
zText3D.set_3d_propertiesc             C   s¢   t j| j| j| j g|jƒ}|d d |d d  }|d d |d d  }tjtj||ƒƒ}| j|d d |d d fƒ | j	t
|ƒƒ tjj| |ƒ d| _d S )Nr   r   F)r   Úproj_trans_pointsr-   r.   ÚMÚmathÚdegreesÚatan2Zset_positionZset_rotationr   r&   r'   Údrawr/   )r*   ÚrendererÚprojZdxZdyZangler   r   r   r5   t   s    zText3D.drawc             C   s   d S )Nr   )r*   r6   r   r   r   Úget_tightbbox€   s    zText3D.get_tightbboxN)r   r   r   r%   r   )r   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r(   r)   r   Úallow_rasterizationr5   r8   r   r   r   r   r$   V   s
   

r$   r   c             C   s   t | _| j||ƒ dS )z"Convert a Text to a Text3D object.N)r$   Ú	__class__r)   )Úobjr   r"   r   r   r   Útext_2d_to_3d†   s    r@   c               @   s@   e Zd ZdZdd„ Zddd„Zdd	„ Zd
d„ Zej	dd„ ƒZ
dS )ÚLine3Dz
    3D line object.
    c             O   s(   t jj| g g f|ž|Ž |||f| _dS )zU
        Keyword arguments are passed onto :func:`~matplotlib.lines.Line2D`.
        N)r   ÚLine2Dr(   Ú_verts3d)r*   ÚxsÚysÚzsÚargsr+   r   r   r   r(   ‘   s    zLine3D.__init__r   r   c             C   sV   | j ƒ }| jƒ }ytj|t|ƒd�}W n tk
r:   Y nX t||||ƒ| _d| _d S )N)Z
fill_valueT)	Z	get_xdataZ	get_ydatar   Z	full_likeÚfloatÚ	TypeErrorÚjuggle_axesrC   r/   )r*   rF   r"   rD   rE   r   r   r   r)   ˜   s    zLine3D.set_3d_propertiesc             G   s(   t |ƒdkr|d | _n|| _d| _dS )ad  
        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    rC   r/   )r*   rG   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_likes
            The current data as a tuple or array_likes
        )rC   )r*   r   r   r   Úget_data_3d¼   s    	zLine3D.get_data_3dc             C   sH   | j \}}}tj||||jƒ\}}}| j||ƒ tjj| |ƒ d| _d S )NF)	rC   r   Zproj_transformr1   Úset_datar   rB   r5   r/   )r*   r6   Zxs3dZys3dZzs3drD   rE   rF   r   r   r   r5   Ç   s
    zLine3D.drawN)r   r   )r9   r:   r;   r<   r(   r)   rK   rL   r   r=   r5   r   r   r   r   rA   Œ   s   
rA   c             C   s   t | _| j||ƒ dS )zConvert a 2D line to 3D.N)rA   r>   r)   )ÚlinerF   r"   r   r   r   Úline_2d_to_3dÐ   s    rO   c                sH   t j|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>Ü   s    z'_path_to_3d_segment.<locals>.<listcomp>c                s    g | ]\}}}t |||ˆ ƒ‘qS r   )rJ   )rR   r   r   r   )r"   r   r   rT   Ý   s    )r   Úbroadcast_tor    Úiter_segmentsÚzip)r   rF   r"   ÚpathsegsÚsegÚseg3dr   )r"   r   Ú_path_to_3d_segment×   s
    r[   c             C   s   t | ||d�S )zConvert a path to a 3D segment.)rF   r"   )r[   )r   rF   r"   r   r   r   Úpath_to_3d_segmentá   s    r\   c                s,   t j|t| ƒƒ}‡ fdd„t| |ƒD ƒ}|S )z6Convert paths from a collection object to 3D segments.c                s   g | ]\}}t ||ˆ ƒ‘qS r   )r[   )rR   r   Úpathz)r"   r   r   rT   ë   s   z)_paths_to_3d_segments.<locals>.<listcomp>)r   rU   r    rW   )ÚpathsrF   r"   Zsegsr   )r"   r   Ú_paths_to_3d_segmentsç   s    
r_   c             C   s   t | ||d�S )z6Convert paths from a collection object to 3D segments.)rF   r"   )r_   )r^   rF   r"   r   r   r   Úpaths_to_3d_segmentsð   s    r`   c                sj   t j|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.F)rP   rQ   c             S   s&   g | ]\\\}}}}|||f|f‘qS r   r   )rR   r   r   rS   r   r   r   r   rT   û   s    z2_path_to_3d_segment_with_codes.<locals>.<listcomp>c                s    g | ]\}}}t |||ˆ ƒ‘qS r   )rJ   )rR   r   r   r   )r"   r   r   rT   þ   s    )r   rU   r    rV   rW   Úlist)r   rF   r"   rX   Z	seg_codesrY   ÚcodesrZ   r   )r"   r   Ú_path_to_3d_segment_with_codesö   s    rc   c             C   s   t | ||d�S )z/Convert a path to a 3D segment with path codes.)rF   r"   )rc   )r   rF   r"   r   r   r   Úpath_to_3d_segment_with_codes  s    rd   c                sT   t j|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   )rc   )rR   r   r]   )r"   r   r   rT     s   z4_paths_to_3d_segments_with_codes.<locals>.<listcomp>)r   rU   r    rW   ra   )r^   rF   r"   Zsegments_codesÚsegmentsrb   r   )r"   r   Ú _paths_to_3d_segments_with_codes  s    

rf   c             C   s   t | ||d�S )zP
    Convert paths from a collection object to 3D segments with path codes.
    )rF   r"   )rf   )r^   rF   r"   r   r   r   Úpaths_to_3d_segments_with_codes  s    rg   c               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zejdd	d
„ƒZ	d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             C   s   t j|ƒ| _tj| g ƒ dS )z"
        Set 3D segments.
        N)r   Z
asanyarrayÚ_segments3dr   Úset_segments)r*   re   r   r   r   rm   ,  s    zLine3DCollection.set_segmentsc                sX   ‡ fdd„| j D ƒ}dd„ |D ƒ}tj| |ƒ d}x |D ]\}}}t|t|ƒƒ}q8W |S )zB
        Project the points according to renderer matrix.
        c                s   g | ]}t j|ˆ jƒ‘qS r   )r   r0   r1   )rR   Úpoints)r6   r   r   rT   8  s    z5Line3DCollection.do_3d_projection.<locals>.<listcomp>c             S   s    g | ]\}}}t j||gƒ‘qS r   )r   Úcolumn_stack)rR   rD   rE   rF   r   r   r   rT   :  s    g    eÍÍA)rl   r   rm   Úmin)r*   r6   ZxyslistÚsegments_2dZminzrD   rE   rF   r   )r6   r   Údo_3d_projection3  s    

z!Line3DCollection.do_3d_projectionFc             C   s   |r| j |ƒ tj| |ƒ d S )N)rr   r   r5   )r*   r6   Úprojectr   r   r   r5   C  s    
zLine3DCollection.drawN)F)
r9   r:   r;   r<   rk   rm   rr   r   r=   r5   r   r   r   r   rh   "  s   rh   c             C   s$   t | jƒ ||ƒ}t| _| j|ƒ dS )z6Convert a LineCollection to a Line3DCollection object.N)r_   Ú	get_pathsrh   r>   rm   )ÚcolrF   r"   Ú
segments3dr   r   r   Úline_collection_2d_to_3dJ  s    rw   c               @   sB   e Zd ZdZf ddœdd„Zddd„Zd	d
„ Zdd„ Zdd„ ZdS )ÚPatch3Dz
    3D patch object.
    r   )rF   r"   c            O   s"   t j| f|ž|Ž | j||ƒ d S )N)r   r(   r)   )r*   rF   r"   rG   r+   r   r   r   r(   V  s    zPatch3D.__init__r   c                s:   t j|t|ƒƒ}‡ fdd„t||ƒD ƒ| _tj| ƒ| _d S )Nc                s"   g | ]\\}}}t |||ˆ ƒ‘qS r   )rJ   )rR   r   r   r   )r"   r   r   rT   \  s   z-Patch3D.set_3d_properties.<locals>.<listcomp>)r   rU   r    rW   Ú
_segment3dr   Úget_facecolorÚ_facecolor3d)r*   ÚvertsrF   r"   r   )r"   r   r)   Z  s    
zPatch3D.set_3d_propertiesc             C   s   | j S )N)Ú_path2d)r*   r   r   r   Úget_path`  s    zPatch3D.get_pathc             C   s   | j S )N)Ú_facecolor2d)r*   r   r   r   rz   c  s    zPatch3D.get_facecolorc       
      C   sT   | j }t|Ž \}}}tj||||jƒ\}}}}	tjtj||gƒƒ| _	| j
| _t|ƒS )N)ry   rW   r   Úproj_transform_clipr1   ÚmpathÚPathr   ro   r}   r{   r   rp   )
r*   r6   ÚsrD   rE   rF   ÚvxsÚvysÚvzsÚvisr   r   r   rr   f  s    zPatch3D.do_3d_projectionN)r   r   )	r9   r:   r;   r<   r(   r)   r~   rz   rr   r   r   r   r   rx   Q  s   
rx   c               @   s2   e Zd ZdZf ddœdd„Zddd„Zd	d
„ ZdS )ÚPathPatch3Dz
    3D PathPatch object.
    r   )rF   r"   c            K   s    t j| f|Ž | j|||ƒ d S )N)r   r(   r)   )r*   r   rF   r"   r+   r   r   r   r(   u  s    zPathPatch3D.__init__r   c             C   s    t j| |j||d� |j| _d S )N)rF   r"   )rx   r)   Zverticesrb   Ú_code3d)r*   r   rF   r"   r   r   r   r)   y  s    zPathPatch3D.set_3d_propertiesc       
      C   sX   | j }t|Ž \}}}tj||||jƒ\}}}}	tjtj||gƒ| j	ƒ| _
| j| _t|ƒS )N)ry   rW   r   r€   r1   r�   r‚   r   ro   r‰   r}   r{   r   rp   )
r*   r6   rƒ   rD   rE   rF   r„   r…   r†   r‡   r   r   r   rr   }  s    zPathPatch3D.do_3d_projectionN)r   r   )r9   r:   r;   r<   r(   r)   rr   r   r   r   r   rˆ   p  s   
rˆ   c             C   s2   | j ƒ }| jƒ }|j|ƒ}t|ƒr*|d S g S dS )z2Return a list of vertices for the path of a patch.r   N)Úget_patch_transformr~   Zto_polygonsr    )ÚpatchÚtransr   Zpolygonsr   r   r   Ú_get_patch_verts‡  s    
r�   c             C   s   t | ƒS )z2Return a list of vertices for the path of a patch.)r�   )r‹   r   r   r   Úget_patch_verts’  s    rŽ   c             C   s    t | ƒ}t| _| j|||ƒ dS )z$Convert a Patch to a Patch3D object.N)r�   rx   r>   r)   )r‹   r   r"   r|   r   r   r   Úpatch_2d_to_3d˜  s    r�   c             C   s2   | j ƒ }| jƒ }|j|ƒ}t| _| j|||ƒ dS )z,Convert a PathPatch to a PathPatch3D object.N)r~   rŠ   Ztransform_pathrˆ   r>   r)   )Z	pathpatchr   r"   r   rŒ   r�   r   r   r   Úpathpatch_2d_to_3dŸ  s
    
r�   c                   sB   e Zd ZdZddddœ‡ fdd„
Zdd	„ Zd
d„ Zdd„ Z‡  ZS )ÚPatch3DCollectionz%
    A collection of 3D patches.
    r   r   T)rF   r"   Ú
depthshadec               s$   || _ tƒ j||Ž | j||ƒ 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)Ú_depthshadeÚsuperr(   r)   )r*   rF   r"   r’   rG   r+   )r>   r   r   r(   ®  s    zPatch3DCollection.__init__c             C   s   || _ d| _dS )z&Set the position to use for z-sorting.TN)ri   r/   )r*   rj   r   r   r   rk   Â  s    zPatch3DCollection.set_sort_zposc             C   sd   | j ƒ  | jƒ }t|ƒdkr(|j\}}ng }g }t||tj|ƒ|ƒ| _| jƒ | _	| j
ƒ | _d| _d S )Nr   T)Úupdate_scalarmappableÚget_offsetsr    ÚTrJ   r   Ú
atleast_1dÚ
_offsets3drz   r{   Úget_edgecolorÚ_edgecolor3dr/   )r*   rF   r"   ÚoffsetsrD   rE   r   r   r   r)   Ç  s    

z#Patch3DCollection.set_3d_propertiesc             C   s¸   | j \}}}tj||||jƒ\}}}}| jr8t| j|ƒn| j}	tj|	| j	ƒ}	| j
|	ƒ | jrht| j|ƒn| j}
tj|
| j	ƒ}
| j|
ƒ tj| tj||gƒƒ |jdkr®t|ƒS tjS d S )Nr   )r™   r   r€   r1   r“   Ú_zalphar{   ÚmcolorsÚto_rgba_arrayÚ_alphaÚset_facecolorsr›   Úset_edgecolorsr
   Úset_offsetsr   ro   Úsizerp   Únan)r*   r6   rD   rE   rF   r„   r…   r†   r‡   ÚfcsÚecsr   r   r   rr   Ö  s    


z"Patch3DCollection.do_3d_projection)	r9   r:   r;   r<   r(   rk   r)   rr   Ú__classcell__r   r   )r>   r   r‘   ©  s
   r‘   c                   sB   e Zd ZdZddddœ‡ fdd„
Zdd	„ Zd
d„ Zdd„ Z‡  ZS )ÚPath3DCollectionz#
    A collection of 3D paths.
    r   r   T)rF   r"   r’   c               s$   || _ tƒ j||Ž | j||ƒ 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.
        N)r“   r”   r(   r)   )r*   rF   r"   r’   rG   r+   )r>   r   r   r(   ð  s    zPath3DCollection.__init__c             C   s   || _ d| _dS )z&Set the position to use for z-sorting.TN)ri   r/   )r*   rj   r   r   r   rk     s    zPath3DCollection.set_sort_zposc             C   sd   | j ƒ  | jƒ }t|ƒdkr(|j\}}ng }g }t||tj|ƒ|ƒ| _| jƒ | _	| j
ƒ | _d| _d S )Nr   T)r•   r–   r    r—   rJ   r   r˜   r™   rz   r{   rš   r›   r/   )r*   rF   r"   rœ   rD   rE   r   r   r   r)   	  s    

z"Path3DCollection.set_3d_propertiesc             C   s²   | j \}}}tj||||jƒ\}}}}| jr8t| j|ƒn| j}	tj|	| j	ƒ}	| j
|	ƒ | jrht| j|ƒn| j}
tj|
| j	ƒ}
| j|
ƒ tj| tj||gƒƒ |jr¬tj|ƒS tjS )N)r™   r   r€   r1   r“   r�   r{   rž   rŸ   r    r¡   r›   r¢   r   r£   r   ro   r¤   rp   r¥   )r*   r6   rD   rE   rF   r„   r…   r†   r‡   r¦   r§   r   r   r   rr     s    

z!Path3DCollection.do_3d_projection)	r9   r:   r;   r<   r(   rk   r)   rr   r¨   r   r   )r>   r   r©   ë  s
   r©   Tc             C   s8   t | tƒrt| _nt | tƒr"t| _|| _| j||ƒ 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*.

    N)Ú
isinstancer   r©   r>   r
   r‘   r“   r)   )ru   rF   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 dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )!ÚPoly3DCollectionz&
    A collection of 3D polygons.
    Úaverage)Úzsortc               s(   t ƒ j|f|ž|Ž | j|ƒ d| _dS )a  
        Create a Poly3DCollection.

        *verts* should contain 3D coordinates.

        Keyword arguments:
        zsort, see set_zsort for options.

        Note that this class does a bit of magic with the _facecolors
        and _edgecolors properties.
        N)r”   r(   Ú	set_zsortÚ_codes3d)r*   r|   r®   rG   r+   )r>   r   r   r(   I  s    
zPoly3DCollection.__init__)r­   rp   Úmaxc             C   s6   |dkrt jddd� d}| j| | _d| _d| _dS )a]  
        Sets 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.  *True* is
            deprecated and equivalent to 'average'.
        Tz3.1z�Passing True to mean 'average' for set_zsort is deprecated and support will be removed in Matplotlib 3.3; pass 'average' instead.)Úmessager­   N)r   Zwarn_deprecatedÚ_zsort_functionsÚ
_zsortfuncri   r/   )r*   r®   r   r   r   r¯   _  s    
zPoly3DCollection.set_zsortc             C   sš   d}d}g }g }x4|D ],}|j |ƒ |t|ƒ }|j||fƒ |}qW t|ƒr^t|Ž \}}}	ng g g   }}}	tjt|ƒƒ}
tj|||	|
gƒ| _|| _dS )zOptimize points for projection.r   N)	Úextendr    ÚappendrW   r   Úonesr   Ú_vecÚ_segis)r*   rv   ÚsiÚeiZsegisrn   ÚprD   rE   rF   r·   r   r   r   Ú
get_vectort  s    

zPoly3DCollection.get_vectorTc             C   s"   | j |ƒ tj| g dƒ || _dS )zSet 3D vertices.FN)r½   r	   Ú	set_vertsÚ_closed)r*   r|   Úclosedr   r   r   r¾   Š  s    
zPoly3DCollection.set_vertsc             C   s   | j |dd� || _dS )z!Sets 3D vertices with path codes.F)rÀ   N)r¾   r°   )r*   r|   rb   r   r   r   Úset_verts_and_codes‘  s    z$Poly3DCollection.set_verts_and_codesc             C   sF   | j ƒ  d | _| jdƒ tj| ƒ| _tj| ƒ| _tj| ƒ| _	d| _
d S )Nr­   T)r•   ri   r¯   r	   rz   Ú_facecolors3drš   Ú_edgecolors3dZ	get_alphaZ_alpha3dr/   )r*   r   r   r   r)   ™  s    
z"Poly3DCollection.set_3d_propertiesc             C   s   || _ d| _dS )z&Set the position to use for z-sorting.TN)ri   r/   )r*   rj   r   r   r   rk   ¤  s    zPoly3DCollection.set_sort_zposc       
         sÂ  ˆ j dk	rˆ jƒ  ˆ jˆ _tjˆ j|jƒ\‰‰‰‡‡‡fdd„ˆ jD ƒ}ˆ j}ˆ j	}t
|ƒt
|ƒkrv|jt
|ƒdd�}t
|ƒt
|ƒkrªt
|ƒdkr˜|}n|jt
|ƒdd�}t‡ fdd„tt|||ƒƒD ƒdd	„ d
d�}dd„ |D ƒ}ˆ jdk	�r‡ fdd„|D ƒ}tjˆ ||ƒ ntjˆ |ˆ jƒ dd„ |D ƒˆ _t
ˆ j	ƒt
|ƒk�rXdd„ |D ƒˆ _nˆ j	ˆ _ˆ jdk	�r¢tjdgdgˆ jgdggƒ}tj||jƒ}	|	d d S ˆjdk�r¸tjˆƒS tjS dS )z<
        Perform the 3D projection for this object.
        Nc                s2   g | ]*\}}ˆ ||… ˆ||… ˆ||… f‘qS r   r   )rR   rº   r»   )ÚtxsÚtysÚtzsr   r   rT   ³  s   z5Poly3DCollection.do_3d_projection.<locals>.<listcomp>r   )Zaxisc             3   s<   | ]4\}\\}}}}}ˆ j |ƒtj||gƒ|||fV  qd S )N)r´   r   ro   )rR   ÚidxrD   rE   rF   ÚfcÚec)r*   r   r   ú	<genexpr>Ã  s   z4Poly3DCollection.do_3d_projection.<locals>.<genexpr>c             S   s   | d S )Nr   r   )r   r   r   r   Ú<lambda>Æ  s    z3Poly3DCollection.do_3d_projection.<locals>.<lambda>T)ÚkeyÚreversec             S   s   g | ]\}}}}}|‘qS r   r   )rR   r   rƒ   rÈ   rÉ   rÇ   r   r   r   rT   È  s    c                s    g | ]\}}}}}ˆ j | ‘qS r   )r°   )rR   r   rƒ   rÈ   rÉ   rÇ   )r*   r   r   rT   Ê  s    c             S   s   g | ]\}}}}}|‘qS r   r   )rR   r   rƒ   rÈ   rÉ   rÇ   r   r   r   rT   Ï  s    c             S   s   g | ]\}}}}}|‘qS r   r   )rR   r   rƒ   rÈ   rÉ   rÇ   r   r   r   rT   Ñ  s    r   é   )Z_Ar•   Z_facecolorsrÂ   r   Z_proj_transform_vecr¸   r1   r¹   rÃ   r    ÚrepeatÚsortedÚ	enumeraterW   r°   r	   rÁ   r¾   r¿   Ú_facecolors2dÚ_edgecolors2dri   r   r   r¤   rp   r¥   )
r*   r6   ZxyzlistZcfaceZcedgeZz_segments_2drq   rb   ZzvecZztransr   )r*   rÄ   rÅ   rÆ   r   rr   ©  sD    



z!Poly3DCollection.do_3d_projectionc             C   s   t j| |ƒ t j| ƒ| _d S )N)r	   Úset_facecolorrz   rÂ   )r*   r   r   r   r   rÔ   â  s    zPoly3DCollection.set_facecolorc             C   s   t j| |ƒ t j| ƒ| _d S )N)r	   Úset_edgecolorrš   rÃ   )r*   r   r   r   r   rÕ   æ  s    zPoly3DCollection.set_edgecolorc             C   s®   |dk	r2yt |ƒ W n tk
r0   tdƒ‚Y nX tjj| |ƒ ytj| j| jƒ| _W n t	tt
fk
rp   Y nX ytj| j| jƒ| _W n t	tt
fk
r¢   Y nX d| _dS )z†
        Set the alpha transparencies of the collection.

        Parameters
        ----------
        alpha : float or None
        Nzalpha must be a float or NoneT)rH   rI   r   ZArtistÚ	set_alpharž   rŸ   rÂ   r    ÚAttributeErrorÚ
IndexErrorrÃ   Z_edgecolorsr/   )r*   Úalphar   r   r   rÖ   ê  s"    zPoly3DCollection.set_alphac             C   s   | j S )N)rÒ   )r*   r   r   r   rz     s    zPoly3DCollection.get_facecolorc             C   s   | j S )N)rÓ   )r*   r   r   r   rš     s    zPoly3DCollection.get_edgecolor)T)r9   r:   r;   r<   r(   r   r­   rp   r±   r³   r¯   r½   r¾   rÁ   r)   rk   rr   rÔ   rÕ   rÖ   rz   rš   r¨   r   r   )r>   r   r¬   D  s"   

9r¬   c             C   s2   t | jƒ ||ƒ\}}t| _| j||ƒ | jƒ  dS )z6Convert a PolyCollection to a Poly3DCollection object.N)rf   rt   r¬   r>   rÁ   r)   )ru   rF   r"   Zsegments_3drb   r   r   r   Úpoly_collection_2d_to_3d  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)rD   rE   rF   r"   r   r   r   rJ     s    

rJ   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   )rD   rE   rF   r"   r   r   r   rÜ   $  s    



rÜ   c             C   s*   t jt| ƒrtj| ƒn
ddddg|dfƒS )z@Stretch the color argument to provide the required number *num*.r   é   )r   rU   r    rž   rŸ   )ÚcÚnumr   r   r   Ú_get_colors8  s    rà   c             C   s
   t | |ƒS )z@Stretch the color argument to provide the required number *num*.)rà   )rÞ   rß   r   r   r   Ú
get_colors?  s    rá   c             C   s€   t |ƒdkrtjdƒS tt|ƒt|ƒƒ}d||ƒd  }tjtj| ƒt |ƒdfƒ}tj	|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æ?Nr   )r   rÝ   )
r    r   Úzerosr   rp   r±   rU   rž   rŸ   ro   )r   rF   ZnormZsatsZrgbar   r   r   r�   E  s    
r�   c             C   s
   t | |ƒS )z7Modify the alphas of the color list according to depth.)r�   )r   rF   r   r   r   ÚzalphaS  s    rã   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   T)r   r   )@r<   r2   Znumpyr   Z
matplotlibr   r   r   rž   r   r   r&   r   r�   Zmatplotlib.collectionsr   r	   r
   r   Zmatplotlib.colorsr   Zmatplotlib.patchesr   r%   r   r   Ú
deprecatedr   r   r   r#   r'   r$   r@   rB   rA   rO   r[   r\   r_   r`   rc   rd   rf   rg   rh   rw   rx   rˆ   r�   rŽ   r�   r�   r‘   r©   r«   r¬   rÚ   rJ   rÜ   rà   rá   r�   rã   r   r   r   r   Ú<module>   s`    #0
D



	

(



B?
 H
	