o
    i<r                     @   s  d Z ddlZddlZddl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dCddZG dd dejZdCddZ dCddZ!dCddZ"dCddZ#dCddZ$G d d! d!eZ%dCd"d#Z&G d$d% d%eZ'G d&d' d'e'Z(d(d) Z)dCd*d+Z*dCd,d-Z+G d.d/ d/eZ,G d0d1 d1eZ-d2d3 Z.dDd5d6Z/G d7d8 d8eZ0dCd9d:Z1d;d< Z2d=d> Z3d?d@ Z4dAdB Z5dS )Ezx
Module containing 3D artist code and functions to convert 2D
artists into 3D versions which can be added to an Axes3D.
    N)artistcolorslinestextpath)LineCollectionPolyCollectionPatchCollectionPathCollection)	Normalize)Patch   )proj3dc                 C       | d d } | dkr| d } | S )z?Return the given angle normalized to -180 < *a* <= 180 degrees.ih      ar   r   U/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/mpl_toolkits/mplot3d/art3d.py_norm_angle      r   c                 C   r   )z=Return the given angle normalized to -90 < *a* <= 90 degrees.r   Z   r   r   r   r   r   _norm_text_angle   r   r   c                 C   sj   | dkr	t dS | dkrt dS | dkrt dS | du r$t dS t | r1t| d	kr1| S td
)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.

    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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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   s2   |   \}}t|||f| _t|| _d| _d S NT)get_positionr   r   _position3dr$   _dir_vecstale)r,   r   r#   r   r   r   r   r   r+   b   s   

zText3D.set_3d_propertiesc                 C   s   t | j| j| j g|j}|d d |d d  }|d d |d d  }tt||}| |d d |d d f | 	t
| tj| | d| _d S )Nr   r   F)r   proj_trans_pointsr0   r1   Mmathdegreesatan2set_positionset_rotationr   r(   r)   drawr2   )r,   rendererprojdxdyangler   r   r   r:   h   s   
zText3D.drawc                 C   s   d S r'   r   )r,   r;   r   r   r   get_tightbboxt   s   zText3D.get_tightbboxN)r   r   r   r&   r   r   r   )
__name__
__module____qualname____doc__r*   r+   r   allow_rasterizationr:   r@   r   r   r   r   r%   J   s    


r%   r   c                 C      t | _| || dS )z"Convert a Text to a Text3D object.N)r%   	__class__r+   )objr   r#   r   r   r   text_2d_to_3dz   s   rJ   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 g|R i | |||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   s8   |   }|  }t||j}t||||| _d| _d S r.   )	get_xdata	get_ydatar   broadcast_toshapejuggle_axesrM   r2   )r,   rP   r#   rN   rO   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    rM   r2   )r,   rQ   r   r   r   set_data_3d   s   
zLine3D.set_data_3dc                 C      | j S )z
        Get the current data

        Returns
        -------
        verts3d : length-3 tuple or array-like
            The current data as a tuple or array-like.
        )rM   r,   r   r   r   get_data_3d   s   	zLine3D.get_data_3dc                 C   sH   | j \}}}t||||j\}}}| || tj| | d| _d S )NF)	rM   r   proj_transformr4   set_datar   rL   r:   r2   )r,   r;   xs3dys3dzs3drN   rO   rP   r   r   r   r:      s
   
zLine3D.drawNrA   )rB   rC   rD   rE   r*   r+   rW   rZ   r   rF   r:   r   r   r   r   rK      s    
rK   c                 C   rG   )zConvert a 2D line to 3D.N)rK   rH   r+   )linerP   r#   r   r   r   line_2d_to_3d   s   ra   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                        g | ]\}}}t ||| qS r   rV   rf   r   r   r   r"   r   r   rh           )r   rT   r    iter_segmentszip)r   rP   r#   pathsegssegseg3dr   r"   r   _path_to_3d_segment   s
   rs   c                    s,   t |t| } fddt| |D }|S )z6Convert paths from a collection object to 3D segments.c                       g | ]
\}}t || qS r   )rs   rf   r   pathzr"   r   r   rh          z)_paths_to_3d_segments.<locals>.<listcomp>)r   rT   r    ro   )pathsrP   r#   segsr   r"   r   _paths_to_3d_segments   s
   
rz   c                    sj   t |t| }| jddd}dd t||D }|r+t| \}} fdd|D }ng }g }|t|fS )z/Convert a path to a 3D segment with path codes.Frb   c                 S   s&   g | ]\\\}}}}|||f|fqS r   r   re   r   r   r   rh      s   & z2_path_to_3d_segment_with_codes.<locals>.<listcomp>c                    rj   r   rk   rl   r"   r   r   rh      rm   )r   rT   r    rn   ro   list)r   rP   r#   rp   	seg_codesrq   codesrr   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                    rt   r   )r~   ru   r"   r   r   rh      rw   z4_paths_to_3d_segments_with_codes.<locals>.<listcomp>)r   rT   r    ro   r{   )rx   rP   r#   segments_codessegmentsr}   r   r"   r    _paths_to_3d_segments_with_codes   s   

r   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      || _ d| _dS z&Set the position to use for z-sorting.TN
_sort_zposr2   r,   valr   r   r   set_sort_zpos      
zLine3DCollection.set_sort_zposc                 C   s   || _ t| g  dS )z"
        Set 3D segments.
        N)_segments3dr   set_segments)r,   r   r   r   r   r      s   zLine3DCollection.set_segmentsc                    s\   t |   fdd| jD }dd |D }t| | d}|D ]\}}}t|t|}q|S )zB
        Project the points according to renderer matrix.
        c                    s   g | ]	}t | jqS r   )r   r3   r4   )rf   pointsr;   r   r   rh     s    z5Line3DCollection.do_3d_projection.<locals>.<listcomp>c                 S   s    g | ]\}}}t ||gqS r   )r   column_stack)rf   rN   rO   rP   r   r   r   rh     rm   g    eA)_update_scalarmappabler   r   r   min)r,   r;   xyslistsegments_2dminzrN   rO   rP   r   r   r   do_3d_projection  s   
z!Line3DCollection.do_3d_projectionFc                 C   s   |r|  | t| | d S r'   )r   r   r:   )r,   r;   projectr   r   r   r:     s   
zLine3DCollection.drawN)F)
rB   rC   rD   rE   r   r   r   r   rF   r:   r   r   r   r   r      s    r   c                 C   s$   t |  ||}t| _| | dS )z6Convert a LineCollection to a Line3DCollection object.N)rz   	get_pathsr   rH   r   )colrP   r#   
segments3dr   r   r   line_collection_2d_to_3d   s   r   c                   @   sB   e Zd ZdZd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   r   rP   r#   c                O   s(   t j| g|R i | | || d S r'   r   r*   r+   )r,   rP   r#   rQ   r-   r   r   r   r*   ,  s   zPatch3D.__init__r   c                    s:   t |t|} fddt||D | _t| | _d S )Nc                    s"   g | ]\\}}}t ||| qS r   rk   rl   r"   r   r   rh   2  s    
z-Patch3D.set_3d_properties.<locals>.<listcomp>)r   rT   r    ro   
_segment3dr   get_facecolor_facecolor3d)r,   vertsrP   r#   r   r"   r   r+   0  s
   
zPatch3D.set_3d_propertiesc                 C   rX   r'   )_path2drY   r   r   r   get_path6     zPatch3D.get_pathc                 C   rX   r'   )_facecolor2drY   r   r   r   r   9  r   zPatch3D.get_facecolorc           
      C   sT   | j }t| \}}}t||||j\}}}}	tt||g| _	| j
| _t|S r'   )r   ro   r   proj_transform_clipr4   mpathPathr   r   r   r   r   r   
r,   r;   srN   rO   rP   vxsvysvzsvisr   r   r   r   <  s   zPatch3D.do_3d_projectionNrA   )	rB   rC   rD   rE   r*   r+   r   r   r   r   r   r   r   r   '  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   rP   r#   r-   r   r   r   r*   K  s   zPathPatch3D.__init__r   c                 C   s    t j| |j||d |j| _d S )Nr   )r   r+   verticesr}   _code3d)r,   r   rP   r#   r   r   r   r+   O  s   zPathPatch3D.set_3d_propertiesc           
      C   sX   | j }t| \}}}t||||j\}}}}	tt||g| j	| _
| j| _t|S r'   )r   ro   r   r   r4   r   r   r   r   r   r   r   r   r   r   r   r   r   r   S  s   zPathPatch3D.do_3d_projectionNrA   )rB   rC   rD   rE   r*   r+   r   r   r   r   r   r   F  s
    
r   c                 C   s.   |   }|  }||}t|r|d S g S )z2Return a list of vertices for the path of a patch.r   )get_patch_transformr   to_polygonsr    )patchtransr   polygonsr   r   r   _get_patch_verts]  s   
r   c                 C   s    t | }t| _| ||| dS )z$Convert a Patch to a Patch3D object.N)r   r   rH   r+   )r   r   r#   r   r   r   r   patch_2d_to_3dh  s   r   c                 C   s2   |   }|  }||}t| _| ||| dS )z,Convert a PathPatch to a PathPatch3D object.N)r   r   transform_pathr   rH   r+   )	pathpatchr   r#   r   r   r   r   r   r   pathpatch_2d_to_3do  s
   
r   c                       B   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rP   r#   
depthshadec                   (   || _ 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_depthshadesuperr*   r+   r,   rP   r#   r   rQ   r-   rH   r   r   r*   ~     zPatch3DCollection.__init__c                 C   r   r   r   r   r   r   r   r     r   zPatch3DCollection.set_sort_zposc                 C   sd   |    |  }t|dkr|j\}}ng }g }t||t||| _|  | _	| 
 | _d| _d S Nr   T)update_scalarmappableget_offsetsr    TrV   r   
atleast_1d
_offsets3dr   r   get_edgecolor_edgecolor3dr2   r,   rP   r#   offsetsrN   rO   r   r   r   r+     s   


z#Patch3DCollection.set_3d_propertiesc                 C   s   t |  | j\}}}t||||j\}}}}| jr t| j|n| j}	t	|	| j
}	| |	 | jr8t| j|n| j}
t	|
| j
}
| |
 t| t||g |jdkr[t|S tjS Nr   )r   r   r   r   r4   r   _zalphar   mcolorsto_rgba_array_alphaset_facecolorsr   set_edgecolorsr	   set_offsetsr   r   sizer   nan)r,   r;   rN   rO   rP   r   r   r   r   fcsecsr   r   r   r     s"   


z"Patch3DCollection.do_3d_projection	rB   rC   rD   rE   r*   r   r+   r   __classcell__r   r   r   r   r   y  s    r   c                       r   )Path3DCollectionz#
    A collection of 3D paths.
    r   r   Tr   c                   r   )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.
        Nr   r   r   r   r   r*     r   zPath3DCollection.__init__c                 C   r   r   r   r   r   r   r   r     r   zPath3DCollection.set_sort_zposc                 C   sx   |    |  }t|dkr|j\}}ng }g }t||t||| _|  | _	| 
 | _|  | _|  | _d| _d S r   )r   r   r    r   rV   r   r   r   r   r   r   r   	get_sizes_sizes3dget_linewidth_linewidth3dr2   r   r   r   r   r+     s   




z"Path3DCollection.set_3d_propertiesc                 C   sZ  t |  | j\}}}t||||j\}}}}| jr t| j|n| j}	| jr,t| j|n| j}
| j	}| j
}t|d d d }|| }|| }|| }t|	dkrU|	| }	t|
dkr_|
| }
t|dkri|| }t|dkrs|| }t||f}t|	| j}	t|
| j}
| |
 | |	 | | | | t| | |jrt|S tjS )Nr   )r   r   r   r   r4   r   r   r   r   r   r   r   argsortr    r   r   r   r   r   r   	set_sizesset_linewidthr
   r   r   r   r   )r,   r;   rN   rO   rP   r   r   r   r   r   r   sizeslwsz_markers_idxvpsr   r   r   r     s@   



z!Path3DCollection.do_3d_projectionr   r   r   r   r   r     s    r   c                 C   sP   | j du rdS | jd }|  }|r$| jr| j| _dS | jr&| j| _dS dS dS )a	  
    Update a 3D ScalarMappable.

    With ScalarMappable objects if the data, colormap, or norm are
    changed, we need to update the computed colors.  This is handled
    by the base class method update_scalarmappable.  This method works
    by, detecting if work needs to be done, and if so stashing it on
    the ``self._facecolors`` attribute.

    With 3D collections we internally sort the components so that
    things that should be "in front" are rendered later to simulate
    having a z-buffer (in addition to doing the projections).  This is
    handled in the ``do_3d_projection`` methods which are called from the
    draw method of the 3D Axes.  These methods:

    - do the projection from 3D -> 2D
    - internally sort based on depth
    - stash the results of the above in the 2D analogs of state
    - return the z-depth of the whole artist

    the last step is so that we can, at the Axes level, sort the children by
    depth.

    The base `draw` method of the 2D artists unconditionally calls
    update_scalarmappable and rely on the method's internal caching logic to
    lazily evaluate.

    These things together mean you can have the sequence of events:

    - we create the artist, do the color mapping and stash the results
      in a 3D specific state.
    - change something about the ScalarMappable that marks it as in
      need of an update (`ScalarMappable.changed` and friends).
    - We call do_3d_projection and shuffle the stashed colors into the
      2D version of face colors
    - the draw method calls the update_scalarmappable method which
      overwrites our shuffled colors
    - we get a render that is wrong
    - if we re-render (either with a second save or implicitly via
      tight_layout / constrained_layout / bbox_inches='tight' (ex via
      inline's defaults)) we again shuffle the 3D colors
    - because the CM is not marked as changed update_scalarmappable is
      a no-op and we get a correct looking render.

    This function is an internal helper to:

    - sort out if we need to do the color mapping at all (has data!)
    - sort out if update_scalarmappable is going to be a no-op
    - copy the data over from the 2D -> 3D version

    This must be called first thing in do_3d_projection to make sure that
    the correct colors get shuffled.

    Parameters
    ----------
    sm : ScalarMappable
        The ScalarMappable to update and stash the 3D data from

    Nr   )	_A_update_dictr   
_is_filled_facecolorsr   _is_stroked_edgecolorsr   )sm
copy_stateretr   r   r   r     s   
<
r   Tc                 C   s8   t | tr	t| _nt | trt| _|| _| || 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   rH   r	   r   r   r+   )r   rP   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 )!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                   s.   t  j|g|R i | | | d| _dS )aP  
        Parameters
        ----------
        verts : list of array-like Nx3
            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.
        N)r   r*   	set_zsort_codes3d)r,   r   r   rQ   r-   r   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   r2   )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    )rf   segmentr   r   r   rh     s    z/Poly3DCollection.get_vector.<locals>.<listcomp>Nr   r   )r    r   	row_stackr   onesr   _veccumsummapslice
_segslices)r,   r   rN   rO   rP   r  indicesr   r   r   
get_vector  s   &zPoly3DCollection.get_vectorTc                 C   s"   |  | t| 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 Set 3D vertices with path codes.F)r  N)r	  r   )r,   r   r}   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   r   r   r   	get_alpha_alpha3dr2   rY   r   r   r   r+     s   

z"Poly3DCollection.set_3d_propertiesc                 C   r   r   r   r   r   r   r   r     r   zPoly3DCollection.set_sort_zposc                    s  t   t j|j\fdd jD } j} j}t|t|kr2|j	t|dd}t|t|krLt|dkrC|}n	|j	t|dd}t
 fddtt|||D dd d	d
}t| \}} _ _} jdur 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}|d d S jdkrtS tjS )z<
        Perform the 3D projection for this object.
        c                    s"   g | ]} | | | fqS r   r   )rf   sl)txstystzsr   r   rh     ri   z5Poly3DCollection.do_3d_projection.<locals>.<listcomp>r   )axisc                 3   s>    | ]\}\\}}}}}  |t||g|||fV  qd S r'   )r   r   r   )rf   idxrN   rO   rP   fcecrY   r   r   	<genexpr>  s    &z4Poly3DCollection.do_3d_projection.<locals>.<genexpr>c                 S   s   | d S r   r   )r   r   r   r   <lambda>  s    z3Poly3DCollection.do_3d_projection.<locals>.<lambda>T)keyreverseNc                    s   g | ]} j | qS r   )r   )rf   r  rY   r   r   rh     s    r      )r   r   _proj_transform_vecr  r4   r  r   r   r    repeatsorted	enumeratero   _facecolors2d_edgecolors2dr   r   r  r	  r
  r   r   r   r   r   r   )r,   r;   xyzlistcfacecedgez_segments_2dzzsr   idxsr}   zvecztransr   )r,   r  r  r  r   r     s@   




z!Poly3DCollection.do_3d_projectionc                 C      t | | t | | _d S r'   )r   set_facecolorr   r   r,   r   r   r   r   r+       zPoly3DCollection.set_facecolorc                 C   r*  r'   )r   set_edgecolorr   r   r,  r   r   r   r.    r-  zPoly3DCollection.set_edgecolorc              
   C   sx   t j| | zt| j| j| _W n ttt	fy   Y nw zt| j
| j| _W n ttt	fy6   Y nw d| _d S r.   )r   Artist	set_alphar   r   r   r   AttributeError	TypeError
IndexErrorr   r   r2   )r,   alphar   r   r   r0  !  s    


zPoly3DCollection.set_alphac                 C   rX   r'   )r   rY   r   r   r   r   0  r   zPoly3DCollection.get_facecolorc                 C   rX   r'   )r!  rY   r   r   r   r   3  r   zPoly3DCollection.get_edgecolor)T)rB   rC   rD   rE   r*   r   r   r   r   r   r   r  r	  r  r+   r   r   r+  r.  r0  r   r   r   r   r   r   r   r   z  s&    
5r   c                 C   s2   t |  ||\}}t| _| || |   dS )z6Convert a PolyCollection to a Poly3DCollection object.N)r   r   r   rH   r  r+   )r   rP   r#   segments_3dr}   r   r   r   poly_collection_2d_to_3d7  s   
r6  c                 C   sH   |dkr	|| |fS |dkr| ||fS |d dkrt | |||S | ||f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   -)rotate_axesrN   rO   rP   r#   r   r   r   rV   @  s   


rV   c                 C   sR   |dkr	||| fS |dkr|| |fS |dkr|| |fS |dkr$||| fS | ||f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-yr   r9  r   r   r   r8  P  s   




r8  c                 C   s&   t t| rt| ng d|dfS )z@Stretch the color argument to provide the required number *num*.)r   r   r   r      )r   rT   r    r   r   )cnumr   r   r   _get_colorsd  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:  r   gffffff?r:  Nr   )
r    r   zerosr   r   r   rT   r   r   r   )r   rP   normsatsrgbar   r   r   r   k  s   
.r   rA   )r   r   T)6rE   r5   numpyr   
matplotlibr   r   r   r   r   r(   r   r   matplotlib.collectionsr   r   r	   r
   matplotlib.colorsr   matplotlib.patchesr   r&   r   r   r   r$   r)   r%   rJ   rL   rK   ra   rs   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r6  rV   r8  r=  r   r   r   r   r   <module>   sJ   #
0
>



	

*


D\
G 
>	