
    ht                     8   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  SSKJrJrJrJrJr  SSKJr  SSKJr  SS	KJr  S
 rS rS rS r  " S S\RB                  5      r"S3S jr# " S S\RH                  5      r%S3S jr&S4S jr'S4S jr(S4S jr)S4S jr* " S S\5      r+S3S jr, " S S\5      r-S3S jr. " S S\5      r/ " S  S!\/5      r0S" r1S3S# jr2S4S$ jr3 " S% S&\5      r4 " S' S(\5      r5S5S) jr6 " S* S+\5      r7S3S, jr8S- r9S. r:S/ r;S6S0 jr<S1 r=S7S2 jr>g)8zx
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)
CollectionLineCollectionPolyCollectionPatchCollectionPathCollection)	Normalize)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    L/var/www/html/env/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:X  a  [         R                  " S5      $ U S:X  a  [         R                  " S5      $ U S:X  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)nparrayiterablelen
ValueError)zdirs    r   get_dir_vectorr*   *   s    ( s{xx	""	xx	""	xx	""	xx	""	T		s4yA~xx~MNNr   c           	      
   [         R                  R                  XR                  R                  :  XR                  R
                  :  XR                  R                  :  XR                  R                  :  X#R                  R                  :  X#R                  R
                  :  45      n[         R                  R                  XS9n[         R                  R                  XS9n[         R                  R                  X$S9nXVU4$ )a  
Return original points with points outside the axes view limits masked.

Parameters
----------
xs, ys, zs : array-like
    The points to mask.
axes : Axes3D
    The axes to use for the view limits.

Returns
-------
xs_masked, ys_masked, zs_masked : np.ma.array
    The masked points.
)mask)r$   
logical_orreduce
xy_viewLimxminxmaxyminymax
zz_viewLimmar%   )xsyszsaxesr,   	xs_masked	ys_masked	zs_maskeds           r   _viewlim_maskr=   L   s      ==oo&:&:!:!#oo&:&:!:!#oo&:&:!:!#oo&:&:!:!#oo&:&:!:!#oo&:&:!:!< =D B*IB*IB*I**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$ )Text3Dh   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.

Other Parameters
----------------
**kwargs
     All other parameters are passed on to `~matplotlib.text.Text`.
c                 l    [         R                  R                  " XX$40 UD6  U R                  X5U5        g N)mtextText__init__set_3d_properties)selfr    r!   r"   r	   r)   
axlim_clipkwargss           r   rE   Text3D.__init__~   s+    

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rG   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)rG   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)rN   stale)rG   r"   s     r   rV   Text3D.set_z   s     
r   c                 J    Xl         [        U5      U l        X0l        SU l        g)aS  
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.
TN)rN   r*   rW   _axlim_clipr]   )rG   r"   r)   rH   s       r   rF   Text3D.set_3d_properties   s"     &t,%
r   c                    U R                   (       a  [        U R                  U R                  U R                  U R
                  5      u  p#n[        R                  R                  X#U45      R                  5       R                  [        R                  5      nO;U R                  U R                  U R                  pCn[        R                  " X#U/5      n[        R                  " XUU R                  -   /U R
                  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   [.        R0                  R3                  X5        S S S 5        SU l        g ! , (       d  f       N= f)Nr   r   )rL   rM   	_rotationF)r`   r=   rL   rM   rN   r9   r$   r5   	row_stackravelfillednan
asanyarrayr   _proj_trans_pointsrW   Mmathdegreesatan2r   _setattr_cmr   rC   rD   drawr]   )
rG   rendererr6   r7   r8   
position3dprojdxdyangles
             r   ro   Text3D.draw   sR   &tww$))LJBB""6<<>EEbffMJ$''477BB|4J((dmm34diikkC!WQZ$q'!*$!WQZ$q'!*$TZZ/0tQ
tAwqz)9%)@BJJOOD+B 
B Bs    F33
Gc                     g rB   r   )rG   rp   s     r   get_tightbboxText3D.get_tightbbox   s     r   )r`   rW   rN   r]   )r   r   r    r"   FrB   r   r"   F)__name__
__module____qualname____firstlineno____doc__rE   rP   rZ   rV   rF   r   allow_rasterizationro   rx   __static_attributes____classcell__rY   s   @r   r?   r?   h   sE    *4
)1"	&   $ r   r?   c                 >    [         U l        U R                  XU5        g)aL  
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.
N)r?   rY   rF   )objr"   r)   rH   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$ )Line3D   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)rH   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)rT   rE   set_data_3dr`   )rG   r6   r7   r8   rH   argsrI   rY   s          r   rE   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.
TN)	get_xdata	get_ydatar   _to_unmasked_float_arrayre   r$   broadcast_tor'   juggle_axes_verts3dr`   r]   )rG   r8   r)   rH   r6   r7   s         r   rF   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   rX   z must be a sequenceTN)r'   zipr$   r&   RuntimeErrorr   r]   )rG   r   namerX   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   rO   s    r   get_data_3dLine3D.get_data_3d.  s     }}r   c                 f  > U R                   (       a%  [        / U R                  QU R                  P76 u  p#nOU R                  u  p#n[        R
                  " X#UU R                  R                  U R                  R                  5      u  pVpxU R                  XV5        [        T	U ])  U5        SU l        g )NF)r`   r=   r   r9   r   _proj_transform_cliprj   _focal_lengthset_datarT   ro   r]   )
rG   rp   xs3dys3dzs3dr6   r7   r8   tisrY   s
            r   ro   Line3D.draw9  s    ,GdmmGTYYGD#}}D 55d$6:iikk6:ii6M6MO 	bX
r   )r`   r   r]   r{   )r|   r}   r~   r   r   rE   rF   r   r   r   r   ro   r   r   r   s   @r   r   r      s@     6; & &$.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.
N)r   rY   rF   )liner8   r)   rH   s       r   line_2d_to_3dr   G  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
   r8   r)   pathsegsr    r!   coder"   segseg3ds
             r   _path_to_3d_segmentr   Z  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   )pathsr8   r)   r
   pathzsegss         r   _paths_to_3d_segmentsr   d  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
   r8   r)   r   r    r!   r   r"   	seg_codesr   codesr   s               r   _path_to_3d_segment_with_codesr   r  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   r8   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                 P   U R                    VVs/ s H  u  pUPM	     nnnU R                  (       aX  U Vs/ s HK  n[        R                  R	                  [        / UR                  QU R                  P76 5      R                  PMM     nnU Vs/ s H9  n[        R                  " / UR                  QU R                  R                  P76 PM;     nn[        X@R                   5       VVVVs/ s H@  u  u  pVnu  p'[        R                  " [        R                  R                  XV/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f s  snnnnf s  snnf )z0Project the points according to renderer matrix.    eA)_3dverts_codesr`   r$   r5   rd   r=   Tr9   r   proj_transformrj   r   mpathPathcolumn_stack_pathsconcatenater'   min)	rG   vs_vs_list	xyzs_listr6   r7   csr8   s	            r   do_3d_projectionCollection3D.do_3d_projection  sG   #'#6#67#6%"2#67!(*!(2 uu}'Fbdd'FDII'FGII!(  *IPQ2V**>BDD>$))++>	Q36yBUBU3VX3V/;BA zz"%%"4"4bX">C3VX^^	:	HAqR	:;r77rvvx++ 8*QX:s   F
AFA F*AF
F"
)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   typerY   r`   )colr8   r)   rH   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 rB   )rT   rE   r`   )rG   r   rH   rI   rY   s       r   rE   Line3DCollection.__init__  s    )&)%r   c                     Xl         SU l        gz&Set the position to use for z-sorting.TN
_sort_zposr]   rG   vals     r   set_sort_zposLine3DCollection.set_sort_zpos      
r   c                 0   > Xl         [        TU ]	  / 5        g)z
Set 3D segments.
N)_segments3drT   set_segments)rG   r   rY   s     r   r   Line3DCollection.set_segments  s     $R r   c           	      "   U R                   nU R                  (       a  [        R                  R	                  U5      n[        R                  R                  / [        / UR                  QU R                  P76 Q5      nU Vs/ s H  n[        R                  " U5      S   PM     nn[        R                  " U[        R                  " USS 5      5      nU Vs/ s H-  n[        R                  " X`R                  R                  5      PM/     nnU VV	V
s/ s H&  u  pn
[        R                  R                  X/5      PM(     nn	nn
[        R                   " X5        SnU H  u  pn
[#        U[#        U
5      5      nM     U$ s  snf s  snf s  sn
n	nf )z2
Project the points according to renderer matrix.
r   Nr   )r   r`   r$   r5   vstackr   r=   r   r9   shapesplitcumsumr   ri   rj   r   r   r   )rG   r   
all_pointsmasked_pointssegmentsegment_lengthspointsxyslistr6   r7   r8   segments_2dminzs                r   r   !Line3DCollection.do_3d_projection  sP    ##h/JEE.. 0K 2J
 2J?Cyy2J 0K LMCKL8rxx038OLxxryy"9M/NOH!)+!)v ,,VYY[[A!) 	 +FMNg
ruu))2(3gN##D6 !JBBtSW%D " M+Ns   #F 4F-F
)r`   r   r   r]   F)r|   r}   r~   r   r   rE   r   r   r   r   r   r   s   @r   r   r     s!    &
! 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   rY   r   r`   )r   r8   r)   rH   
segments3ds        r   line_collection_2d_to_3dr    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
$ )Patch3Di  z
3D patch object.
r   r"   Fr8   r)   rH   c                J   > [         TU ]  " U0 UD6  U R                  XU5        g)ai  
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.
N)rT   rE   rF   )rG   r8   r)   rH   r   rI   rY   s         r   rE   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.
N)r$   r   r'   r   r   
_segment3dr`   )rG   vertsr8   r)   rH   r    r!   r"   s           r   rF   Patch3D.set_3d_properties  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)hasattrr9   get_projrj   r   r  rO   s    r   get_pathPatch3D.get_path  s?     tY'')),,.DIIK!!#||r   c                    U R                   nU R                  (       a!  [        / [        U6 QU R                  P76 u  p#nO[        U6 u  p#n[
        R                  " X#UU R                  R                  U R                  R                  5      u  pVpx[        R                  " [        R                  R                  XV/5      5      U l        [        U5      $ rB   )r	  r`   r=   r   r9   r   r   rj   r   r   r   r$   r5   r   r  r   	rG   sr6   r7   r8   vxsvysvzsviss	            r   r   Patch3D.do_3d_projection  s    OO&;Q;;JBBaJBB#889=9=9P9PR# zz"%%"4"4cZ"@A3xr   )r`   r  r	  r{   )r|   r}   r~   r   r   rE   rF   r  r   r   r   r   s   @r   r  r    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.
N)r   rE   rF   )rG   r
   r8   r)   rH   rI   s         r   rE   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.
r  N)r  rF   r   r   _code3d)rG   r
   r8   r)   rH   s        r   rF   PathPatch3D.set_3d_properties7  s-      	!!$"-7 	" 	9zzr   c                    U R                   nU R                  (       a!  [        / [        U6 QU R                  P76 u  p#nO[        U6 u  p#n[
        R                  " X#UU R                  R                  U R                  R                  5      u  pVpx[        R                  " [        R                  R                  XV/5      U R                  5      U l        [!        U5      $ rB   )r	  r`   r=   r   r9   r   r   rj   r   r   r   r$   r5   r   r  r  r   r  s	            r   r   PathPatch3D.do_3d_projectionK  s    OO&;Q;;JBBaJBB#889=9=9P9PR# zz"%%"4"4cZ"@$,,O3xr   )r  r  Nr{   )	r|   r}   r~   r   r   rE   rF   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_vertsr)  X  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)r)  r  rY   rF   )r&  r"   r)   rH   r
  s        r   patch_2d_to_3dr+  `  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  r$  transform_pathr  rY   rF   )	pathpatchr"   r)   r
   r'  r   s         r   pathpatch_2d_to_3dr/  g  sF    D))+E  &E%I$/r   c                      ^  \ rS rSrSrSSSSS.U 4S jjrS	 rS
 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$ )Patch3DCollectioniq  z
A collection of 3D patches.
r   r"   TFr8   r)   
depthshaderH   c                V   > X0l         [        TU ]  " U0 UD6  U R                  XU5        g)aJ  
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 to shade the patches in order to give the appearance of depth
(default is *True*). This is typically desired in scatter plots.
N)_depthshaderT   rE   rF   rG   r8   r)   r3  rH   r   rI   rY   s          r   rE   Patch3DCollection.__init__v  s-      &$)&)r4r   c                     U R                   $ rB   r5  rO   s    r   get_depthshade Patch3DCollection.get_depthshade      r   c                     Xl         SU l        gz
Set whether depth shading is performed on collection members.

Parameters
----------
depthshade : bool
    Whether to shade the patches in order to give the appearance of
    depth.
TNr5  r]   rG   r3  s     r   set_depthshade Patch3DCollection.set_depthshade       &
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.
r   r   NT)update_scalarmappableget_offsetsr'   r   r   r$   
atleast_1d
_offsets3dslice_z_markers_idx_vzsr`   r]   rG   r8   r)   rH   offsetsr6   r7   s          r   rF   #Patch3DCollection.set_3d_properties  sz    $ 	""$""$w<!YYFBBB%bbmmB.?F#Bi	%
r   c                   > U R                   (       a%  [        / U R                  QU R                  P76 u  pnOU R                  u  pn[        R
                  " XUU R                  R                  U R                  R                  5      u  pEpgX`l        [        TU ])  [        R                  R                  XE/5      5        UR                  S:  a  [        U5      $ [        R                   $ Nr   )r`   r=   rJ  r9   r   r   rj   r   rM  rT   set_offsetsr$   r5   r   sizer   rg   )	rG   r6   r7   r8   r  r  r  r  rY   s	           r   r   "Patch3DCollection.do_3d_projection  s    &CCCJBBJBB#889=9=9P9PR# 	BEE..z:;88a<s8O66Mr   c                     U R                   b&  U R                  (       a  [        XR                   5      OUn[        U5      S:  a  XR                     n[
        R                  " XR                  5      $ Nr   rM  r5  _zalphar'   rL  mcolorsto_rgba_array_alpharG   color_arrays     r   "_maybe_depth_shade_and_sort_colors4Patch3DCollection._maybe_depth_shade_and_sort_colors  ^     yy$)9)9 K+ 	
 {a%&9&9:K$$[++>>r   c                 >   > U R                  [        TU ]	  5       5      $ rB   r_  rT   get_facecolorrG   rY   s    r   rd  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   
_str_equal_edgecolorsrd  r_  rT   get_edgecolorre  s    r   rn  Patch3DCollection.get_edgecolor  F     D,,f55%%''66uw7L7NOOr   )r`   r5  rJ  r   rM  rL  r]   r   )r|   r}   r~   r   r   rE   r:  rA  r   rF   r   r_  rd  rn  r   r   r   s   @r   r1  r1  q  sM    
 CDU5 5( 
> ?PP Pr   r1  c                      ^  \ rS rSrSr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 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"   TFr2  c                r   > X0l         SU l        [        TU ]  " U0 UD6  U R	                  XU5        SU l        g)aE  
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 to shade the patches in order to give the appearance of depth
(default is *True*). This is typically desired in scatter plots.
FN)r5  _in_drawrT   rE   rF   _offset_zorderedr6  s          r   rE   Path3DCollection.__init__  s<      &$)&)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)rt  )_use_zordered_offsetr   rn   rT   ro   )rG   rp   rY   s     r   ro   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.
r   r   NT)rG  rH  r'   r   _zdirr   r$   rI  rJ  _sizes_sizes3dr%   _linewidths_linewidths3drK  rL  rM  r`   r]   rN  s          r   rF   "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 rB   )rT   	set_sizesrt  r  )rG   sizesdpirY   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 rB   )rT   set_linewidthrt  r$   r%   r  r  )rG   lwrY   s     r   r  Path3DCollection.set_linewidth@  s3    b!}}!#$*:*:!;D r   c                     U R                   $ rB   r9  rO   s    r   r:  Path3DCollection.get_depthshadeE  r<  r   c                     Xl         SU l        gr>  r?  r@  s     r   rA  Path3DCollection.set_depthshadeH  rC  r   c                 d   U R                   (       a%  [        / U R                  QU R                  P76 u  pnOU R                  u  pn[        R
                  " XUU R                  R                  U R                  R                  5      u  pEpg[        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        [$        R&                  " U [        R                  R)                  XE45      5        Xh   nXH   nXX   n[        R                  R)                  XE45      U l        UR,                  (       a  [        R.                  " U5      $ [        R0                  $ )Nr   r   )r`   r=   rJ  r9   r   r   rj   r   r$   r5   argsortrL  rM  r'   r  r~  r  r  r   rS  r   ru  rT  r   rg   )	rG   r6   r7   r8   r  r  r  r  z_markers_idxs	            r   r   !Path3DCollection.do_3d_projectionU  sL   &CCCJBBJBB#889=9=9P9PR# /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rB   )ru  _offsetsrT   rS  )rG   
old_offsetrY   s     r   rx  %Path3DCollection._use_zordered_offsetz  sE       ( JG 5 56+ *
s   8AA  AAAc                     U R                   b&  U R                  (       a  [        XR                   5      OUn[        U5      S:  a  XR                     n[
        R                  " XR                  5      $ rW  rX  r]  s     r   r_  3Path3DCollection._maybe_depth_shade_and_sort_colors  ra  r   c                 >   > U R                  [        TU ]	  5       5      $ rB   rc  re  s    r   rd  Path3DCollection.get_facecolor  rg  r   c                    > [         R                  " U R                  S5      (       a  U R                  5       $ U R	                  [
        TU ]  5       5      $ ri  rk  re  s    r   rn  Path3DCollection.get_edgecolor  rp  r   )r`   r5  rt  r  r  ru  r  rJ  r~  r  r   rM  rL  r}  r]   r   )g      R@)r|   r}   r~   r   r   rE   ro   r   rF   r  r  r:  rA  r   r   rx  r_  rd  rn  r   r   r   s   @r   rr  rr    sr    
 CDU% %,'

0d"
<
 #3J + +?PP Pr   rr  c                     [        U [        5      (       a  [        U l        SU l        O [        U [
        5      (       a  [        U l        X0l        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: True
    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.
NF)

isinstancer   rr  rY   ru  r   r1  r5  rt  rF   )r   r8   r)   r3  rH   s        r   patch_collection_2d_to_3dr    sP    * #~&&(#	C	)	)) O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lightsourcerH   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.

*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)rS   N)r'   r$   r   ).0verts     r   	<genexpr>,Poly3DCollection.__init__.<locals>.<genexpr>
  s"     >3rxx~&!+s   /1)_generate_normalsget_shade_colorsr(   rT   rE   r  r$   ndarrayndimany	set_zsort_codes3dr`   )rG   r
  r  r  r  rH   r   rI   normalsr  r  rY   s              r   rE   Poly3DCollection.__init__  s   D '.GL$7J%'4(|$  L$7J%'4(|$ !j&8 %& & 	000eRZZ((zzQ !LMM  >>>> !LMMu%r   )r  r   maxc                 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   r]   )rG   r  s     r   r  Poly3DCollection.set_zsort  s$     //6
r   z3.10c                 $    U R                  U5      $ rB   )_get_vector)rG   r  s     r   
get_vectorPoly3DCollection.get_vector$  s    
++r   c           	         [        U5      (       a$  [        R                  " U5      R                  u  p#nO/ / / pCn[        R                  " [        U5      5      n[        R
                  " X#XE/5      U l        S/[        R                  " U Vs/ s H  n[        U5      PM     sn5      Qn/ [        [        USS USS 5      QU l
        gs  snf )zOptimize points for projection.r   Nr   r   )r'   r$   r   r   onesr%   _vecr   maprK  
_segslices)rG   r  r6   r7   r8   r  r   indicess           r   r  Poly3DCollection._get_vector(  s    z??:.00JBBRBBwws2wHHbb/0	Kryyj!Ij7#g,j!IJKBCws|WQR[AB "Js   C
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  rT   	set_verts_closed)rG   r
  closedrY   s      r   r  Poly3DCollection.set_verts4  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  )rG   r
  r   s      r   set_verts_and_codes$Poly3DCollection.set_verts_and_codesG  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)rG  r   r  r   rd  _facecolor3drn  _edgecolor3d	get_alpha_alpha3dr]   )rG   rH   s     r   rF   "Poly3DCollection.set_3d_propertiesO  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_zposZ  r   r   c           
        ^  T R                   bT  T R                  5         T R                  (       a  T R                  T l        T R
                  (       a  T R                  T l        T R                  (       a  [        / T R                  SS QT R                  P76 u  pnT R                  R                  S   S:X  aY  [        R                  R                  UR                   T R                  S   5      n[        R                  R#                  XX4/5      nO.[        R                  R#                  XU/5      nOT R                  n[$        R&                  " UT R                  R(                  5      u  pgnT R*                   V	s/ s H  oU	   Xy   X   4PM     n
n	T R                  nT R                  n[-        U5      [-        U
5      :w  a  UR/                  [-        U
5      SS9n[-        U5      [-        U
5      :w  a+  [-        U5      S:X  a  UnOUR/                  [-        U
5      SS9nU
(       aA  [1        U 4S j[3        [5        XU5      5       5       S SS9n[5        U6 u  pT l        T l        nO:/ n[        R:                  " S	5      T l        [        R:                  " S	5      T l        / nT R<                  b8  U Vs/ s H  nT R<                  U   PM     nn[>        R@                  " T UU5        O"[>        RB                  " T UT RD                  5        [-        T R                  5      [-        U5      :w  a  T R                  T l        T RF                  b[  [        R"                  " S/S/T RF                  /S
//5      n[$        R&                  " UT R                  R(                  5      nUS   S   $ URH                  S:  a  [        RJ                  " U5      $ [        RL                  $ s  sn	f s  snf )z,
Perform the 3D projection for this object.
r   r#      axisc              3      >#    U  HK  u  nu  u  p#pEnTR                  UR                  5      [        R                  R	                  X#/5      XVU4v   MM     g 7frB   )r  datar$   r5   r   )r  idxr6   r7   r8   fcecrG   s          r   r  4Poly3DCollection.do_3d_projection.<locals>.<genexpr>  sP      ;9 1S0<BBR //"''*BEE,>,>x,H"RUV9s   AAc                     U S   $ rR  r   )r    s    r   <lambda>3Poly3DCollection.do_3d_projection.<locals>.<lambda>  s    adr   T)keyreverser   r  r   rS   )'_ArG  _face_is_mapped_facecolorsr  _edge_is_mappedrm  r  r`   r=   r  r9   r   r$   r5   masked_wherer,   r%   r   _proj_transform_vecrj   r  r'   repeatsorted	enumerater   _facecolors2d_edgecolors2demptyr  r   r  r  r  r   rT  r   rg   )rG   r6   r7   r8   w_maskedvectxstystzsslxyzlistcfacecedgez_segments_2dr   r   idxsr  r   zvecztranss   `                    r   r   !Poly3DCollection.do_3d_projection_  s    77 &&(##$($4$4!##$($4$4!&B		!AB		BJBByyq!Q&55--bggtyy|Deekk22"89eekk22,/))C223		D#9=I2GSWcg.I !!!!u:W%LLWAL6Eu:W%5zQS\:";c'%89; #D	2M ]# IAD.0BD K!#&!1D!#&!1DD==$3784CT]]3'4E8..t[%H$$T;Et  !SZ/!%!2!2D ??&88aS1#'81#>?D//diikkBF!9Q<XX\ 66#;66Mc J< 9s   ;O1Oc                 Z   > [         TU ]  U5        [        R                  " U 5      U l        g rB   )rT   set_facecolorr   rd  r  rG   r   rY   s     r   r  Poly3DCollection.set_facecolor  #    f%*88>r   c                 Z   > [         TU ]  U5        [        R                  " U 5      U l        g rB   )rT   set_edgecolorr   rn  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_alpharZ  r[  r  r\  AttributeError	TypeError
IndexErrorr  rm  r]   )rG   alphas     r   r  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  r9   r  rj   r   r$   asarrayr  rO   s    r   rd  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  r9   r  rj   r   r$   r  r  rO   s    r   rn  Poly3DCollection.get_edgecolor  r  r   )r  r`   r  r  r  rm  r  r  r  r  r   r  r  r]   )Tr   )r|   r}   r~   r   r   rE   r$   r  r   r  r  r  r   
deprecatedr  r  r  r  rF   r   r   r  r	  r  rd  rn  r   r   r   s   @r   r  r    s    ( ,5E!e<& <&~ ::vvvv 
__V, ,
C&	
L\?
?
.. .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  rY   r  rF   r`   )r   r8   r)   rH   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r6   r7   r8   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   r   s       r   r  r    s2     {rz		rzrzr   c                    [        U 5      S:X  d  [        U5      S:X  a  [        R                  " S5      $ [        [	        U5      [        U5      5      nSU" U5      S-  -
  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      $ )z7Modify the alphas of the color list according to depth.r   r  r   gffffff?r  Nr#   )
r'   r$   zerosr   r   r  r   rZ  r[  r   )r   r8   normsatsrgbas        r   rY  rY    s     6{a3r7a<xxSWc"g&DtBx#~D??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#   TNrS   )atol)r$   r  r   isnanr  uniquer'   linalgr$  newaxiscrosswhereisclosedeletedot	transposeallclose)
r6   r7   r8   r(  r   r   cross_normszero_cross_normsndotss
             r   _all_points_on_planer8    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#   rS   .N)	r  r$   r  r   r  r'   r  r  r-  )	r(  r6  i1i2i3v1v2poly_ipss	            r   r  r  D  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*.
Nr   g-x3@)azdegaltdegignore)invalidr   T)r  keepdimsr   g333333?c                     > T" T" U 5      5      $ rB   r   )r    in_normout_norms    r   r$  _shade_colors.<locals>.norm  s    GAJ''r   r   r#   )rZ  LightSourcer$   errstater+  r$  	directionr)  r  r   inverser[  r,  rh   copy)
colorr  r  r  r,   r$  r  r   rI  rJ  s
           @@r   r  r  p  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"   TF)g:0yE>rB   )?r   rk   numpyr$   
contextlibr   
matplotlibr   r   r   r   rZ  r   r	   rC   r
   r   matplotlib.collectionsr   r   r   r   r   matplotlib.colorsr   matplotlib.patchesr   rz   r   r   r   r*   r=   rD   r?   r   Line2Dr   r   r   r   r   r   r   r   r   r  r  r  r)  r+  r/  r1  rr  r  r  r  r   r  rY  r8  r  r  r   r   r   <module>rY     s:  

   %  Q Q ' $ OD+8dUZZ dN/$cU\\ cL1&',: , 
!(~ (V!=e =@5' 5p:80pP pPfwP~ wPt0>W.~ W.t!."=&+R)X#r   