
    ^j                     4   d Z ddlZddlZddlmZ ddlmZmZm	Z	m
ZmZmZmZmZ ddlmZmZmZmZmZ ddlmZ ddlmZ d	 Zd
 Zd Zd Zd Z  G d dejB                        Z"d5dZ# G d dejH                        Z%d5dZ&d6dZ'd6dZ(d6dZ)d6dZ* G d de      Z+d5dZ, G d de      Z-d5dZ. G d de      Z/ G d  d!e/      Z0d" Z1d5d#Z2d6d$Z3 G d% d&e      Z4d' Z5 G d( d)e      Z6	 	 	 	 d7dd*d+Z7 G d, d-e      Z8d5d.Z9d/ Z:d0 Z;	 	 d8d1Z<d9d2Z=d3 Z>d:d4Z?y);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                 *    | dz   dz  } | dkD  r| dz
  } | S )z?Return the given angle normalized to -180 < *a* <= 180 degrees.ih      as    S/opt/ringagent/.cad-venv/lib/python3.12/site-packages/mpl_toolkits/mplot3d/art3d.py_norm_angler      s$    	
SCA3wGH    c                 *    | dz   dz  } | dkD  r| dz
  } | S )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                    t        j                  | d      rt        j                  d      S t        j                  | d      rt        j                  d      S t        j                  | d      rt        j                  d      S | t        j                  d      S t        j                  |       r#t        |       dk(  rt        j                  |       S t        d	      )
a  
    Return a direction vector.

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

        - 'x': equivalent to (1, 0, 0)
        - 'y': equivalent to (0, 1, 0)
        - 'z': equivalent to (0, 0, 1)
        - *None*: equivalent to (0, 0, 0)
        - an iterable (x, y, z) is 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           	      d   t         j                  j                  | |j                  j                  k  | |j                  j
                  kD  ||j                  j                  k  ||j                  j                  kD  ||j                  j                  k  ||j                  j
                  kD  f      }|S )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      ==doo&:&:!:!#doo&:&:!:!#doo&:&:!:!#doo&:&:!:!#doo&:&:!:!#doo&:&:!:!< =D Kr   c           	         t         j                  j                  t        j                  |j                  j
                  j                  |             t        j                  |j                  j
                  j                  |            t        j                  |j                  j
                  j                  |            f      S )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                   l     e Zd ZdZd	dZd Zd
 fd	Zd ZddZe	j                  d        Zd
dZ xZS )Text3DaJ  
    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                     d|v rt        j                  d       d|v rt        j                  d       t        j                  j                  | |||fi | | j                  |||       y )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   rK   zText3D.__init__   sk    , f$, 	

D!Q77q$
3r   c                 H    | j                   | j                  | j                  fS )z*Return the (x, y, z) position of the text.)_x_y_zrM   s    r   get_position_3dzText3D.get_position_3d   s    ww((r   c                 x    t         |   |dd        | j                  |d          |t        |      | _        yy)ax  
        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)rM   xyzr*   	__class__s      r   set_position_3dzText3D.set_position_3d   s?     	S!W%

3q6*40DM r   c                      || _         d| _        y)zl
        Set the *z* position of the text.

        Parameters
        ----------
        z : float
        TN)rS   stale)rM   r"   s     r   rZ   zText3D.set_z   s     
r   c                 N    || _         t        |      | _        || _        d| _        y)a  
        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)rS   r+   r[   _axlim_clipr`   )rM   r"   r*   rN   s       r   rL   zText3D.set_3d_properties   s&      &t,%
r   c                    t        | j                  | j                  | j                  | j                        }| j
                  r9|t        | j                  | j                  | j                  | j                        z  }t        j                  |      ret        j                  j                  | j                  | j                  | j                  g|t              j                  t        j                        }n<t        j                  | j                  | j                  | j                  gt              }|| j                  z   }t        j                  ||g      }t!        j"                  |d d df   |d d df   |d d df   | j                        }|d   d   |d   d   z
  }|d   d   |d   d   z
  }t%        j&                  t%        j(                  ||            }	t+        j,                  | |d   d   |d   d   t/        |	            5  t0        j2                  j5                  | |       d d d        d| _        y # 1 sw Y   d| _        y xY w)N)r9   dtyperd   r   r   rW   )rQ   rR   	_rotationF)rB   rQ   rR   rS   r8   rb   r:   r%   anymar&   floatfillednanr[   asarrayr   _scale_proj_transformmathdegreesatan2r   _setattr_cmr   rI   rJ   drawr`   )
rM   rendererr9   pos3ddir_endpointsprojdxdyangles
             r   rr   zText3D.draw   s   "477DGGTWWdiiHM$''477DGGTYYGGD66$<EEKK$''477 ;%)   88>rvv  HHdggtww8FE$--'UG,-++1a4L&A,q!tdiiA!WQZ$q'!*$!WQZ$q'!*$TZZB/0tQ
tAwqz)9%)@B 	,JJOOD(+	, 
	, 
s   !H99I	c                      y Nr   )rM   rs   s     r   get_tightbboxzText3D.get_tightbbox   s     r   )r   r   r    r"   Fr|   r   r"   F)__name__
__module____qualname____doc__rK   rU   r^   rZ   rL   r   allow_rasterizationrr   r}   __classcell__r]   s   @r   rD   rD   |   s@    .4)1"	*   ,r   rD   c                 @    t         | _        | j                  |||       y)a  
    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]   rL   )objr"   r*   rN   s       r   text_2d_to_3dr      s      CM!T:.r   c                   d     e Zd ZdZdd fd
Zd	dZd Zd Zej                   fd       Z
 xZS )
Line3Da  
    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)rN   c                b    t        |   g g g|i | | j                  |||       || _        y)aM  

        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)rX   rK   set_data_3drb   )rM   r5   r6   r7   rN   argsrO   r]   s          r   rK   zLine3D.__init__  s8     	R1$1&1R$%r   c                 
   | j                         }| j                         }t        j                  |      j	                         }t        j                  |t        |            }t        ||||      | _	        || _
        d| _        y)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_verts3drb   r`   )rM   r7   r*   rN   r5   r6   s         r   rL   zLine3D.set_3d_properties&  sj    " ^^^^++B/557__RR)#BB5%
r   c                     t        |      dk(  r|d   }t        d|      D ](  \  }}t        j                  |      rt	        | d       || _        d| _        y)ag  
        Set the x, y and z data

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

        Notes
        -----
        Accepts x, y, z arguments or a single array-like (x, y, z)
        r   r   r\   z must be a sequenceTN)r(   zipr%   r'   RuntimeErrorr   r`   )rM   r   namer\   s       r   r   zLine3D.set_data_3d?  sc    " t9>7DUD) 	AID#;;s#"dV+>#?@@	A 
r   c                     | j                   S )z
        Get the current data

        Returns
        -------
        verts3d : length-3 tuple or array-like
            The current data as a tuple or array-like.
        )r   rT   s    r   get_data_3dzLine3D.get_data_3dX  s     }}r   c                    t        g | j                  | j                   }| j                  r$|t	        g | j                  | j                   z  }t        j                  |      rt        j                  |t        | j                        g| j                  d   j                        }t
        j                  j                  | j                  t        |      j                  t
        j                        \  }}}n| j                  \  }}}t        j                   |||| j                        \  }}}	}
| j#                  ||       t$        | M  |       d| _        y )Nr   rd   r9   F)rB   r   r8   rb   r:   r%   rg   r   r(   shaperh   r&   ri   rj   rk   r   _scale_proj_transform_clipset_datarX   rr   r`   )rM   rs   
scale_maskr9   xs3dys3dzs3dr5   r6   r7   tisr]   s              r   rr   zLine3D.drawc  s   (C$--CC
-BB		BBJ66*??T]]#=dmmA&6&<&<=D  "uu{{4==16T  +  CCI6"&&> D$  $}}D$ ;;D$diiXBCb"X
r   r   )r   r   r   r   rK   rL   r   r   r   r   rr   r   r   s   @r   r   r   	  s;     6; &$22	   r   r   c                 @    t         | _        | j                  |||       y)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]   rL   )liner7   r*   rN   s       r   line_2d_to_3dr   w  s    " DN2tZ0r   c                 $   t        j                  |t        |             }| j                  dd      }t	        ||      D cg c]  \  \  \  }}}}|||f }}}}}|D cg c]  \  }}}t        ||||       }	}}}|	S c c}}}}w c c}}}w )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!?H03Hb0A
B
B,.6Aq4!Aq!9
BC
B9<==IQ1[Aq$'=E=L C=s   B
$Bc           	         t        j                  |      s t        j                  |t        |             }n"t        |      t        |       k7  rt	        d      t        | |      D cg c]  \  }}t        |||       }}}|S c c}}w )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     s{     ;;r?__RU,r7c%j LMM  #5"~/e  eT2 /D /K/s   'Bc                 b   t        j                  |t        |             }| j                  dd      }t	        ||      D cg c]  \  \  \  }}}}|||f|f }}}}}|r/t	        | \  }	}
|	D cg c]  \  }}}t        ||||       }}}}ng }g }
|t        |
      fS c c}}}}w c c}}}w )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N'8~Aq1a)T"NIN)_
U=@AA	AqQ1d+AA$u+ O Bs   B"
3B*c           	          t        j                  |t        |             }t        | |      D cg c]  \  }}t	        |||       }}}|rt        | \  }}ng g }}t        |      t        |      fS c c}}w )zP
    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     sz    
 
SZ	(B),UB9%$ 5T5$G 9N 9~.%b%>4;&&9s   A1c                       e Zd ZdZd Zy)Collection3DzA collection of 3D paths.c                 V   | j                   D cg c]  \  }}|	 }}}|D cg c]#  }t        g |j                  | j                   % }}| j                  r@t        ||      D cg c])  \  }}|t        g |j                  | j                   z  + }}}t        ||      D cg c][  \  }}t        j                  |      r?t        j                  j                  |t        j                  ||j                              n|] }}}|D cg c]9  }t        j                  |dddf   |dddf   |dddf   | j                        ; }}t        || j                         D 	cg c]A  \  \  }}}\  }}	t        j                   t        j                  j#                  ||g      |	      C c}	}}}| _        t        j&                  |D 
cg c]  \  }}}
|

 c}
}      }
t)        |
      r|
j+                         S dS c c}}w c c}w c c}}w c c}}w c c}w c c}	}}}w c c}
}w )z0Project the points according to renderer matrix.r9   Nr   r   rW       eA)_3dverts_codesrB   Tr8   rb   r   r:   r%   rg   rh   r&   r   r   r   rm   mpathPathcolumn_stack_pathsconcatenater(   min)rM   vs_vs_listmasksm	xyzs_listr5   r6   csr7   s              r   do_3d_projectionzCollection3D.do_3d_projection  s   #'#6#67%"a277AHI2$6bdd6DII6II"%eW"57B 88dii88 7E 7 !$GU 35r1 ffQi 55;;r288(D;E%'( 5 5 @GH9; 11q!tHbAh1a4$))5 H	 H 47y$BUBU3VX X/;BAB zz"%%"4"4b"X">C X^^	:HAq"R:;r7rvvx++ 8I75HX:s*   H(H(.H(A H>H*AH
H%
N)r   r   r   r   r   r   r   r   r   r     s
    #,r   r   c                 ,   t        j                  |t        | j                                     }t	        | j                         |      D cg c]  \  }}t        j
                  t        g t        j
                  |j                  t        j                  |t        |j                              g      j                  |       |j                  f c}}| _
         t        j                  t        d      t        |             | _        || _        yc c}}w )z4Convert a `.Collection` to a `.Collection3D` object.z{}3DN)r%   r   r(   	get_pathsr   r   r   verticesr   r   r   r   _make_class_factoryr   typer]   rb   )colr7   r*   rN   pr"   s         r   collection_2d_to_3dr     s    	S1	2B ,.
 Aq	 
 __ajj"//!S_*MNOQQ 
 
	.C DE--lFCDINCM CO.s   BDc                   :     e Zd ZdZd fd	Zd Z fdZd Z xZS )Line3DCollectionz#
    A collection of 3D lines.
    c                 4    t        |   |fi | || _        y r|   )rX   rK   rb   )rM   r   rN   rO   r]   s       r   rK   zLine3DCollection.__init__  s"    )&)%	r   c                      || _         d| _        yz&Set the position to use for z-sorting.TN
_sort_zposr`   rM   vals     r   set_sort_zposzLine3DCollection.set_sort_zpos      
r   c                 2    || _         t        | 	  g        y)z"
        Set 3D segments.
        N)_segments3drX   set_segments)rM   r   r]   s     r   r   zLine3DCollection.set_segments	  s     $R r   c                    | j                   }|D cg c]  }t        |       }}t        t        |            dkD  }|rHt        d |D              r t        j
                  j                  |      }n+t	        j                  |      }nt	        j                  |      }|j                  dk(  r&t        j                  | g        t        j                  S d}t        j
                  j                  |      r2|j                  t        j
                  j                  ur|j                  }t        |d   |d   |d   | j                         }t	        j                  |      r;|t	        j"                  |dt        j$                  f   g |j&                  d	      z  }| j(                  rst+        |d   |d   |d   | j                         }t	        j                  |      r=t	        j"                  |dt        j$                  f   g |j&                  d	      }||z  }t-        j.                  || j                         }|dur!t        j
                  j1                  ||
      }|dddf   }	|r,t	        j2                  |	t	        j4                  |dd             }	t        j                  | |	       t        |      dkD  rt7        |d   j7                         d      }
|
S t        j                  }
|
S c c}w )zB
        Project the points according to renderer matrix.
        r   c              3   Z   K   | ]#  }t         j                  j                  |       % y wr|   )r%   rh   isMA).0segments     r   	<genexpr>z4Line3DCollection.do_3d_projection.<locals>.<genexpr>  s     ?7255::g&?s   )+r   F.r   .r   .rW   .r#   r   rW   Nr   )r   r(   setrg   r%   rh   r   
asanyarraysizer   r   rk   r   r9   nomaskrB   r8   r   newaxisr   rb   r:   r   _scale_proj_transform_vectorsr&   splitcumsumr   )rM   r   r   segment_lengthsraggedr9   r   viewlim_maskxyzssegments_2dminzs              r   r   z!Line3DCollection.do_3d_projection  s{    ## 8@@G3w<@@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l*33HdiiHu55;;t$;/D3!8n((;		/#2:N0OPK##D+6 t9q=tF|'')3/D  66Di As   K$F)	r   r   r   r   rK   r   r   r   r   r   s   @r   r   r     s    8
!;r   r   c                     t        | j                         ||      }t        | _        | j	                  |       || _        y)z<Convert a `.LineCollection` to a `.Line3DCollection` object.N)r   r   r   r]   r   rb   )r   r7   r*   rN   
segments3ds        r   line_collection_2d_to_3dr  N  s2    &s}}DAJ$CMZ  COr   c                   @     e Zd ZdZdddd fd
Zd
dZd Zd	 Z xZS )Patch3Dz
    3D patch object.
    r   r"   Fr7   r*   rN   c                J    t        |   |i | | j                  |||       y)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)rX   rK   rL   )rM   r7   r*   rN   r   rO   r]   s         r   rK   zPatch3D.__init__[  s)      	$)&)r44r   c                     t        j                  |t        |            }t        ||      D cg c]  \  \  }}}t	        ||||       c}}}| _        || _        yc c}}}w )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   
_segment3drb   )rM   vertsr7   r*   rN   r    r!   r"   s           r   rL   zPatch3D.set_3d_propertiesn  s]    $ __RU,.1%n> >*A 'q!Q5 >%>s   Ac                     t        | d      s9| j                  j                         | j                  _        | j	                          | j
                  S )N_path2d)hasattrr8   get_projMr   r  rT   s    r   get_pathzPatch3D.get_path  s<     tY')),,.DIIK!!#||r   c                 X   | j                   }t        | \  }}}t        |||| j                        }| j                  r|t        |||| j                        z  }t        j                  |      rNt        j                  j                  t        | t        |      j                  t        j                        \  }}}n|||}}}t        j                  |||| j                        \  }	}
}}t        j                   t        j                  j#                  |	|
g            | _        t'        |      S Nr   )r  r   rB   r8   rb   r:   r%   rg   rh   r&   ri   rj   rk   r   r   r   r   r   r  r   rM   sxs0ys0zs0r9   r5   r6   r7   vxsvysvzsviss                r   r   zPatch3D.do_3d_projection  s    OOQS#"3S$))<M#sC;;D66$<S!W+0t % ==CVBFF^ BB c3BB#>>r2r499US#szz"%%"4"4c3Z"@A3xr   r   )	r   r   r   r   rK   rL   r  r   r   r   s   @r   r
  r
  V  s%     "$#% 5&&.r   r
  c                   .    e Zd ZdZdddddZd
dZd Zy	)PathPatch3Dz
    3D PathPatch object.
    r   r"   Fr  c                X    t        j                  | fi | | j                  ||||       y)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   rK   rL   )rM   r
   r7   r*   rN   rO   s         r   rK   zPathPatch3D.__init__  s)    " 	t&v&tRz:r   c                 n    t         j                  | |j                  |||       |j                  | _        y)aB  
        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
  rL   r   r   _code3d)rM   r
   r7   r*   rN   s        r   rL   zPathPatch3D.set_3d_properties  s1    $ 	!!$"4-7 	" 	9zzr   c                 n   | j                   }t        | \  }}}t        |||| j                        }| j                  r|t        |||| j                        z  }t        j                  |      rNt        j                  j                  t        | t        |      j                  t        j                        \  }}}n|||}}}t        j                  |||| j                        \  }	}
}}t        j                   t        j                  j#                  |	|
g      | j$                        | _        t)        |      S r  )r  r   rB   r8   rb   r:   r%   rg   rh   r&   ri   rj   rk   r   r   r   r   r   r%  r  r   r  s                r   r   zPathPatch3D.do_3d_projection  s    OOQS#"3S$))<M#sC;;D66$<S!W+0t % ==CVBFF^ BB c3BB#>>r2r499US#szz"%%"4"4c3Z"@$,,O3xr   Nr   )r   r   r   r   rK   rL   r   r   r   r   r"  r"    s     $&CE ;(",r   r"  c                     | j                         }| j                         }|j                  |      }t        |      r|d   S t	        j
                  g       S )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-    sI    %%'E>>D&Hh-8A;9RXXb\9r   c                 X    t        |       }t        | _        | j                  ||||       y)z*Convert a `.Patch` to a `.Patch3D` object.N)r-  r
  r]   rL   )r*  r"   r*   rN   r  s        r   patch_2d_to_3dr/    s'    U#EEO	E1dJ7r   c                     | j                         }| j                         }|j                  |      }t        | _        | j                  |||       y)z2Convert a `.PathPatch` to a `.PathPatch3D` object.N)r  r(  transform_pathr"  r]   rL   )	pathpatchr"   r*   r
   r+  r   s         r   pathpatch_2d_to_3dr3    sH    D))+E  &E%Iq$/r   c                   r     e Zd ZdZdddddd fd
Zd Z	 dd	Zd
 ZddZ fdZ	d Z
 fdZ fdZ xZS )Patch3DCollectionz%
    A collection of 3D patches.
    r   r"   NFr7   r*   
depthshadedepthshade_minalpharN   c                    |	t         d   }|	t         d   }|| _        || _        t        |   |i | | j                  |||       y)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_minalpharX   rK   rL   	rM   r7   r*   r7  r8  rN   r   rO   r]   s	           r   rK   zPatch3DCollection.__init__  s\    8 !"56J&"*+G"H%$7!$)&)r44r   c                     | j                   S r|   r<  rT   s    r   get_depthshadez Patch3DCollection.get_depthshade      r   c                 D    |	t         d   }|| _        || _        d| _        y)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, default: :rc:`axes3d.depthshade_minalpha`
            Sets the minimum alpha value used by depth-shading.

            .. versionadded:: 3.11
        Nr;  Tr   r<  r=  r`   rM   r7  r8  s      r   set_depthshadez Patch3DCollection.set_depthshade"  -    $ &"*+G"H%$7!
r   c                      || _         d| _        yr   r   r   s     r   r   zPatch3DCollection.set_sort_zpos:  r   r   c                    | j                          | j                         }t        |      dkD  r|j                  \  }}ng }g }t	        ||t        j                  |      |      | _        t        d      | _	        d| _
        || _        d| _        y)ai  
        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_vzsrb   r`   rM   r7   r*   rN   offsetsr5   r6   s          r   rL   z#Patch3DCollection.set_3d_properties?  s~    ( 	""$""$w<!YYFBBB%b"bmmB.?F#Bi	%
r   c                    t        g | j                  | j                   }| j                  r$|t	        g | j                  | j                   z  }t        j                  |      r0t
        j                  j                  | j                  |      \  }}}n| j                  \  }}}t        j                  |||| j                        \  }}}}|| _        t
        j                  j                  |      r/t        	| 9  t
        j                  j                  ||g             n$t        	| 9  t        j                  ||g             |j                   dkD  rt#        |      S t
        j$                  S )Nr   r   )rB   rM  r8   rb   r:   r%   rg   rh   r&   r   r   rP  r   rX   set_offsetsr   r   r   rk   )
rM   r9   r5   r6   r7   r  r  r  r   r]   s
            r   r   z"Patch3DCollection.do_3d_projection`  s   "?DOO?TYY?M>4??>DII>>D66$<T__4@JBBJBB#>>r2r499US#s	55::c?G 2 2C: >?Gc
 ;<88a<s8O66Mr   c                    | j                   }| j                  N| j                  rBt        || j                  | j                        }||j
                  d   dk(  r||d d df   z  }t        |      dkD  rI|| j                     }t        j                  |      dkD  r"t        j                  |      | j                     }t        j                  ||      S )N)	min_alphar      r#   r   )_alpharP  r<  _zalphar=  r   r(   rO  r%   ndimrl   mcolorsto_rgba_arrayrM   color_arrayalphas      r   "_maybe_depth_shade_and_sort_colorsz4Patch3DCollection._maybe_depth_shade_and_sort_colorst  s     99 T%5%5!		33K
  [%6%6q%9Q%>AqD 11 {a%d&9&9:Kwwu~!

5)$*=*=>$$[%88r   c                 >    | j                  t        | 	               S r|   r`  rX   get_facecolorrM   r]   s    r   rc  zPatch3DCollection.get_facecolor      66uw7L7NOOr   c                     t        j                  | j                  d      r| j                         S | j	                  t
        |                S Nfacer   r$   _edgecolorsrc  r`  rX   get_edgecolorrd  s    r   rk  zPatch3DCollection.get_edgecolor  C     D,,f5%%''66uw7L7NOOr   r|   r  )r   r   r   r   rK   rA  rF  r   rL   r   r`  rc  rk  r   r   s   @r   r5  r5    sU      #5J  !0
B(9,PP Pr   r5  c                 P   t         j                  j                  |       sy| j                         | j	                         z
  }|j                         |j	                         z
  }|j                         |j	                         z
  }t        j
                  |dz  |dz  z   |dz  z         S )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   rW   )r%   rh   countmaxr   sqrt)XYZptp_xptp_yptp_zs         r   _get_data_scalerw    s     55;;q>
 EEGaeegEEEGaeegEEEGaeegE775A:
*UaZ788r   c                        e Zd ZdZdddddd fd
Z fdZd	 Zdd
Zd fd	Z fdZ	d Z
	 ddZd Ze fd       Zd Z fdZ fdZ xZS )Path3DCollectionz#
    A collection of 3D paths.
    r   r"   NFr6  c                    |	t         d   }|	t         d   }|| _        || _        d| _        t	        |   |i | | j                  |||       d| _        y)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.
        Nr:  r;  F)r   r<  r=  _in_drawrX   rK   rL   _offset_zorderedr>  s	           r   rK   zPath3DCollection.__init__  sk    8 !"56J&"*+G"H%$7!$)&)r44 $r   c                     | j                         5  t        j                  | d      5  t        |   |       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NT)r{  )_use_zordered_offsetr   rq   rX   rr   )rM   rs   r]   s     r   rr   zPath3DCollection.draw  sZ    &&( 	'""4$7 'X&'	' 	'' '	' 	's!   AAAA	AA c                      || _         d| _        yr   r   r   s     r   r   zPath3DCollection.set_sort_zpos  r   r   c                    | j                          | j                         }t        |      dkD  r|j                  \  }}ng }g }|| _        t        ||t        j                  |      |      | _        | j                  | _
        t        j                  | j                        | _        | j                  \  }}}t        d      | _        d| _        || _        d| _        y)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  rb   r`   rQ  s          r   rL   z"Path3DCollection.set_3d_properties  s    ( 	""$""$w<!YYFBBB
%b"bmmB.?F XXd&6&67__
B
 $Bi	%
r   c                 N    t         |   ||       | j                  s|| _        y y r|   )rX   	set_sizesr{  r  )rM   sizesdpir]   s      r   r  zPath3DCollection.set_sizes  s%    %%}}!DM r   c                     t         |   |       | j                  s%t        j                  | j
                        | _        y y r|   )rX   set_linewidthr{  r%   r&   r  r  )rM   lwr]   s     r   r  zPath3DCollection.set_linewidth  s3    b!}}!#$*:*:!;D r   c                     | j                   S r|   r@  rT   s    r   rA  zPath3DCollection.get_depthshade!  rB  r   c                 D    |	t         d   }|| _        || _        d| _        y)aw  
        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
        Nr;  TrD  rE  s      r   rF  zPath3DCollection.set_depthshade$  rG  r   c                    d}| j                   D ]1  }t        j                  j                  |      s#||j                  z  }3 |t        g | j                   | j                   z  }| j                  r$|t        g | j                   | j                   z  }t        j                  |      rpt        j                  |t        | j                         g| j                   d   j                        }t        j                  j                  | j                   |      }n| j                   }t        j                  g || j                   \  }}}}t!        |||      | _        t        j                  j%                  |      d d d   x}| _        || _        t        | j*                        dkD  r| j*                  |   | _        t        | j.                        dkD  r| j.                  |   | _        t3        j4                  | t        j                  j7                  ||f             ||   }||   }||   }t        j                  j7                  ||f      | _        |j:                  rt        j<                  |      S t        j>                  S )NFr   r   r   r   ) rM  r%   rh   r   r9   rB   r8   rb   r:   rg   r   r(   r   r&   r   r   rw  _data_scaleargsortrO  rP  r  r  r  r  r   rT  r   r|  r   r   rk   )	rM   r9   r\   r  r  r  r  r   z_markers_idxs	            r   r   z!Path3DCollection.do_3d_projection<  s
   ?? 	'Cuuzz#chh	' )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S#s*3S9 /1eemmC.@2.FF+	 t}}!--6DKt!!"Q&#11-@D""4););S#J)GH - - -  !# 2 2C: >!hhrvvc{2BFF2r   c              #      K   | j                   d  y | j                  }t        |   | j                          	 d  || _        y # || _        w xY wwr|   )r|  _offsetsrX   rT  )rM   
old_offsetr]   s     r   r~  z%Path3DCollection._use_zordered_offseti  sJ       ( JG 5 56+ *
s   7AA A	AAc                    | j                   }| j                  Y| j                  rMt        || j                  | j                  | j
                        }||j                  d   dk(  r||d d df   z  }t        |      dkD  rI|| j                     }t        j                  |      dkD  r"t        j                  |      | j                     }t        j                  ||      S )N)rV  r  r   rW  r#   r   )rX  rP  r<  rY  r=  r  r   r(   rO  r%   rZ  rl   r[  r\  r]  s      r   r`  z3Path3DCollection._maybe_depth_shade_and_sort_colorsw  s     99 T%5%5!		33 ,,	K  [%6%6q%9Q%>AqD 11 {a%d&9&9:Kwwu~!

5)$*=*=>$$[%88r   c                 >    | j                  t        | 	               S r|   rb  rd  s    r   rc  zPath3DCollection.get_facecolor  re  r   c                     t        j                  | j                  d      r| j                         S | j	                  t
        |                S rg  ri  rd  s    r   rk  zPath3DCollection.get_edgecolor  rl  r   r  )g      R@r|   )r   r   r   r   rK   rr   r   rL   r  r  rA  rF  r   r   r~  r`  rc  rk  r   r   s   @r   ry  ry    sy      %%N'

2h"
<
  !0+3Z + +9.PP Pr   ry  )r8  c                    t        | t              rt        | _        d| _        nt        | t
              rt        | _        |	t        d   }|	t        d   }|| _        || _	        d| _
        | j                  |||       y)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
    Nr:  r;  F)
isinstancer   ry  r]   r|  r   r5  r   r<  r=  r{  rL   )r   r7   r*   r7  rN   r8  r   s          r   patch_collection_2d_to_3dr    sz    H #~&(#	C	))12
"&'CD CO2CCL"dJ/r   c                        e Zd ZdZddddd fd
Zej                  ej                  ej                  dZ	d Z
 ej                  d	      d
        Zd Zd fd	Zd ZddZd Zd Z fdZ fdZd Zd Zd Z xZS )Poly3DCollectiona  
    A collection of 3D polygons.

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

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

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

        If you need filled areas, it is recommended to create them via
        `~mpl_toolkits.mplot3d.axes3d.Axes3D.plot_trisurf`, which creates a
        triangulation and thus generates consistent surfaces.
    averageFN)zsortshadelightsourcerN   c                   |rbt        |      }|j                  dd      }	|	t        |	||      |d<   |j                  dd      }
|
t        |
||      |d<   |	|
t        d      t	        |   |g|i | t        |t        j                        r|j                  dk7  r(t        d      t        d |D              rt        d      | j                  |       d| _        || _        y)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   ^   K   | ]%  }t        t        j                  |            d k7   ' yw)rW   N)r(   r%   r   )r   verts     r   r   z,Poly3DCollection.__init__.<locals>.<genexpr>  s"     >3rxx~&!+>s   +-)_generate_normalsget_shade_colorsr)   rX   rK   r  r%   ndarrayrZ  rg   	set_zsort_codes3drb   )rM   r  r  r  r  rN   r   rO   normalsr  r  r]   s              r   rK   z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   ro  c                 H    | j                   |   | _        d| _        d| _        y)a  
        Set the calculation method for the z-order.

        Parameters
        ----------
        zsort : {'average', 'min', 'max'}
            The function applied on the z-coordinates of the vertices in the
            viewer's coordinate system, to determine the z-order.
        NT)_zsort_functions
_zsortfuncr   r`   )rM   r  s     r   r  zPoly3DCollection.set_zsort(  s$     //6
r   z3.10c                 $    | j                  |      S r|   )_get_vector)rM   r  s     r   
get_vectorzPoly3DCollection.get_vector6  s    
++r   c                    t        |t        j                        r}t        j                  d|       t        |t        j
                  j                        r3|j                  | _        |j                  j                  d      | _        y
|| _        d| _        y
t        |      }t        j                  t        t        |      t        j                        }|j!                  d      }t        j"                  ||d	f      }t%        |      D ]  \  }}|||d
t        |      f<    || _        t        j&                  |      |d
d
d
f   k\  | _        y
)af  
        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   axisFre   r   )initialr#   N)r  r%   r  r   check_shaperh   MaskedArraydata_facesr9   rg   _invalid_verticesr(   fromitermapintpro  empty	enumeratearange)rM   r  	num_faces	num_verts	max_vertsr   irh  s           r   r  zPoly3DCollection._get_vector:  s	    j"**-_D*bee&7&78(oo)3)<)<")<)E&().& JICZ$8HI!a0IxxIq 9:H$Z0 /4*.JSYJ'/"DK%'YYy%9Yq$w=O%OD"r   c                 V    | j                  |       t        | 	  g d       || _        y)a  
        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  rX   	set_verts_closed)rM   r  closedr]   s      r   r  zPoly3DCollection.set_vertsY  s)     	"e$r   c                 8    | j                  |d       || _        y)z Set 3D vertices with path codes.F)r  N)r  r  )rM   r  r   s      r   set_verts_and_codesz$Poly3DCollection.set_verts_and_codesl  s     	uU+r   c                     | j                          d | _        | j                  d       t        j                  |       | _        t        j                  |       | _        t        j                  |       | _	        d| _
        y )Nr  T)rJ  r   r  r   rc  _facecolor3drk  _edgecolor3d	get_alpha_alpha3dr`   )rM   rN   s     r   rL   z"Poly3DCollection.set_3d_propertiest  sb     	""$y!*88>*88>&006
r   c                      || _         d| _        yr   r   r   s     r   r   zPoly3DCollection.set_sort_zpos  r   r   c                 8	   | j                   J| j                          | j                  r| j                  | _        | j
                  r| j                  | _        t        | j                        }| j                  t        | j                  d   | j                  d   | j                  d   | j                        z  }t        j                  |      }t        j                  dd      5  t!        j"                  | j                  | j                        }ddd       | j$                  r[t'        | j                  d   | j                  d   | j                  d   | j                        }t        j                  |      rd}||z  }d   }|r!t        j(                  j+                  ||      }| j                  }| j                  }t        |      |k7  r|j-                  |d	
      }t        |      |k7  r$t        |      d	k(  r|}n|j-                  |d	
      }t        |      d	kD  r| j/                  |d
      }	n|}	|r|	j0                  }	t        j2                  |	d
      ddd   }
t        |      d	kD  r||
ddddf   }n|}| j4                  }t        | j4                        d	kD  re|r/||
ddf    }t7        ||      D cg c]  \  }}||ddf    }}}|
D cg c]  }| j4                  |    }}t9        j:                  | ||       nz|rWt        |      d	kD  rIt        j<                  ||
dddf   |j>                        }t        j(                  j+                  ||      }t9        j@                  | || jB                         t        |      d	kD  r||
   | _"        n|| _"        t        | j                        t        |      k(  rt        |      d	kD  r||
   | _#        n| j                  | _#        | jH                  Yt        jJ                  d	gd	g| jH                  gdgg      }t!        jL                  || j                  jN                        }|d   d	   S |jP                  d	kD  rt        jR                  |      S t        jT                  S # 1 sw Y   wxY wc c}}w c c}w )z<
        Perform the 3D projection for this object.
        Nr   r   r   ignore)invaliddivideTr   r   r  r   rW   r   )+_ArJ  _face_is_mapped_facecolorsr  _edge_is_mappedrj  r  r(   r  r  rB   r8   r%   rg   errstater   r   rb   r:   rh   r  repeatr  r  r  r  r   r   r  r   r   r  r  _facecolors2d_edgecolors2dr   r&   _proj_transform_vecr  r   r   rk   )rM   r  r9   needs_maskingpfacesr  pzscfacecedgeface_z
face_orderfaces_2dsegment_maskrh  idxr   invalid_vertices_2dzvecztranss                      r   r   z!Poly3DCollection.do_3d_projection  s    77 &&(##$($4$4!##$($4$4!$	%%(;KKV!4KK), , t [[(; 	R99$++tyyQF	R (V)<dkk&>Q)-V)<diiILvvl# $l*Vn%%##Cd#3C !!!!u:"LLL3Eu:"5zQYQ7s8a<__Sr_2FF[[FZZR026
v;?j!RaR/0HH==$T]]);a)? $Z] 33"%h"=?jdDDqM ? ?3=>CT]]3'>E>..tXuEX!2&(ooQ,-NN'$# 55,, ': - <$$T8T\\Bu:>!&z!2D!&Dt  !SZ/CJN!&z!2D!%!2!2D ??&88aS1#'81#>?D//diikkBF!9Q<XX\ 66#;66MS	R 	RP?>s   $+R<RRRc                 X    t         |   |       t        j                  |       | _        y r|   )rX   set_facecolorr   rc  r  rM   r   r]   s     r   r  zPoly3DCollection.set_facecolor  #    f%*88>r   c                 X    t         |   |       t        j                  |       | _        y r|   )rX   set_edgecolorr   rk  r  r  s     r   r  zPoly3DCollection.set_edgecolor  r  r   c                    t         j                  j                  | |       	 t        j                  | j
                  | j                        | _        	 t        j                  | j                  | j                        | _        d| _        y # t        t        t        f$ r Y Nw xY w# t        t        t        f$ r
 Y d| _        y w xY w)NT)r   Artist	set_alphar[  r\  r  rX  AttributeError	TypeError
IndexErrorr  rj  r`   )rM   r_  s     r   r  zPoly3DCollection.set_alpha  s    e,	 ' 5 5!!4;;!0D	&44%%t{{ 4D 
 	:6 		
 	:6 	
	s#   /B	 /B# 	B B #C Cc                     t        | d      s9| j                  j                         | j                  _        | j	                          t        j                  | j                        S )Nr  )r  r8   r  r  r   r%   rl   r  rT   s    r   rc  zPoly3DCollection.get_facecolor  G     t_-)),,.DIIK!!#zz$,,--r   c                     t        | d      s9| j                  j                         | j                  _        | j	                          t        j                  | j                        S )Nr  )r  r8   r  r  r   r%   rl   r  rT   s    r   rk  zPoly3DCollection.get_edgecolor
  r  r   )Tr  )r   r   r   r   rK   r%   r  r   ro  r  r  r   
deprecatedr  r  r  r  rL   r   r   r  r  r  rc  rk  r   r   s   @r   r  r    s    ( ,5E!e>&B ::vvvv T__V, ,P>&	
cJ?
?
..r   r  c                     t        | j                         ||      \  }}t        | _        | j	                  ||       | j                          || _        y)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  rL   rb   )r   r7   r*   rN   segments_3dr   s         r   poly_collection_2d_to_3dr    sJ     :MMOR'K$CMK/ COr   c                 `    |dk(  r|| |fS |dk(  r| ||fS |d   dk(  rt        | |||      S | ||fS )z
    Reorder coordinates so that 2D *xs*, *ys* can be plotted in the plane
    orthogonal to *zdir*. *zdir* is normally 'x', 'y' or 'z'. However, if
    *zdir* starts with a '-' it is interpreted as a compensation for
    `rotate_axes`.
    r    r!   r   -)rotate_axesr5   r6   r7   r*   s       r   r   r   *  sR     s{2rz	2rz	aC2r2t,,2rzr   c                 0    |dv r||| fS |dv r|| |fS | ||fS )z
    Reorder coordinates so that the axes are rotated with *zdir* along
    the original z axis. Prepending the axis with a '-' does the
    inverse transform, so *zdir* can be 'x', '-x', 'y', '-y', 'z' or '-z'.
    )r    z-y)z-xr!   r   r  s       r   r  r  ;  s8     {2rz		2rz2rzr   c                    t        |       dk(  st        |      dk(  rt        j                  d      S t        j                  |dd      }||dk(  rt        j                  |      }n3t        j                  d|t        j
                  |      z
  |z  z
  |d      }t        j                  t        j                  |       t        |      df      }t        j                  |ddddf   |dddf   |z  g      S )z?Modify the alpha values of the color list according to z-depth.r   )r   rW  r   NrW  r#   )
r(   r%   zerosclip	ones_liker   r   r[  r\  r   )r   r7   rV  r  satsrgbas         r   rY  rY  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                 <   t        j                  |       t        j                  |      t        j                  |      }}} t        j                  | ||g      }|t        j                  |      j	                  d          }t        j
                  |d      }t        |      dk  ry||d   z
  dd }|t         j                  j                  |d      ddt         j                  f   z  }t        j
                  |d      }t        |      dk  ryt         j                  j                  t        j                  |d   |dd       d      }t        j                  t        j                  |d|            d   dz   }t        j                  ||d      }t        |      dk  ryt        j                  |d   |d         }|t         j                  j                  |      z  }t        j                  ||j                               }	t        j                   |	d|      S )	a  
    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#   TNrW   )atol)r%   rl   r   isnanrg   uniquer(   linalgnormr   crosswhereisclosedeletedot	transposeallclose)
r5   r6   r7   r  rv   r   cross_normszero_cross_normsndotss
             r   _all_points_on_planer  e  s    BBBBB__b"b\*FRXXf%))q)112FYYvA&F
6{a
6!9
ab	!B	biinnRan(BJJ7	7B	2A	B
2w!|)).."Q%AB!8q.AKxx

; EFqIAM	2'a	0B
2w!|
A1A	BIINN1A 66!R\\^$D;;tQT**r   c                 `   t        | t        j                        rI| j                  d   }d|dz  d|z  dz  }}}| d|ddf   | d|ddf   z
  }| d|ddf   | d|ddf   z
  }nt        j                  t        |       df      }t        j                  t        |       df      }t        |       D ]h  \  }}t        |      }t        j                  |      }d|dz  d|z  dz  }}}||ddf   ||ddf   z
  ||ddf<   ||ddf   ||ddf   z
  ||ddf<   j t        j                  ||      S )aA  
    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#   rW   .N)	r  r%   r  r   r  r(   r  rl   r  )	r,  r  i1i2i3v1v2poly_ipss	            r   r  r    sI   0 (BJJ' NN21ac1fBc2qj!HS"aZ$88c2qj!HS"aZ$88 XXs8}a()XXs8}a()#H- 	2JFBBABBAqD!A#q&BBr1uI2q5	1BvqyMr1uI2q5	1BvqyM	2 88Br   c                   	 |t        j                  dd      }t        j                  d      5  |t        j                  j                  |dd	      z  |j                  z  }ddd       t        j                         }|j                         rt        j                  d
d      t        j                  dd      j                  		fd}d|| <   t        j                  |       } | dddf   } ||      ddt        j                  f   | z  }||dddf<   |S t        j                  |       j                         }|S # 1 sw Y   xY w)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                        |             S r|   r   )r    in_normout_norms    r   r  z_shade_colors.<locals>.norm  s    GAJ''r   r   r#   )r[  LightSourcer%   r  r  r  	directionr  rg   	Normalizeinverser\  r   r   copy)
colorr  r  r  r9   r  r_  r   r-  r.  s
           @@r   r  r    s,    ))GD	X	& *BIINN7TNJJ(()* HHUODxxz##B*$$S!,44	( te%%e, adeQ

]+e3q!t M u%**,M3* *s   3EEr   )r   r"   )r   r"   NF)r+  N)g:0yE>r|   )@r   rn   numpyr%   
contextlibr   
matplotlibr   r   r   r   r[  r   r	   rI   r
   r   r   matplotlib.collectionsr   r   r   r   r   matplotlib.patchesr   r~   r   r   r   r+   r:   rB   rJ   rD   r   Line2Dr   r   r   r   r   r   r   r   r   r  r
  r"  r-  r/  r3  r5  rw  ry  r  r  r  r   r  rY  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   