
    
3j                     T   S r SSKrSSKrSSKJr  SSKJrJrJ	r	J
rJrJrJrJr  SSKJrJrJrJrJr  SSKJr  SSKJr  S	 rS
 rS rS rS r  " S S\RB                  5      r"S5S jr# " S S\RH                  5      r%S5S jr&S6S jr'S6S jr(S6S jr)S6S jr* " S S\5      r+S5S jr, " S S\5      r-S5S jr. " S S\5      r/ " S  S!\/5      r0S" r1S5S# jr2S6S$ jr3 " S% S&\5      r4S' r5 " S( S)\5      r6    S7SS*.S+ jjr7 " S, S-\5      r8S5S. jr9S/ r:S0 r;  S8S1 jr<S9S2 jr=S3 r>S:S4 jr?g);zx
Module containing 3D artist code and functions to convert 2D
artists into 3D versions which can be added to an Axes3D.
    N)contextmanager)_apiartistcbookcolorslinestextpathrcParams)
CollectionLineCollectionPolyCollectionPatchCollectionPathCollection)Patch   )proj3dc                 ,    U S-   S-  n U S:  a  U S-
  n U $ )z?Return the given angle normalized to -180 < *a* <= 180 degrees.ih      as    T/home/wildlama/miniconda3/lib/python3.13/site-packages/mpl_toolkits/mplot3d/art3d.py_norm_angler      s$    	
SCA3wGH    c                 ,    U S-   S-  n U S:  a  U S-
  n U $ )z=Return the given angle normalized to -90 < *a* <= 90 degrees.r   Z   r   r   s    r   _norm_text_angler   !   s$    	
SCA2vGHr   c                    [         R                  " U S5      (       a  [        R                  " S5      $ [         R                  " U S5      (       a  [        R                  " S5      $ [         R                  " U S5      (       a  [        R                  " S5      $ U c  [        R                  " S5      $ [        R                  " U 5      (       a%  [        U 5      S:X  a  [        R                  " U 5      $ [        S	5      e)
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 an array

Returns
-------
x, y, z : array
    The direction vector.
x)r   r   r   y)r   r   r   z)r   r   r   )r   r   r      z2'x', 'y', 'z', None or vector of length 3 expected)r   
_str_equalnparrayiterablelen
ValueError)zdirs    r   get_dir_vectorr+   )   s    ( c""xx	""			$	$	$xx	""			$	$	$xx	""	xx	""	T		s4yA~xx~MNNr   c           	      X   [         R                  R                  XR                  R                  :  XR                  R
                  :  XR                  R                  :  XR                  R                  :  X#R                  R                  :  X#R                  R
                  :  45      nU$ )a-  
Return the mask of the points outside the axes view limits.

Parameters
----------
xs, ys, zs : array-like
    The points to mask. These should be in data coordinates.
axes : Axes3D
    The axes to use for the view limits.

Returns
-------
mask : np.array
    The mask of the points as a bool array.
)	r%   
logical_orreduce
xy_viewLimxminxmaxyminymax
zz_viewLim)xsyszsaxesmasks        r   _viewlim_maskr:   K   s      ==oo&:&:!:!#oo&:&:!:!#oo&:&:!:!#oo&:&:!:!#oo&:&:!:!#oo&:&:!:!< =D Kr   c           	         [         R                  R                  [         R                  " UR                  R
                  R                  U 5      5      [         R                  " UR                  R
                  R                  U5      5      [         R                  " UR                  R
                  R                  U5      5      45      $ )a  
Return the mask of points whose coordinates are invalid for the axis
scale they live on (e.g. <=0 on a log axis).

Parameters
----------
xs, ys, zs : array-like
    The points to check, in data coordinates.
axes : Axes3D
    The axes whose scales are queried.

Returns
-------
mask : np.ndarray
    Boolean array, ``True`` where any of x/y/z is out of its scale's
    valid domain.
)	r%   r-   r.   logical_notxaxis_scaleval_in_rangeyaxiszaxis)r5   r6   r7   r8   s       r   _scale_invalid_maskrB   d   s    $ ==
tzz((55b9:
tzz((55b9:
tzz((55b9:!< = =r   c                   ~   ^  \ rS rSrSrSS jrS rSU 4S jjrS rSS jr	\
R                  S 5       rSS	 jrS
rU =r$ )Text3D|   a  
Text object with 3D position and direction.

Parameters
----------
x, y, z : float
    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.
axlim_clip : bool, default: False
    Whether to hide text outside the axes view limits.

    .. versionadded:: 3.10

Other Parameters
----------------
**kwargs
     All other parameters are passed on to `~matplotlib.text.Text`.
c                     SU;   a  [         R                  " S5        SU;   a  [         R                  " S5        [        R                  R                  " XX$40 UD6  U R                  X5U5        g )NrotationzOThe `rotation` parameter has not yet been implemented and is currently ignored.rotation_modezTThe `rotation_mode` parameter has not yet been implemented and is currently ignored.)r   warn_externalmtextText__init__set_3d_properties)selfr    r!   r"   r	   r*   
axlim_clipkwargss           r   rL   Text3D.__init__   se    , f$, 	

DQ77q
3r   c                 H    U R                   U R                  U R                  4$ )z*Return the (x, y, z) position of the text.)_x_y_zrN   s    r   get_position_3dText3D.get_position_3d   s    ww((r   c                 z   > [         TU ]  USS 5        U R                  US   5        Ub  [        U5      U l        gg)a0  
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. See `.get_dir_vector` for a description of the values.
N   )superset_positionset_zr+   _dir_vec)rN   xyzr*   	__class__s      r   set_position_3dText3D.set_position_3d   s?     	S!W%

3q6*40DM r   c                     Xl         SU l        g)zD
Set the *z* position of the text.

Parameters
----------
z : float
TN)rU   stale)rN   r"   s     r   r]   Text3D.set_z   s     
r   c                 J    Xl         [        U5      U l        X0l        SU l        g)ao  
Set the *z* position and direction of the text.

Parameters
----------
z : float
    The z-position in 3D space.
zdir : {'x', 'y', 'z', 3-tuple}
    The direction of the text. Default: 'z'.
    See `.get_dir_vector` for a description of the values.
axlim_clip : bool, default: False
    Whether to hide text outside the axes view limits.

    .. versionadded:: 3.10
TN)rU   r+   r^   _axlim_cliprd   )rN   r"   r*   rO   s       r   rM   Text3D.set_3d_properties   s"      &t,%
r   c                    [        U R                  U R                  U R                  U R                  5      nU R
                  (       a9  U[        U R                  U R                  U R                  U R                  5      -  n[        R                  " U5      (       ab  [        R                  R                  U R                  U R                  U R                  /U[        S9R                  [        R                  5      nO:[        R                  " U R                  U R                  U R                  /[        S9nX0R                  -   n[        R                  " X4/5      n[         R"                  " US S 2S4   US S 2S4   US S 2S4   U R                  5      nUS   S   US   S   -
  nUS   S   US   S   -
  n[$        R&                  " [$        R(                  " X5      5      n	[*        R,                  " XS   S   US   S   [/        U	5      S9   [0        R2                  R5                  X5        S S S 5        SU l        g ! , (       d  f       N= f)N)r9   dtyperj   r   r   rZ   )rS   rT   	_rotationF)rB   rS   rT   rU   r8   rg   r:   r%   anymar&   floatfillednanr^   asarrayr   _scale_proj_transformmathdegreesatan2r   _setattr_cmr   rJ   rK   drawrd   )
rN   rendererr9   pos3ddir_endpointsprojdxdyangles
             r   rx   Text3D.draw   s   "477DGGTWWdiiHM$''477DGGTYYGGD66$<<EEKK$''477 ;%)   88>rvv  HHdggtww8FE--'U,-++1a4L&A,q!tdiiA!WQZ$q'!*$!WQZ$q'!*$TZZ/0tQ
tAwqz)9%)@BJJOOD+B 
B Bs    H<<
I
c                     g Nr   )rN   ry   s     r   get_tightbboxText3D.get_tightbbox   s     r   )rg   r^   rU   rd   )r   r   r    r"   Fr   r   r"   F)__name__
__module____qualname____firstlineno____doc__rL   rW   ra   r]   rM   r   allow_rasterizationrx   r   __static_attributes____classcell__r`   s   @r   rD   rD   |   sE    .4)1"	*   , r   rD   c                 >    [         U l        U R                  XU5        g)ah  
Convert a `.Text` to a `.Text3D` object.

Parameters
----------
z : float
    The z-position in 3D space.
zdir : {'x', 'y', 'z', 3-tuple}
    The direction of the text. Default: 'z'.
    See `.get_dir_vector` for a description of the values.
axlim_clip : bool, default: False
    Whether to hide text outside the axes view limits.

    .. versionadded:: 3.10
N)rD   r`   rM   )objr"   r*   rO   s       r   text_2d_to_3dr      s      CM!:.r   c                   t   ^  \ rS rSrSrSS.U 4S jjrSS jrS rS r\	R                  U 4S	 j5       rS
rU =r$ )Line3Di	  a  
3D line object.

.. note:: Use `get_data_3d` to obtain the data associated with the line.
        `~.Line2D.get_data`, `~.Line2D.get_xdata`, and `~.Line2D.get_ydata` return
        the x- and y-coordinates of the projected 2D-line, not the x- and y-data of
        the 3D-line. Similarly, use `set_data_3d` to set the data, not
        `~.Line2D.set_data`, `~.Line2D.set_xdata`, and `~.Line2D.set_ydata`.
F)rO   c                `   > [         TU ]  " / / /UQ70 UD6  U R                  XU5        X@l        g)z

Parameters
----------
xs : array-like
    The x-data to be plotted.
ys : array-like
    The y-data to be plotted.
zs : array-like
    The z-data to be plotted.
*args, **kwargs
    Additional arguments are passed to `~matplotlib.lines.Line2D`.
N)r[   rL   set_data_3drg   )rN   r5   r6   r7   rO   argsrP   r`   s          r   rL   Line3D.__init__  s4     	R1$1&1$%r   c                    U R                  5       nU R                  5       n[        R                  " U5      R	                  5       n[
        R                  " U[        U5      5      n[        XEX5      U l	        X0l
        SU l        g)a  
Set the *z* position and direction of the line.

Parameters
----------
zs : float or array of floats
    The location along the *zdir* axis in 3D space to position the
    line.
zdir : {'x', 'y', 'z'}
    Plane to plot line orthogonal to. Default: 'z'.
    See `.get_dir_vector` for a description of the values.
axlim_clip : bool, default: False
    Whether to hide lines with an endpoint outside the axes view limits.

    .. versionadded:: 3.10
TN)	get_xdata	get_ydatar   _to_unmasked_float_arrayravelr%   broadcast_tor(   juggle_axes_verts3drg   rd   )rN   r7   r*   rO   r5   r6   s         r   rM   Line3D.set_3d_properties&  sd    " ^^^^++B/557__RR)#BB5%
r   c                     [        U5      S:X  a  US   n[        SU5       H.  u  p#[        R                  " U5      (       a  M"  [	        U S35      e   Xl        SU l        g)z
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   r_   z must be a sequenceTN)r(   zipr%   r'   RuntimeErrorr   rd   )rN   r   namer_   s       r   r   Line3D.set_data_3d?  s[    " t9>7DUD)ID;;s##"dV+>#?@@ * 
r   c                     U R                   $ )z}
Get the current data

Returns
-------
verts3d : length-3 tuple or array-like
    The current data as a tuple or array-like.
)r   rV   s    r   get_data_3dLine3D.get_data_3dX  s     }}r   c                   > [        / U R                  QU R                  P76 nU R                  (       a$  U[	        / U R                  QU R                  P76 -  n[
        R                  " U5      (       a  [
        R                  " U[        U R                  5      /U R                  S   R                  Q75      n[
        R                  R                  U R                  [        US9R                  [
        R                  5      u  pEnOU R                  u  pEn[        R                   " XEX`R                  5      u  pxpU R#                  Xx5        [$        TU ]M  U5        SU l        g )Nr   rj   r9   F)rB   r   r8   rg   r:   r%   rm   r   r(   shapern   r&   ro   rp   rq   r   _scale_proj_transform_clipset_datar[   rx   rd   )rN   ry   
scale_maskr9   xs3dys3dzs3dr5   r6   r7   tisr`   s              r   rx   Line3D.drawc  s
   (C$--CC
-BB		BBJ66*??T]]#=dmmA&6&<&<=D  "uu{{4==16T  +  CCI6"&&> D  $}}D ;;DiiXbX
r   )rg   r   rd   r   )r   r   r   r   r   rL   rM   r   r   r   r   rx   r   r   r   s   @r   r   r   	  s@     6; & &$22	   r   r   c                 >    [         U l        U R                  XU5        g)a  
Convert a `.Line2D` to a `.Line3D` object.

Parameters
----------
zs : float
    The location along the *zdir* axis in 3D space to position the line.
zdir : {'x', 'y', 'z'}
    Plane to plot line orthogonal to. Default: 'z'.
    See `.get_dir_vector` for a description of the values.
axlim_clip : bool, default: False
    Whether to hide lines with an endpoint outside the axes view limits.

    .. versionadded:: 3.10
N)r   r`   rM   )liner7   r*   rO   s       r   line_2d_to_3dr   w  s    " DN2Z0r   c                    [         R                  " U[        U 5      5      nU R                  SSS9n[	        X15       VVVVs/ s H  u  u  u  pEpgXEU4PM     nnnnnU VVVs/ s H  u  pEn[        XEXr5      PM     n	nnnU	$ s  snnnnf s  snnnf )zConvert a path to a 3D segment.Fsimplifycurves)r%   r   r(   iter_segmentsr   r   )
r
   r7   r*   pathsegsr    r!   coder"   segseg3ds
             r   _path_to_3d_segmentr     s     
SY	'B!!5!?H03H0A
B0A,.6A4A!90AC
B9<=IQ1[q'E=L C=s   B 
!Bc           	      "   [         R                  " U5      (       d!  [         R                  " U[        U 5      5      nO#[        U5      [        U 5      :w  a  [	        S5      e[        X5       VVs/ s H  u  p4[        X4U5      PM     nnnU$ s  snnf )z6Convert paths from a collection object to 3D segments.z-Number of z-coordinates does not match paths.)r%   r'   r   r(   r)   r   r   )pathsr7   r*   r
   pathzsegss         r   _paths_to_3d_segmentsr     sz     ;;r??__RU,r7c%j LMM  #5~/-  T2- 	 /K/s   .Bc                 d   [         R                  " U[        U 5      5      nU R                  SSS9n[	        X15       VVVVs/ s H  u  u  u  pEpgXEU4U4PM     nnnnnU(       a.  [	        U6 u  pU	 VVVs/ s H  u  pEn[        XEXr5      PM     nnnnO/ n/ n
U[        U
5      4$ s  snnnnf s  snnnf )z/Convert a path to a 3D segment with path codes.Fr   )r%   r   r(   r   r   r   list)r
   r7   r*   r   r    r!   r   r"   	seg_codesr   codesr   s               r   _path_to_3d_segment_with_codesr     s     
SY	'B!!5!?H<?<MN<M'8~1)T"<MIN)_
=@AS	qQ1+SA$u+ O Bs   B#
4B+c           	          [         R                  " U[        U 5      5      n[        X5       VVs/ s H  u  p4[	        X4U5      PM     nnnU(       a  [        U6 u  pgO/ / pv[        U5      [        U5      4$ s  snnf )zH
Convert paths from a collection object to 3D segments with path codes.
)r%   r   r(   r   r   r   )r   r7   r*   r
   r   segments_codessegmentsr   s           r    _paths_to_3d_segments_with_codesr     su    
 
SZ	(B),U9)7+$ 5T$G)7  9~.%b%>4;&&9s   A5c                       \ rS rSrSrS rSrg)Collection3Di  zA collection of 3D paths.c                    U R                    VVs/ s H  u  pUPM	     nnnU Vs/ s H$  n[        / UR                  QU R                  P76 PM&     nnU R                  (       aA  [        XC5       VVs/ s H)  u  pQU[        / UR                  QU R                  P76 -  PM+     nnn[        X45       VVs/ s H^  u  p[        R                  " U5      (       a<  [        R                  R                  U[        R                  " XQR                  5      S9OUPM`     nnnU Vs/ s H;  n[        R                  " USS2S4   USS2S4   USS2S4   U R                  5      PM=     nn[        X`R                   5       VVVV	s/ s H@  u  u  pxnu  p)[        R                   " [        R                  R#                  Xx/5      U	5      PMB     sn	nnnU l        [        R&                  " U VV
s/ s H  u    p*U
PM
     sn
n5      n
[)        U
5      (       a  U
R+                  5       $ S$ s  snnf s  snf s  snnf s  snnf s  snf s  sn	nnnf s  sn
nf )z0Project the points according to renderer matrix.r9   Nr   r   rZ       eA)_3dverts_codesrB   Tr8   rg   r   r:   r%   rm   rn   r&   r   r   r   rs   mpathPathcolumn_stack_pathsconcatenater(   min)rN   vs_vs_listmasksm	xyzs_listr5   r6   csr7   s              r   do_3d_projectionCollection3D.do_3d_projection  s   #'#6#67#6%"2#67AHI2$6bdd6DII6I"%e"57"5 88dii88"5  7 !$G 35 3ur ffQii 55;;r88(D;E%'( 3 	 5 @GH?F 11q!tHbAh1a4$))5?F 	 H 47yBUBU3VX3V/;BA zz"%%"4"4bX">C3VX^^	:	HAqR	:;r77rvvx++ 8I75HX:s+   H+H"10H'2A%H-AH3<AH8
#I 
)r   N)r   r   r   r   r   r   r   r   r   r   r   r     s
    #,r   r   c                 8   [         R                  " U[        U R                  5       5      5      n[	        U R                  5       U5       VVs/ s H  u  pE[         R
                  " [        / [         R
                  " UR                  [         R                  " U[        UR                  5      5      /5      R                  QUP76 5      UR                  4PM     snnU l
        [        R                  " [        S5      " [        U 5      5      U l        X0l        gs  snnf )z4Convert a `.Collection` to a `.Collection3D` object.z{}3DN)r%   r   r(   	get_pathsr   r   r   verticesr   r   r   r   _make_class_factoryr   typer`   rg   )colr7   r*   rO   pr"   s         r   collection_2d_to_3dr     s    	S1	2B ,.
 -DA	 
 __ajj"//!S_*MNOQQ 
 
	 -.C --lFCDINCM O.s   BDc                   H   ^  \ rS rSrSrSU 4S jjrS rU 4S jrS rSr	U =r
$ )	Line3DCollectioni  z
A collection of 3D lines.
c                 4   > [         TU ]  " U40 UD6  X l        g r   )r[   rL   rg   )rN   r   rO   rP   r`   s       r   rL   Line3DCollection.__init__  s     )&)%	r   c                     Xl         SU l        gz&Set the position to use for z-sorting.TN
_sort_zposrd   rN   vals     r   set_sort_zposLine3DCollection.set_sort_zpos      
r   c                 0   > Xl         [        TU ]	  / 5        g)z
Set 3D segments.
N)_segments3dr[   set_segments)rN   r   r`   s     r   r   Line3DCollection.set_segments	  s     $R r   c                 .   U R                   nU Vs/ s H  n[        U5      PM     nn[        [        U5      5      S:  nU(       aN  [        S U 5       5      (       a   [        R
                  R                  U5      nO-[        R                  " U5      nO[        R                  " U5      nUR                  S:X  a'  [        R                  " U / 5        [        R                  $ Sn[        R
                  R                  U5      (       a3  UR                  [        R
                  R                  La  UR                  n[        US   US   US   U R                   5      n[        R                  " U5      (       a<  U[        R"                  " US[        R$                  4   / UR&                  QS	P75      -  nU R(                  (       ay  [+        US   US   US   U R                   5      n[        R                  " U5      (       a=  [        R"                  " US[        R$                  4   / UR&                  QS	P75      nXW-  n[,        R.                  " XR                   5      nUSLa  [        R
                  R1                  XS
9nUSSS24   n	U(       a.  [        R2                  " U	[        R4                  " USS 5      5      n	[        R                  " X	5        [        U5      S:  a  [7        US   R7                  5       S5      n
U
$ [        R                  n
U
$ s  snf )z2
Project the points according to renderer matrix.
r   c              3   `   #    U  H$  n[         R                  R                  U5      v   M&     g 7fr   )r%   rn   isMA).0segments     r   	<genexpr>4Line3DCollection.do_3d_projection.<locals>.<genexpr>  s      ?h7255::g&&hs   ,.r   F.r   .r   .rZ   .r#   r   rZ   Nr   )r   r(   setrm   r%   rn   r   
asanyarraysizer   r   rq   r  r9   nomaskrB   r8   r   newaxisr   rg   r:   r   _scale_proj_transform_vectorsr&   splitcumsumr   )rN   r   r  segment_lengthsraggedr9   r   viewlim_maskxyzssegments_2dminzs              r   r   !Line3DCollection.do_3d_projection  s    ## 8@@xG3w<x@S)*Q.?h???55,,X6>>(3}}X.H ==A''b166M55::hHMM$E==D(&)9)1&)9)1&)9)-4
 66*BOOJsBJJ$?$:j&6&6$:$:< <D (&)9)1&)9)1&)9)-4L vvl##!|CO/L/G1C1C/GQ/G I*33HiiHu55;;t;/D3!8n((;		/#2:N0OPK##D6 t9q=tF|'')3/D  66Di As   L)rg   r   r   rd   F)r   r   r   r   r   rL   r   r   r   r   r   r   s   @r   r   r     s!    8
!; ;r   r   c                 |    [        U R                  5       X5      n[        U l        U R	                  U5        X0l        g)z<Convert a `.LineCollection` to a `.Line3DCollection` object.N)r   r   r   r`   r   rg   )r   r7   r*   rO   
segments3ds        r   line_collection_2d_to_3dr  N  s.    &s}}AJ$CMZ  Or   c                   N   ^  \ rS rSrSrSSSS.U 4S jjrSS jrS	 rS
 rSr	U =r
$ )Patch3DiV  z
3D patch object.
r   r"   Fr7   r*   rO   c                J   > [         TU ]  " U0 UD6  U R                  XU5        g)a  
Parameters
----------
verts :
zs : float
    The location along the *zdir* axis in 3D space to position the
    patch.
zdir : {'x', 'y', 'z'}
    Plane to plot patch orthogonal to. Default: 'z'.
    See `.get_dir_vector` for a description of the values.
axlim_clip : bool, default: False
    Whether to hide patches with a vertex outside the axes view limits.

    .. versionadded:: 3.10
N)r[   rL   rM   )rN   r7   r*   rO   r   rP   r`   s         r   rL   Patch3D.__init__[  s'      	$)&)r4r   c                     [         R                  " U[        U5      5      n[        X5       VVVs/ s H  u  u  pVn[	        XVXs5      PM     snnnU l        X@l        gs  snnnf )a  
Set the *z* position and direction of the patch.

Parameters
----------
verts :
zs : float
    The location along the *zdir* axis in 3D space to position the
    patch.
zdir : {'x', 'y', 'z'}
    Plane to plot patch orthogonal to. Default: 'z'.
    See `.get_dir_vector` for a description of the values.
axlim_clip : bool, default: False
    Whether to hide patches with a vertex outside the axes view limits.

    .. versionadded:: 3.10
N)r%   r   r(   r   r   
_segment3drg   )rN   vertsr7   r*   rO   r    r!   r"   s           r   rM   Patch3D.set_3d_propertiesn  sS    $ __RU,.1%n>.<{ 'qQ5.<>%>s   Ac                     [        U S5      (       d9  U R                  R                  5       U R                  l        U R	                  5         U R
                  $ )N_path2d)hasattrr8   get_projMr   r(  rV   s    r   get_pathPatch3D.get_path  s?     tY'')),,.DIIK!!#||r   c                 R   U R                   n[        U6 u  p#n[        X#X@R                  5      nU R                  (       a  U[        X#X@R                  5      -  n[        R                  " U5      (       aJ  [        R                  R                  [        U6 [        US9R                  [        R                  5      u  pgnOX#Upn[        R                  " XgXR                  5      u  pp[        R                   " [        R                  R#                  X/5      5      U l        ['        U5      $ Nr   )r$  r   rB   r8   rg   r:   r%   rm   rn   r&   ro   rp   rq   r   r   r   r   r   r(  r   rN   sxs0ys0zs0r9   r5   r6   r7   vxsvysvzsviss                r   r   Patch3D.do_3d_projection  s    OOQ#"3S))<M#C;;D66$<<S!W+0t % ==CVBFF^ BB 3BB#>>rr99U#zz"%%"4"4cZ"@A3xr   )rg   r(  r$  r   )r   r   r   r   r   rL   rM   r,  r   r   r   r   s   @r   r  r  V  s/     "$#% 5 5&&. r   r  c                   :    \ rS rSrSrSSSS.S jrSS jrS	 rS
rg)PathPatch3Di  z
3D PathPatch object.
r   r"   Fr   c                V    [         R                  " U 40 UD6  U R                  XX45        g)a  
Parameters
----------
path :
zs : float
    The location along the *zdir* axis in 3D space to position the
    path patch.
zdir : {'x', 'y', 'z', 3-tuple}
    Plane to plot path patch orthogonal to. Default: 'z'.
    See `.get_dir_vector` for a description of the values.
axlim_clip : bool, default: False
    Whether to hide path patches with a point outside the axes view limits.

    .. versionadded:: 3.10
N)r   rL   rM   )rN   r
   r7   r*   rO   rP   s         r   rL   PathPatch3D.__init__  s%    " 	t&v&t:r   c                 d    [         R                  XR                  X#US9  UR                  U l        g)a  
Set the *z* position and direction of the path patch.

Parameters
----------
path :
zs : float
    The location along the *zdir* axis in 3D space to position the
    path patch.
zdir : {'x', 'y', 'z', 3-tuple}
    Plane to plot path patch orthogonal to. Default: 'z'.
    See `.get_dir_vector` for a description of the values.
axlim_clip : bool, default: False
    Whether to hide path patches with a point outside the axes view limits.

    .. versionadded:: 3.10
r   N)r  rM   r   r   _code3d)rN   r
   r7   r*   rO   s        r   rM   PathPatch3D.set_3d_properties  s-    $ 	!!$"-7 	" 	9zzr   c                 h   U R                   n[        U6 u  p#n[        X#X@R                  5      nU R                  (       a  U[        X#X@R                  5      -  n[        R                  " U5      (       aJ  [        R                  R                  [        U6 [        US9R                  [        R                  5      u  pgnOX#Upn[        R                  " XgXR                  5      u  pp[        R                   " [        R                  R#                  X/5      U R$                  5      U l        [)        U5      $ r/  )r$  r   rB   r8   rg   r:   r%   rm   rn   r&   ro   rp   rq   r   r   r   r   r   r?  r(  r   r0  s                r   r   PathPatch3D.do_3d_projection  s    OOQ#"3S))<M#C;;D66$<<S!W+0t % ==CVBFF^ BB 3BB#>>rr99U#zz"%%"4"4cZ"@$,,O3xr   )r?  r(  Nr   )	r   r   r   r   r   rL   rM   r   r   r   r   r   r;  r;    s     $&CE ;(",r   r;  c                     U R                  5       nU R                  5       nUR                  U5      n[        U5      (       a  US   $ [        R
                  " / 5      $ )z2Return a list of vertices for the path of a patch.r   )get_patch_transformr,  to_polygonsr(   r%   r&   )patchtransr
   polygonss       r   _get_patch_vertsrI    sK    %%'E>>D&Hh--8A;9RXXb\9r   c                 T    [        U 5      n[        U l        U R                  XAX#5        g)z*Convert a `.Patch` to a `.Patch3D` object.N)rI  r  r`   rM   )rF  r"   r*   rO   r%  s        r   patch_2d_to_3drK    s#    U#EEO	Ed7r   c                     U R                  5       nU R                  5       nUR                  U5      n[        U l        U R                  XQU5        g)z2Convert a `.PathPatch` to a `.PathPatch3D` object.N)r,  rD  transform_pathr;  r`   rM   )	pathpatchr"   r*   r
   rG  r   s         r   pathpatch_2d_to_3drO    sF    D))+E  &E%I$/r   c                      ^  \ rS rSrSrSSSSSS.U 4S jjrS	 r SS
 jrS rSS jr	U 4S jr
S rU 4S jrU 4S jrSrU =r$ )Patch3DCollectioni  z
A collection of 3D patches.
r   r"   NFr7   r*   
depthshadedepthshade_minalpharO   c                   > Uc	  [         S   nUc	  [         S   nX0l        X@l        [        TU ]  " U0 UD6  U R                  XU5        g)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.

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.

*depthshade_minalpha* sets the minimum alpha value applied by
depth-shading.
Naxes3d.depthshadeaxes3d.depthshade_minalpha)r   _depthshade_depthshade_minalphar[   rL   rM   	rN   r7   r*   rS  rT  rO   r   rP   r`   s	           r   rL   Patch3DCollection.__init__  sV    8 !"56J&"*+G"H%$7!$)&)r4r   c                     U R                   $ r   rX  rV   s    r   get_depthshade Patch3DCollection.get_depthshade      r   c                 B    Uc	  [         S   nXl        X l        SU l        g)aR  
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.
depthshade_minalpha : float, default: :rc:`axes3d.depthshade_minalpha`
    Sets the minimum alpha value used by depth-shading.

    .. versionadded:: 3.11
NrW  Tr   rX  rY  rd   rN   rS  rT  s      r   set_depthshade Patch3DCollection.set_depthshade"  )    $ &"*+G"H%$7!
r   c                     Xl         SU l        gr   r   r   s     r   r   Patch3DCollection.set_sort_zpos:  r   r   c                    U R                  5         U R                  5       n[        U5      S:  a  UR                  u  pVO/ n/ n[	        XV[
        R                  " U5      U5      U l        [        S5      U l	        SU l
        X0l        SU l        g)a  
Set the *z* positions and direction of the patches.

Parameters
----------
zs : float or array of floats
    The location or locations to place the patches in the collection
    along the *zdir* axis.
zdir : {'x', 'y', 'z'}
    Plane to plot patches orthogonal to.
    All patches must have the same direction.
    See `.get_dir_vector` for a description of the values.
axlim_clip : bool, default: False
    Whether to hide patches with a vertex outside the axes view limits.

    .. versionadded:: 3.10
r   r
  NT)update_scalarmappableget_offsetsr(   r   r   r%   
atleast_1d
_offsets3dslice_z_markers_idx_vzsrg   rd   rN   r7   r*   rO   offsetsr5   r6   s          r   rM   #Patch3DCollection.set_3d_properties?  sz    ( 	""$""$w<!YYFBBB%bbmmB.?F#Bi	%
r   c                   > [        / U R                  QU R                  P76 nU R                  (       a$  U[	        / U R                  QU R                  P76 -  n[
        R                  " U5      (       a,  [
        R                  R                  U R                  US9u  p#nOU R                  u  p#n[        R                  " X#X@R                  5      u  pVpxXpl        [
        R                  R                  U5      (       a.  [        T	U ]9  [
        R                  R                  XV/5      5        O$[        T	U ]9  [
        R                  " XV/5      5        UR                   S:  a  [#        U5      $ [
        R$                  $ )Nr   r   )rB   rm  r8   rg   r:   r%   rm   rn   r&   r   r   rp  r  r[   set_offsetsr   r  r   rq   )
rN   r9   r5   r6   r7   r5  r6  r7  r8  r`   s
            r   r   "Patch3DCollection.do_3d_projection`  s   "?DOO?TYY?M>4??>DII>>D66$<<T__4@JBBJBB#>>rr99U#	55::c??G 2 2C: >?G
 ;<88a<s8O66Mr   c                    U R                   nU R                  bQ  U R                  (       a@  [        UU R                  U R                  S9nUb  UR
                  S   S:X  a  X!S S 2S4   -  n[        U5      S:  aK  XR                     n[        R                  " U5      S:  a#  [        R                  " U5      U R                     n[        R                  " X5      $ )N)	min_alphar      r#   r   )_alpharp  rX  _zalpharY  r   r(   ro  r%   ndimrr   mcolorsto_rgba_arrayrN   color_arrayalphas      r   "_maybe_depth_shade_and_sort_colors4Patch3DCollection._maybe_depth_shade_and_sort_colorst  s     99 T%5%5!		33K
  [%6%6q%9Q%>AqD 11 {a%&9&9:Kwwu~!

5)$*=*=>$$[88r   c                 >   > U R                  [        TU ]	  5       5      $ r   r  r[   get_facecolorrN   r`   s    r   r  Patch3DCollection.get_facecolor      66uw7L7NOOr   c                    > [         R                  " U R                  S5      (       a  U R                  5       $ U R	                  [
        TU ]  5       5      $ Nfacer   r$   _edgecolorsr  r  r[   get_edgecolorr  s    r   r  Patch3DCollection.get_edgecolor  F     D,,f55%%''66uw7L7NOOr   )rg   rX  rY  rm  r   rp  ro  rd   r   r  )r   r   r   r   r   rL   r^  rd  r   rM   r   r  r  r  r   r   r   s   @r   rQ  rQ    sZ      #5 #5J  !0
B(9,PP Pr   rQ  c                 \   [         R                  R                  U 5      (       d  gU R                  5       U R	                  5       -
  nUR                  5       UR	                  5       -
  nUR                  5       UR	                  5       -
  n[         R
                  " US-  US-  -   US-  -   5      $ )z
Estimate the scale of the 3D data for use in depth shading

Parameters
----------
X, Y, Z : masked arrays
    The data to estimate the scale of.
r   rZ   )r%   rn   countmaxr   sqrt)XYZptp_xptp_yptp_zs         r   _get_data_scaler    s     55;;q>>
 EEGaeegEEEGaeegEEEGaeegE775A:
*UaZ788r   c                      ^  \ rS rSrSrSSSSSS.U 4S jjrU 4S	 jrS
 rSS jrSU 4S jjr	U 4S jr
S r SS jrS r\U 4S j5       rS rU 4S jrU 4S jrSrU =r$ )Path3DCollectioni  z
A collection of 3D paths.
r   r"   NFrR  c                   > Uc	  [         S   nUc	  [         S   nX0l        X@l        SU l        [        TU ]  " U0 UD6  U R                  XU5        SU l        g)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.

*depthshade_minalpha* sets the minimum alpha value applied by
depth-shading.
NrV  rW  F)r   rX  rY  _in_drawr[   rL   rM   _offset_zorderedrZ  s	           r   rL   Path3DCollection.__init__  se    8 !"56J&"*+G"H%$7!$)&)r4 $r   c                    > U R                  5          [        R                  " U SS9   [        TU ]  U5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)NT)r  )_use_zordered_offsetr   rw   r[   rx   )rN   ry   r`   s     r   rx   Path3DCollection.draw  sH    &&(""4$7X& 8 )(77 )(s!   AA	A	
A	A
A(c                     Xl         SU l        gr   r   r   s     r   r   Path3DCollection.set_sort_zpos  r   r   c                    U R                  5         U R                  5       n[        U5      S:  a  UR                  u  pVO/ n/ nX l        [        XV[        R                  " U5      U5      U l        U R                  U l
        [        R                  " U R                  5      U l        U R                  u  pVn[        S5      U l        SU l        X0l        SU l        g)a  
Set the *z* positions and direction of the paths.

Parameters
----------
zs : float or array of floats
    The location or locations to place the paths in the collection
    along the *zdir* axis.
zdir : {'x', 'y', 'z'}
    Plane to plot paths orthogonal to.
    All paths must have the same direction.
    See `.get_dir_vector` for a description of the values.
axlim_clip : bool, default: False
    Whether to hide paths with a vertex outside the axes view limits.

    .. versionadded:: 3.10
r   r
  NT)rj  rk  r(   r   _zdirr   r%   rl  rm  _sizes_sizes3dr&   _linewidths_linewidths3drn  ro  rp  rg   rd   rq  s          r   rM   "Path3DCollection.set_3d_properties  s    ( 	""$""$w<!YYFBBB
%bbmmB.?F XXd&6&67__

 $Bi	%
r   c                 T   > [         TU ]  X5        U R                  (       d  Xl        g g r   )r[   	set_sizesr  r  )rN   sizesdpir`   s      r   r  Path3DCollection.set_sizes  s!    %%}}!M r   c                    > [         TU ]  U5        U R                  (       d&  [        R                  " U R
                  5      U l        g g r   )r[   set_linewidthr  r%   r&   r  r  )rN   lwr`   s     r   r  Path3DCollection.set_linewidth  s3    b!}}!#$*:*:!;D r   c                     U R                   $ r   r]  rV   s    r   r^  Path3DCollection.get_depthshade!  r`  r   c                 B    Uc	  [         S   nXl        X l        SU l        g)a'  
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.
depthshade_minalpha : float
    Sets the minimum alpha value used by depth-shading.

    .. versionadded:: 3.11
NrW  Trb  rc  s      r   rd  Path3DCollection.set_depthshade$  rf  r   c                 ,   SnU R                    H7  n[        R                  R                  U5      (       d  M)  XR                  -  nM9     U[        / U R                   QU R                  P76 -  nU R                  (       a$  U[        / U R                   QU R                  P76 -  n[        R                  " U5      (       an  [        R                  " U[        U R                   5      /U R                   S   R                  Q75      n[        R                  R                  U R                   US9nOU R                   n[        R                  " / UQU R                  P76 u  pEpg[!        XEU5      U l        [        R                  R%                  U5      S S S2   =ol        X`l        [        U R*                  5      S:  a  U R*                  U   U l        [        U R.                  5      S:  a  U R.                  U   U l        [2        R4                  " U [        R                  R7                  XE45      5        Xh   nXH   nXX   n[        R                  R7                  XE45      U l        UR:                  (       a  [        R<                  " U5      $ [        R>                  $ )NFr   r   r
  r   ) rm  r%   rn   r  r9   rB   r8   rg   r:   rm   r   r(   r   r&   r   r   r  _data_scaleargsortro  rp  r  r  r  r  r   ru  r   r  r  r   rq   )	rN   r9   r_   r  r5  r6  r7  r8  z_markers_idxs	            r   r   !Path3DCollection.do_3d_projection<  s   ??Cuuzz#hh # )F4??FDIIFF-DD$))DDD66$<<??4$'$8#T4??1;M;S;S#TVD55;;tT;:D??D#>>PPdiiP#*3S9 /1eemmC.@2.FF+	 t}}!--6DKt!!"Q&#11-@D""4););SJ)GH     !# 2 2C: >!hhrvvc{2BFF2r   c              #      >#    U R                   c  S v   g U R                  n[        TU ]  U R                   5         S v   Xl        g ! Xl        f = f7fr   )r  _offsetsr[   ru  )rN   
old_offsetr`   s     r   r  %Path3DCollection._use_zordered_offseti  sE       ( JG 5 56+ *
s   8AA  AAAc                    U R                   nU R                  b\  U R                  (       aK  [        UU R                  U R                  U R
                  S9nUb  UR                  S   S:X  a  X!S S 2S4   -  n[        U5      S:  aK  XR                     n[        R                  " U5      S:  a#  [        R                  " U5      U R                     n[        R                  " X5      $ )N)rx  r  r   ry  r#   r   )rz  rp  rX  r{  rY  r  r   r(   ro  r%   r|  rr   r}  r~  r  s      r   r  3Path3DCollection._maybe_depth_shade_and_sort_colorsw  s     99 T%5%5!		33 ,,	K  [%6%6q%9Q%>AqD 11 {a%&9&9:Kwwu~!

5)$*=*=>$$[88r   c                 >   > U R                  [        TU ]	  5       5      $ r   r  r  s    r   r  Path3DCollection.get_facecolor  r  r   c                    > [         R                  " U R                  S5      (       a  U R                  5       $ U R	                  [
        TU ]  5       5      $ r  r  r  s    r   r  Path3DCollection.get_edgecolor  r  r   )rg   r  rX  rY  r  r  r  r  r  rm  r  r  r   rp  ro  r  rd   r  )g      R@r   )r   r   r   r   r   rL   rx   r   rM   r  r  r^  rd  r   r   r  r  r  r  r   r   r   s   @r   r  r    s~      %% %%N'

2h"
<
  !0+3Z + +9.PP Pr   r  )rT  c                   [        U [        5      (       a  [        U l        SU l        O [        U [
        5      (       a  [        U l        Uc	  [        S   nUc	  [        S   nX0l        XPl	        SU l
        U R                  XU5        g)a  
Convert a `.PatchCollection` into a `.Patch3DCollection` object
(or a `.PathCollection` into a `.Path3DCollection` object).

Parameters
----------
col : `~matplotlib.collections.PatchCollection` or `~matplotlib.collections.PathCollection`
    The collection to convert.
zs : float or array of floats
    The location or locations to place the patches in the collection along
    the *zdir* axis. Default: 0.
zdir : {'x', 'y', 'z'}
    The axis in which to place the patches. Default: "z".
    See `.get_dir_vector` for a description of the values.
depthshade : bool, default: :rc:`axes3d.depthshade`
    Whether to shade the patches to give a sense of depth.
axlim_clip : bool, default: False
    Whether to hide patches with a vertex outside the axes view limits.

    .. versionadded:: 3.10

depthshade_minalpha : float, default: :rc:`axes3d.depthshade_minalpha`
    Sets the minimum alpha value used by depth-shading.

    .. versionadded:: 3.11
NrV  rW  F)
isinstancer   r  r`   r  r   rQ  r   rX  rY  r  rM   )r   r7   r*   rS  rO   rT  r   s          r   patch_collection_2d_to_3dr    sz    H #~&&(#	C	)	))12
"&'CD O2CL"J/r   c                     ^  \ rS rSrSrSSSSS.U 4S jjr\R                  \R                  \R                  S.r
S	 r\R                  " S
5      S 5       rS rSU 4S jjrS rSS jrS rS rU 4S jrU 4S jrS rS rS rSrU =r$ )Poly3DCollectioni  a  
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.
averageFN)zsortshadelightsourcerO   c                  > U(       ad  [        U5      nUR                  SS5      n	U	b  [        XU5      US'   UR                  SS5      n
U
b  [        XU5      US'   U	c  U
c  [        S5      e[        TU ]  " U/UQ70 UD6  [        U[        R                  5      (       a  UR                  S:w  a  [        S5      eO"[        S U 5       5      (       a  [        S5      eU R                  U5        SU l        XPl        g)a  
Parameters
----------
verts : list of (N, 3) 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 (N, 3).
zsort : {'average', 'min', 'max'}, default: 'average'
    The calculation method for the z-order.
    See `~.Poly3DCollection.set_zsort` for details.
shade : bool, default: False
    Whether to shade *facecolors* and *edgecolors*. When activating
    *shade*, *facecolors* and/or *edgecolors* must be provided.

    .. versionadded:: 3.7

lightsource : `~matplotlib.colors.LightSource`, optional
    The lightsource to use when *shade* is True.

    .. versionadded:: 3.7

axlim_clip : bool, default: False
    Whether to hide polygons with a vertex outside the view limits.

    .. versionadded:: 3.10

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

facecolorsN
edgecolorszCYou must provide facecolors, edgecolors, or both for shade to work.r#   z)verts must be a list of (N, 3) array-likec              3   f   #    U  H'  n[        [        R                  " U5      5      S :g  v   M)     g7f)rZ   N)r(   r%   r   )r  verts     r   r  ,Poly3DCollection.__init__.<locals>.<genexpr>  s"     >3rxx~&!+s   /1)_generate_normalsget_shade_colorsr)   r[   rL   r  r%   ndarrayr|  rm   	set_zsort_codes3drg   )rN   r%  r  r  r  rO   r   rP   normalsr  r  r`   s              r   rL   Poly3DCollection.__init__  s   H '.GL$7J%'4(|$  L$7J%'4(|$ !j&8 %& & 	000eRZZ((zzQ !LMM  >>>> !LMMu%r   )r  r   r  c                 H    U R                   U   U l        SU l        SU l        g)z
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   rd   )rN   r  s     r   r  Poly3DCollection.set_zsort(  s$     //6
r   z3.10c                 $    U R                  U5      $ r   )_get_vector)rN   r  s     r   
get_vectorPoly3DCollection.get_vector6  s    
++r   c                    [        U[        R                  5      (       a|  [        R                  " SUS9  [        U[        R
                  R                  5      (       a0  UR                  U l        UR                  R                  SS9U l        g
Xl        SU l        g
[        U5      n[        R                  " [        [        U5      [        R                  S9nUR!                  SS9n[        R"                  " X$S	45      n[%        U5       H  u  pgXuUS
[        U5      24'   M     XPl        [        R&                  " U5      US
S
2S
4   :  U l        g
)a&  
Optimize points for projection.

Parameters
----------
segments3d : NumPy array or list of NumPy arrays
    List of vertices of the boundary of every segment. If all paths are
    of equal length and this argument is a NumPy array, then it should
    be of shape (num_faces, num_vertices, 3).
)NNr#   )r  r
  axisFrk   r   )initialr#   N)r  r%   r  r   check_shapern   MaskedArraydata_facesr9   rm   _invalid_verticesr(   fromitermapintpr  empty	enumeratearange)rN   r  	num_faces	num_verts	max_vertsr   ir  s           r   r  Poly3DCollection._get_vector:  s     j"**--_D*bee&7&788(oo)3)<)<")<)E&().& JICZ$8HI!a0Ixxq 9:H$Z0*.JSYJ' 1"K%'YYy%9Yq$w=O%OD"r   c                 T   > U R                  U5        [        TU ]	  / S5        X l        g)af  
Set 3D vertices.

Parameters
----------
verts : list of (N, 3) 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 (N, 3).
closed : bool, default: True
    Whether the polygon should be closed by adding a CLOSEPOLY
    connection at the end.
FN)r  r[   	set_verts_closed)rN   r%  closedr`   s      r   r  Poly3DCollection.set_vertsY  s'     	"e$r   c                 0    U R                  USS9  X l        g)z Set 3D vertices with path codes.F)r  N)r  r  )rN   r%  r   s      r   set_verts_and_codes$Poly3DCollection.set_verts_and_codesl  s     	uU+r   c                    U R                  5         S U l        U R                  S5        [        R                  " U 5      U l        [        R                  " U 5      U l        [        R                  " U 5      U l	        SU l
        g )Nr  T)rj  r   r  r   r  _facecolor3dr  _edgecolor3d	get_alpha_alpha3drd   )rN   rO   s     r   rM   "Poly3DCollection.set_3d_propertiest  sb     	""$y!*88>*88>&006
r   c                     Xl         SU l        gr   r   r   s     r   r   Poly3DCollection.set_sort_zpos  r   r   c                 	   U R                   bT  U R                  5         U R                  (       a  U R                  U l        U R
                  (       a  U R                  U l        [        U R                  5      nU R                  [        U R                  S   U R                  S   U R                  S   U R                  5      -  n[        R                  " U5      n[        R                  " SSS9   [         R"                  " U R                  U R                  5      nSSS5        U R$                  (       a`  ['        U R                  S   U R                  S   U R                  S   U R                  5      n[        R                  " U5      (       a  SnX%-  nWS   nU(       a  [        R(                  R+                  XbS9nU R                  nU R                  n[        U5      U:w  a  UR-                  US	S
9n[        U5      U:w  a"  [        U5      S	:X  a  UnOUR-                  US	S
9n[        U5      S	:  a  U R/                  USS
9n	OUn	U(       a  U	R0                  n	[        R2                  " U	SS
9SSS2   n
[        U5      S	:  a  XJSS2SS24   nOUnU R4                  b  [        U R4                  5      S	:  ak  U(       a.  X*SS24   ) n[7        X5       VVs/ s H  u  pXSS24   PM     nnnU
 Vs/ s H  oR4                  U   PM     nn[8        R:                  " XU5        O}U(       aU  [        U5      S	:  aF  [        R<                  " X*SS2S4   UR>                  5      n[        R(                  R+                  UUS9n[8        R@                  " XU RB                  5        [        U5      S	:  a
  Xz   U l"        OXpl"        [        U R                  5      [        U5      :X  a  [        U5      S	:  a
  X   U l#        OU R                  U l#        U RH                  b[  [        RJ                  " S	/S	/U RH                  /S//5      n[         RL                  " UU R                  RN                  5      nUS   S	   $ URP                  S	:  a  [        RR                  " U5      $ [        RT                  $ ! , (       d  f       GN= fs  snnf s  snf )z,
Perform the 3D projection for this object.
Nr  r  r	  ignore)invaliddivideTr   r   r  r
  rZ   r   )+_Arj  _face_is_mapped_facecolorsr  _edge_is_mappedr  r  r(   r  r  rB   r8   r%   rm   errstater   r  rg   r:   rn   r  repeatr  r  r  r  r   r   r  r   r   r  r   _facecolors2d_edgecolors2dr   r&   _proj_transform_vecr+  r  r   rq   )rN   r  r9   needs_maskingpfacesr  pzscfacecedgeface_z
face_orderfaces_2dsegment_maskr  idxr   invalid_vertices_2dzvecztranss                      r   r   !Poly3DCollection.do_3d_projection  s    77 &&(##$($4$4!##$($4$4!$	%%(;KKV!4KK), , t [[(;99$++tyyQF < (V)<dkk&>Q)-V)<diiILvvl## $*Vn%%##C#3C !!!!u:"LLL3Eu:"5zQYQ7s8a<__Sr_2FF[[FZZR026
v;?!RaR/0HH==$T]]);a)? $] 33"%h"=?"= /9dDqM"=  ?3=>:C]]3':E>..tuEX!2&(ooQ,-NN'$# 55,, ': - <$$TT\\Bu:>!&!2D!&t  !SZ/CJN!&!2D!%!2!2D ??&88aS1#'81#>?D//diikkBF!9Q<XX\ 66#;66MS <;P?>s   .,R(R:0S (
R7c                 Z   > [         TU ]  U5        [        R                  " U 5      U l        g r   )r[   set_facecolorr   r  r  rN   r   r`   s     r   r*  Poly3DCollection.set_facecolor  #    f%*88>r   c                 Z   > [         TU ]  U5        [        R                  " U 5      U l        g r   )r[   set_edgecolorr   r  r  r+  s     r   r/  Poly3DCollection.set_edgecolor  r-  r   c                    [         R                  R                  X5         [        R                  " U R
                  U R                  5      U l         [        R                  " U R                  U R                  5      U l        SU l        g ! [        [        [        4 a     NPf = f! [        [        [        4 a     N:f = f)NT)r   Artist	set_alphar}  r~  r  rz  AttributeError	TypeError
IndexErrorr  r  rd   )rN   r  s     r   r3  Poly3DCollection.set_alpha  s    ,	 ' 5 5!!4;;!0D	&44%%t{{ 4D 
 	:6 		
 	:6 		s#   0B
 0B% 
B"!B"%B=<B=c                     [        U S5      (       d9  U R                  R                  5       U R                  l        U R	                  5         [
        R                  " U R                  5      $ )Nr  )r)  r8   r*  r+  r   r%   rr   r  rV   s    r   r  Poly3DCollection.get_facecolor  J     t_--)),,.DIIK!!#zz$,,--r   c                     [        U S5      (       d9  U R                  R                  5       U R                  l        U R	                  5         [
        R                  " U R                  5      $ )Nr  )r)  r8   r*  r+  r   r%   rr   r  rV   s    r   r  Poly3DCollection.get_edgecolor
  r:  r   )r
  rg   r   r  r  r  r  r  r  r  r  r   r  rd   )Tr  )r   r   r   r   r   rL   r%   r  r   r  r  r  r   
deprecatedr  r  r  r  rM   r   r   r*  r/  r3  r  r  r   r   r   s   @r   r  r    s    ( ,5E!e>& >&B ::vvvv 
__V, ,P>&	
cJ?
?
.. .r   r  c                     [        U R                  5       X5      u  pE[        U l        U R	                  XE5        U R                  5         X0l        g)a  
Convert a `.PolyCollection` into a `.Poly3DCollection` object.

Parameters
----------
col : `~matplotlib.collections.PolyCollection`
    The collection to convert.
zs : float or array of floats
    The location or locations to place the polygons in the collection along
    the *zdir* axis. Default: 0.
zdir : {'x', 'y', 'z'}
    The axis in which to place the patches. Default: 'z'.
    See `.get_dir_vector` for a description of the values.
N)r   r   r  r`   r  rM   rg   )r   r7   r*   rO   segments_3dr   s         r   poly_collection_2d_to_3dr@    sB     :MMOR'K$CMK/ Or   c                 \    US:X  a  X U4$ US:X  a  XU4$ US   S:X  a  [        XX#5      $ XU4$ )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r5   r6   r7   r*   s       r   r   r   *  sH     s{rz	rz	aC22,,rzr   c                 2    US;   a  XU 4$ US;   a  X U4$ XU4$ )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-y)z-xr!   r   rD  s       r   rC  rC  ;  s2     {rz		rzrzr   c                    [        U 5      S:X  d  [        U5      S:X  a  [        R                  " S5      $ [        R                  " USS5      nUb  US:X  a  [        R                  " U5      nO5[        R                  " SU[        R
                  " U5      -
  U-  -
  US5      n[        R                  " [        R                  " U 5      [        U5      S45      n[        R                  " USS2SS24   USS2S4   U-  /5      $ )z?Modify the alpha values of the color list according to z-depth.r   )r   ry  r   Nry  r#   )
r(   r%   zerosclip	ones_liker   r   r}  r~  r   )r   r7   rx  r  satsrgbas         r   r{  r{  I  s     6{a3r7a<xx 	1a(IkQ.||B wwqBO{::IqI??70083r7A,GD ??DBQBKadd):;<<r   c                 $   [         R                  " U 5      [         R                  " U5      [         R                  " U5      p!n [         R                  " XU/5      nU[         R                  " U5      R	                  SS9)    n[         R
                  " USS9n[        U5      S::  a  gXDS   -
  SS nU[         R                  R                  USS9SS2[         R                  4   -  n[         R
                  " USS9n[        U5      S::  a  g[         R                  R                  [         R                  " US   USS 5      SS9n[         R                  " [         R                  " USUS95      S   S-   n[         R                  " XWSS9n[        U5      S::  a  g[         R                  " US   US   5      nU[         R                  R                  U5      -  n[         R                  " XR                  5       5      n	[         R                   " U	SUS9$ )	z
Check if all points are on the same plane. Note that NaN values are
ignored.

Parameters
----------
xs, ys, zs : array-like
    The x, y, and z coordinates of the points.
atol : float, default: 1e-8
    The tolerance for the equality check.
r   r  r   r#   TNrZ   )atol)r%   rr   r   isnanrm   uniquer(   linalgnormr  crosswhereisclosedeletedot	transposeallclose)
r5   r6   r7   rM  r|   r   cross_normszero_cross_normsndotss
             r   _all_points_on_planer]  e  s    BBBBB__bb\*FRXXf%))q)112FYYvA&F
6{a
!9
ab	!B	biinnRan(BJJ7	7B	2A	B
2w!|)).."Q%AB!8q.AKxx

; EFqIAM	2a	0B
2w!|
A1A	BIINN1A 66!\\^$D;;tQT**r   c                 b   [        U [        R                  5      (       aH  U R                  S   nSUS-  SU-  S-  pCnU SUSS24   U SUSS24   -
  nU SUSS24   U SUSS24   -
  nO[        R                  " [        U 5      S45      n[        R                  " [        U 5      S45      n[        U 5       Hb  u  px[        U5      n[        R                  " U5      nSUS-  SU-  S-  pCnXSS24   XSS24   -
  XWSS24'   XSS24   XSS24   -
  XgSS24'   Md     [        R                  " XV5      $ )a  
Compute the normals of a list of polygons, one normal per polygon.

Normals point towards the viewer for a face with its vertices in
counterclockwise order, following the right hand rule.

Uses three points equally spaced around the polygon. This method assumes
that the points are in a plane. Otherwise, more than one shade is required,
which is not supported.

Parameters
----------
polygons : list of (M_i, 3) array-like, or (..., M, 3) array-like
    A sequence of polygons to compute normals for, which can have
    varying numbers of vertices. If the polygons all have the same
    number of vertices and array is passed, then the operation will
    be vectorized.

Returns
-------
normals : (..., 3) array
    A normal vector estimated for the polygon.
r   r#   rZ   .N)	r  r%   r  r   r  r(   r  rr   rR  )	rH  r[  i1i2i3v1v2poly_ipss	            r   r  r    s3   0 (BJJ'' NN21ac1fc2qj!HS"aZ$88c2qj!HS"aZ$88 XXs8}a()XXs8}a()#H-JFBABBAqD!A#q&BB1uIq5	1BqyM1uIq5	1BqyM . 88Br   c                   ^^	 Uc  [         R                  " SSS9n[        R                  " SS9   U[        R                  R                  USSS	9-  UR                  -  nSSS5        [        R                  " W5      ) nUR                  5       (       a  [         R                  " S
S5      m[         R                  " SS5      R                  m	UU	4S jnSX4) '   [         R                  " U 5      n U SS2S4   nU" U5      SS2[        R                  4   U -  nXgSS2S4'   U$ [        R                  " U 5      R                  5       nU$ ! , (       d  f       N= f)z
Shade *color* using normal vectors given by *normals*,
assuming a *lightsource* (using default position if not given).
*color* can also be an array of the same length as *normals*.
N   g-x3@)azdegaltdegr  )r  r   T)r  keepdimsr
  333333?c                     > T" T" U 5      5      $ r   r   )r    in_normout_norms    r   rQ  _shade_colors.<locals>.norm  s    GAJ''r   r   r#   )r}  LightSourcer%   r  rP  rQ  	directionrN  rm   	Normalizeinverser~  r  r  copy)
colorr  r  r  r9   rQ  r  r   rn  ro  s
           @@r   r  r    s#    ))GD	X	&BIINN7TNJJ(() 
' HHUODxxzz##B*$$S!,44	( e%%e, adeQ

]+e3q!t M u%**,M3 
'	&s   0E
Er   )r   r"   )r   r"   NF)rl  N)g:0yE>r   )@r   rt   numpyr%   
contextlibr   
matplotlibr   r   r   r   r}  r   r	   rJ   r
   r   r   matplotlib.collectionsr   r   r   r   r   matplotlib.patchesr   r   r   r   r   r+   r:   rB   rK   rD   r   Line2Dr   r   r   r   r   r   r   r   r   r  r  r;  rI  rK  rO  rQ  r  r  r  r  r@  r   rC  r{  r]  r  r  r   r   r   <module>r}     sf  

   %  Q Q $ OD2=0vUZZ vr/(kU\\ k\1*',: ,*
!g~ gT!De DN<' <~:80^P ^PB9.jP~ jP^ 		00 00fC.~ C.L
!."" 	=8&+R)X#r   