o
    hh                    @   sZ  d Z ddlmZ ddlZddlZddlZddlZddlZddl	Z
ddl	mZmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z" ddl#m$Z% ddl&m'Z' ddl(m)Z)m*Z* ddl#m+Z+ ddl,m-Z- d	d
l.m/Z/ d	dl.m0Z0 d	dl.m1Z1 ej2e3dgdgdgdG dd de'Z4dddZ5G dd dZ6dS )aR  
axes3d.py, original mplot3d version by John Porter
Created: 23 Sep 2005

Parts fixed by Reinier Heeres <reinier@heeres.eu>
Minor additions by Ben Axelrod <baxelrod@coroware.com>
Significant updates and revisions by Ben Root <ben.v.root@gmail.com>

Module containing Axes3D, an object which can plot 3D objects on a
2D matplotlib figure.
    )defaultdictN)_apicbook
_docstring_preprocess_data)Axes)_axis_method_wrapper_process_plot_format)Bbox)Triangulation   )art3d)proj3d)axis3dxlim3dylim3dzlim3d)xlimylimzlimc                       s  e Zd ZdZdZdZe ej	d< e ej	d< 	d
ddd	ddd
dddd	 fddZ
dd Zdd Zdd Zdd Zdd Zdd ZeddZeddZdd Zd fd!d"	Zd#d$ Zd%d&d'd(Zd
d)d*Zej fd+d,Zd-d. Zd/d0 Zedd1Zedd2Zd3d4 Z d5d6 Z!ddddd7d8d9Z"dd;d<Z#dd=d>Z$		dd?d@Z%dAdB Z&	ddCdDZ'ddEdFZ(ddGdHZ)ddIdJZ*ddd ddddKdLdMZ+ddd ddddNdOdPZ,ddd ddddQdRdSZ-ddd ddddTdUdVZ.e,Z/e-Z0e.Z1dWdX Z2dYdZ Z3d[d\ Z4edd]Z5ed^d_Z6ed`d_Z7edd_Z8e9daj:g d\e6_e7_e8_eddbZ;eddcZ<edddZ=eddeZ>eddfZ?eddgdhdiidjZ@eddkZAeAjrfeA jeBCdl7  _dmdn ZD		 ddodpZEd
dqdrZF	 ddsdtdueGdveHjIfdwdxZJdydz ZKdd}d~ZLdd ZMdd ZNdd ZOdd ZPdd ZQ fddZRdd ZSdd ZTdd ZUdd ZVdd ZWd
ddZXdd ZYdd ZZdd Z[d
ddZ\de]de]dveHjIfddZ^dd Z_dd Z`dd Za		 dddZbdd Zcdd Zddd ZedddZfdd ZgdZhdZidddZjd fdd	Zkdd ZleddZmdd Znd
d d fddZoeoZpejoZqdd d fddĄ
ZrerZsddddd dƜddȄZtddddd dɜdd˄Zud ddd̈́Zvdddddd dΜddЄZwdddӄZx		 dddՄZydd dddׄZzdddلZ{e| d dddd dڜ fdd܄
Z}e}Z~e| d dddd dڜ fddބ
Zdd Ze| ddd d fdd
ZeZe| ddd d fdd
Zdd d fddZe|g dd	dd d fddZeZe| dd d fddZe| 		dd dddZd fdd	Ze| d%ddd d dddZeZddddd dddZe|g dd			 	 	 ddd Zd
ddd d fddZe| dddd	ddd ddd	ZeZ  ZS (   Axes3Da  
    3D Axes object.

    .. note::

        As a user, you do not instantiate Axes directly, but use Axes creation
        methods instead; e.g. from `.pyplot` or `.Figure`:
        `~.pyplot.subplots`, `~.pyplot.subplot_mosaic` or `.Figure.add_axes`.
    3dxyzr   viewN   ir   perspT)	elevazimroll	shareviewsharez	proj_typefocal_length
box_aspectcomputed_zorderc       	            s  |du rg d}|| _ || _|| _| ||	 || _t | _t | _d}t||gd| d| gg| _	t | _
| | j| j | j || _|durW| jd | | d| _|| _|durg| jd | | |dd	rqtd
t j||g|R d|
d| t   |   d| _d| _d| _|   d| _|   | jdd}|jj d| j! |jj d| j" |jj d| j# | $  | j%&d | j'( )ddg}|d |d  \| _*| _+| j,dd -d	 dS )a
  
        Parameters
        ----------
        fig : Figure
            The parent figure.
        rect : tuple (left, bottom, width, height), default: None.
            The ``(left, bottom, width, height)`` Axes position.
        elev : float, default: 30
            The elevation angle in degrees rotates the camera above and below
            the x-y plane, with a positive angle corresponding to a location
            above the plane.
        azim : float, default: -60
            The azimuthal angle in degrees rotates the camera about the z axis,
            with a positive angle corresponding to a right-handed rotation. In
            other words, a positive azimuth rotates the camera about the origin
            from its location along the +x axis towards the +y axis.
        roll : float, default: 0
            The roll angle in degrees rotates the camera about the viewing
            axis. A positive angle spins the camera clockwise, causing the
            scene to rotate counter-clockwise.
        shareview : Axes3D, optional
            Other Axes to share view angles with.  Note that it is not possible
            to unshare axes.
        sharez : Axes3D, optional
            Other Axes to share z-limits with.  Note that it is not possible to
            unshare axes.
        proj_type : {'persp', 'ortho'}
            The projection type, default 'persp'.
        focal_length : float, default: None
            For a projection type of 'persp', the focal length of the virtual
            camera. Must be > 0. If None, defaults to 1.
            For a projection type of 'ortho', must be set to either None
            or infinity (numpy.inf). If None, defaults to infinity.
            The focal length can be computed from a desired Field Of View via
            the equation: focal_length = 1/tan(FOV/2)
        box_aspect : 3-tuple of floats, default: None
            Changes the physical dimensions of the Axes3D, such that the ratio
            of the axis lengths in display units is x:y:z.
            If None, defaults to 4:4:3
        computed_zorder : bool, default: True
            If True, the draw order is computed based on the average position
            of the `.Artist`\s along the view direction.
            Set to False if you want to manually control the order in which
            Artists are drawn on top of each other using their *zorder*
            attribute. This can be used for fine-tuning if the automatic order
            does not produce the desired result. Note however, that a manual
            zorder will only be correct for a limited view angle. If the figure
            is rotated by the user, it will look wrong from certain angles.

        **kwargs
            Other optional keyword arguments:

            %(Axes3D:kwdoc)s
        N)        r(         ?r)   F]tE?r   r   datalimr   auto_add_to_figureFzSauto_add_to_figure is no longer supported for Axes3D. Use fig.add_axes(ax) instead.T)frameonr&   UUUUUU?rootmotion_notify_eventbutton_press_eventbutton_release_eventr   r   r   )r   r   ).initial_aziminitial_elevinitial_rollset_proj_typer'   r
   unit
xy_viewLim
zz_viewLim
xy_dataLim
zz_dataLim	view_init_sharez_shared_axesjoin_adjustable
_shareviewpopAttributeErrorsuper__init__set_axis_offset_axis_onMinvM_view_marginautoscale_view	fmt_zdata
mouse_init
get_figurecanvas	callbacks_connect_picklable_on_move_button_press_button_releaseset_top_viewpatchset_linewidthtransLimitsinverted	transform	_pseudo_w	_pseudo_hspinesset_visible)selffigrectr   r    r!   r"   r#   r$   r%   r&   r'   argskwargsxymarginpseudo_bbox	__class__ o/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/mpl_toolkits/mplot3d/axes3d.pyrG   <   st   ?



zAxes3D.__init__c                 C   s   d| _ d| _d S )NFT	_axis3donstalera   rj   rj   rk   rH         
zAxes3D.set_axis_offc                 C   s   d| _ d| _d S NTrl   ro   rj   rj   rk   rI      rp   zAxes3D.set_axis_onc                 C   s   | j |S )zs
        For artists in an Axes, if the zaxis has units support,
        convert *z* using zaxis unit type
        )zaxisconvert_units)ra   r   rj   rj   rk   convert_zunits   s   zAxes3D.convert_zunitsc                 C   sN   d| j  }d| j  }d| j  }d| j  }| |f| j_| |f| j_d| _d S )Ngffffff?g?T)_distviewLim	intervalx	intervalyrn   )ra   xdwlxdwydwlydwrj   rj   rk   rW      s   




zAxes3D.set_top_viewc                 C   s(   t | | _t | | _t | | _dS )z5Init 3D Axes; overrides creation of regular X/Y Axes.N)r   XAxisxaxisYAxisyaxisZAxisrr   ro   rj   rj   rk   
_init_axis   s   zAxes3D._init_axisc                 C      | j S )z0Return the ``ZAxis`` (`~.axis3d.Axis`) instance.)rr   ro   rj   rj   rk   	get_zaxis   s   zAxes3D.get_zaxisrr   get_gridlinesget_ticklinesc           	   
   C   sb   |\}}}}}}|||f|||f|||f|||f|||f|||f|||f|||fg}t || jS )z:Return cube with limits from *vals* transformed by self.M.)r   _proj_pointsrJ   )	ra   valsminxmaxxminymaxyminzmaxzxyzsrj   rj   rk   _transformed_cube   s   zAxes3D._transformed_cubeFc                    sv  t jd|d t jd|||d || _|dv r| |}t| j	 | j
	 | j	 g}tj|dd}| jdkr~tj|dd}t|| | j|  }	|	| j }
t| j| j| jfD ] \}}||v r{||| |
| d	  || |
| d	  d
dd q[dS t| j}|| ||< h d|}|r| }tj| j| }tj|| }||  || 9  < | | dS dS )aq  
        Set the aspect ratios.

        Parameters
        ----------
        aspect : {'auto', 'equal', 'equalxy', 'equalxz', 'equalyz'}
            Possible values:

            =========   ==================================================
            value       description
            =========   ==================================================
            'auto'      automatic; fill the position rectangle with data.
            'equal'     adapt all the axes to have equal aspect ratios.
            'equalxy'   adapt the x and y axes to have equal aspect ratios.
            'equalxz'   adapt the x and z axes to have equal aspect ratios.
            'equalyz'   adapt the y and z axes to have equal aspect ratios.
            =========   ==================================================

        adjustable : None or {'box', 'datalim'}, optional
            If not *None*, this defines which parameter will be adjusted to
            meet the required aspect. See `.set_adjustable` for further
            details.

        anchor : None or str or 2-tuple of float, optional
            If not *None*, this defines where the Axes will be drawn if there
            is extra space due to aspect constraints. The most common way to
            specify the anchor are abbreviations of cardinal directions:

            =====   =====================
            value   description
            =====   =====================
            'C'     centered
            'SW'    lower left corner
            'S'     middle of bottom edge
            'SE'    lower right corner
            etc.
            =====   =====================

            See `~.Axes.set_anchor` for further details.

        share : bool, default: False
            If ``True``, apply the settings to all shared Axes.

        See Also
        --------
        mpl_toolkits.mplot3d.axes3d.Axes3D.set_box_aspect
        )autoequalequalxyequalyzequalxzaspectr   )r   
adjustableanchorsharer   r   r   r   r   axisr+          @TNr   view_margin>   r   r      )r   check_in_listrF   
set_aspect_aspect_equal_aspect_axis_indicesnparrayr~   get_view_intervalr   rr   ptprB   meanmax_box_aspect	enumerate
set_xlim3d
set_ylim3d
set_zlim3d
differencerD   linalgnormset_box_aspect)ra   r   r   r   r   
ax_indicesview_intervalsr   r   scaledeltasiset_limr&   remaining_ax_indices	remainingold_diagnew_diagrh   rj   rk   r      sL   0


&
zAxes3D.set_aspectc                 C   sT   g }|dkrg d}|S |dkrddg}|S |dkr ddg}|S |dkr(ddg}|S )	a  
        Get the indices for which of the x, y, z axes are constrained to have
        equal aspect ratios.

        Parameters
        ----------
        aspect : {'auto', 'equal', 'equalxy', 'equalxz', 'equalyz'}
            See descriptions in docstring for `.set_aspect()`.
        r   r   r   r   r   r   r   r   r   r   rj   )ra   r   r   rj   rj   rk   r   M  s   
z!Axes3D._equal_aspect_axis_indicesr   )zoomc                C   s~   |dkrt d| d|du rtjdtd}ntj|td}tjd|d |d	| tj| 9 }| j|d
d| _	d
| _
dS )a{  
        Set the Axes box aspect.

        The box aspect is the ratio of height to width in display
        units for each face of the box when viewed perpendicular to
        that face.  This is not to be confused with the data aspect (see
        `~.Axes3D.set_aspect`). The default ratios are 4:4:3 (x:y:z).

        To simulate having equal aspect in data space, set the box
        aspect to match your data range in each dimension.

        *zoom* controls the overall size of the Axes3D in the figure.

        Parameters
        ----------
        aspect : 3-tuple of floats or None
            Changes the physical dimensions of the Axes3D, such that the ratio
            of the axis lengths in display units is x:y:z.
            If None, defaults to (4, 4, 3).

        zoom : float, default: 1
            Control overall size of the Axes3D in the figure. Must be > 0.
        r   zArgument zoom = z must be > 0N)   r      dtype)r   r   g}?Treverse)
ValueErrorr   asarrayfloatr   check_shaper   r   _roll_to_verticalr   rn   )ra   r   r   rj   rj   rk   r   b  s   
zAxes3D.set_box_aspectc                 C   sp   |d u r
| j dd}|  j}tj |}|j|j }d}|	 }|
|||}| ||  |d d S )NT)originalr   active)get_positionrP   transSubfiguremtransformsr
   r9   transformedheightwidthfrozenshrunk_to_aspect_set_positionanchored
get_anchor)ra   positiontransbb
fig_aspectr&   pbpb1rj   rj   rk   apply_aspect  s   
zAxes3D.apply_aspectc           	         s`  |   sd S |   | j| d| _|  }| |r || |nd  |  | _t	j
| j| _dd | jD }| jrutdd | j D d }| }}t|dd dd	D ]}t|tjrf||_|d7 }qVt|tjrs||_|d7 }qVn	|D ]}|  qw| jr| j D ]}|| q| j D ]}|| q| j D ]}|| qt | d S )
NFc                 s   s.    | ]}t |tjtjfr| r|V  qd S N)
isinstancemcoll
CollectionmpatchesPatchget_visible).0artistrj   rj   rk   	<genexpr>  s    
zAxes3D.draw.<locals>.<genexpr>c                 s   s    | ]}|  V  qd S r   )
get_zorder)r   r   rj   rj   rk   r     s    r   c                 S   s   |   S r   )do_3d_projection)r   rj   rj   rk   <lambda>  s    zAxes3D.draw.<locals>.<lambda>T)keyr   )r   _unstale_viewLimrX   draw_frameonget_axes_locatorr   get_projrJ   r   r   invrK   	_childrenr'   r   	_axis_mapvaluessortedr   r   r   zorderr   r   r   rm   	draw_pane	draw_gridrF   )	ra   rendererlocatorcollections_and_patcheszorder_offsetcollection_zorderpatch_zorderr   r   rh   rj   rk   r     sR   




zAxes3D.drawc                 C   s`   |  |  }|d d |d d k}|d d |d d k}|d d |d d k}|||fS )Nr   r   r   r   )r   
get_w_lims)ra   tcxhighyhighzhighrj   rj   rk   get_axis_position  s
   
zAxes3D.get_axis_positionc                 K      dS )zK
        Not implemented in `~mpl_toolkits.mplot3d.axes3d.Axes3D`.
        Nrj   )ra   xysre   rj   rj   rk   update_datalim  s   zAxes3D.update_datalim_get_autoscale_on_set_autoscale_onc                 C   r   )z
        Retrieve autoscaling margin of the z-axis.

        .. versionadded:: 3.9

        Returns
        -------
        zmargin : float

        See Also
        --------
        mpl_toolkits.mplot3d.axes3d.Axes3D.set_zmargin
        )_zmarginro   rj   rj   rk   get_zmargin  s   zAxes3D.get_zmarginc                 C   s*   |dkrt d|| _| d d| _dS )a  
        Set padding of Z data limits prior to autoscaling.

        *m* times the data interval will be added to each end of that interval
        before it is used in autoscaling.  If *m* is negative, this will clip
        the data range instead of expanding it.

        For example, if your data is in the range [0, 2], a margin of 0.1 will
        result in a range [-0.2, 2.2]; a margin of -0.1 will result in a range
        of [0.2, 1.8].

        Parameters
        ----------
        m : float greater than -0.5
        g      z margin must be greater than -0.5r   TN)r   r  _request_autoscale_viewrn   )ra   mrj   rj   rk   set_zmargin  s
   

zAxes3D.set_zmargin)r   r   r   tightc                G   s   |r|dus|dus|durt dt|dkr!|d  } }}nt|dkr-|\}}}n|r3t d|du rT|du rT|du rT|durLtd|d	 | j| j| jfS |dur]| | |durf| | |duro| 	| | j
||du|du|dud
 dS )z
        Set or retrieve autoscaling margins.

        See `.Axes.margins` for full documentation.  Because this function
        applies to 3D Axes, it also takes a *z* argument, and returns
        ``(xmargin, ymargin, zmargin)``.
        NzECannot pass both positional and keyword arguments for x, y, and/or z.r   r   r   zYMust pass a single positional argument for all margins, or one for each margin (x, y, z).Tzignoring tight=z in get mode)r  scalexscaleyscalez)	TypeErrorlenr   warn_external_xmargin_ymarginr  set_xmarginset_ymarginr  rM   )ra   r   r   r   r  marginsrj   rj   rk   r    s,   



zAxes3D.marginsbothc                 C   s   |du rd}d}d}n0|dv r|  | |  }nd}|dv r)| | |  }nd}|dv r9| | |  }nd}|rD| jd|d |rM| jd	|d |rX| jd
|d dS dS )a  
        Convenience method for simple axis view autoscaling.

        See `.Axes.autoscale` for full documentation.  Because this function
        applies to 3D Axes, *axis* can also be set to 'z', and setting *axis*
        to 'both' autoscales all three axes.
        NT)r   r  F)r   r  r   r  r   )r  r   r   )set_autoscalex_onget_autoscalex_onset_autoscaley_onget_autoscaley_onset_autoscalez_onget_autoscalez_onr  )ra   enabler   r  r  r  r  rj   rj   rk   	autoscale2  s.   





zAxes3D.autoscalec                 C   s   t |t |kr| jt t |t |g|  n| j||  | j||  |d ur:| j||  | 	  d S r   )
r   shaper<   update_from_data_xycolumn_stackravelupdate_from_data_xupdate_from_data_yr=   rM   )ra   XYZhad_datarj   rj   rk   auto_scale_xyzU  s   zAxes3D.auto_scale_xyzc                 C   s  |du r&| j }|s%| jD ]}t|tjrd}qt|tjtjfr$d} nqnt	| }| _ |rl| 
 rl| jj\}}| j }	|	||\}}| jdkrZ|| | j }
||
8 }||
7 }|sd|	||\}}| ||| j |r|  r| jj\}}| j }|||\}}| jdkr|| | j }
||
8 }||
7 }|s|||\}}| ||| j |r|  r| jj\}}| j }|||\}}| jdkr|| | j }
||
8 }||
7 }|s|||\}}| ||| j dS dS dS )z
        Autoscale the view limits using the data limits.

        See `.Axes.autoscale_view` for full documentation.  Because this
        function applies to 3D Axes, it also takes a *scalez* argument.
        NTFr   )_tightr   r   mimage	AxesImagemlinesLine2Dr   r   boolr   r<   rw   r~   get_major_locatornonsingularr  view_limits
set_xboundrL   r"  rx   r   r  
set_yboundr$  r=   rr   r  
set_zbound)ra   r  r  r  r  r2  r   x0x1xlocatordeltay0y1ylocatorz0z1zlocatorrj   rj   rk   rM   c  s\   







zAxes3D.autoscale_viewc                 C   s4   |   \}}|  \}}|  \}}||||||fS )zGet 3D world limits.)
get_xlim3d
get_ylim3d
get_zlim3d)ra   r   r   r   r   r   r   rj   rj   rk   r    s   zAxes3D.get_w_limsc           	      C   s`   |du rt |r|\}}| \}}|du r|}|du r|}|t||ft| dd|d dS )z%
        Set 3D axis bounds.
        Nr   r   )r   iterabler   r7  )	ra   	get_boundr   axis_invertedlowerupperr   	old_lower	old_upperrj   rj   rk   _set_bound3d  s   

zAxes3D._set_bound3dc                 C      |  | j| j| j||| dS )a  
        Set the lower and upper numerical bounds of the x-axis.

        This method will honor axis inversion regardless of parameter order.
        It will not change the autoscaling setting (`.get_autoscalex_on()`).

        Parameters
        ----------
        lower, upper : float or None
            The lower and upper bounds. If *None*, the respective axis bound
            is not modified.
        view_margin : float or None
            The margin to apply to the bounds. If *None*, the margin is handled
            by `.set_xlim`.

        See Also
        --------
        get_xbound
        get_xlim, set_xlim
        invert_xaxis, xaxis_inverted
        N)rR  
get_xboundset_xlimxaxis_invertedra   rN  rO  r   rj   rj   rk   r;       zAxes3D.set_xboundc                 C   rS  )a  
        Set the lower and upper numerical bounds of the y-axis.

        This method will honor axis inversion regardless of parameter order.
        It will not change the autoscaling setting (`.get_autoscaley_on()`).

        Parameters
        ----------
        lower, upper : float or None
            The lower and upper bounds. If *None*, the respective axis bound
            is not modified.
        view_margin : float or None
            The margin to apply to the bounds. If *None*, the margin is handled
            by `.set_ylim`.

        See Also
        --------
        get_ybound
        get_ylim, set_ylim
        invert_yaxis, yaxis_inverted
        N)rR  
get_yboundset_ylimyaxis_invertedrW  rj   rj   rk   r<    rX  zAxes3D.set_yboundc                 C   rS  )a  
        Set the lower and upper numerical bounds of the z-axis.
        This method will honor axis inversion regardless of parameter order.
        It will not change the autoscaling setting (`.get_autoscaley_on()`).

        Parameters
        ----------
        lower, upper : float or None
            The lower and upper bounds. If *None*, the respective axis bound
            is not modified.
        view_margin : float or None
            The margin to apply to the bounds. If *None*, the margin is handled
            by `.set_zlim`.

        See Also
        --------
        get_zbound
        get_zlim, set_zlim
        invert_zaxis, zaxis_inverted
        N)rR  
get_zboundset_zlimzaxis_invertedrW  rj   rj   rk   r=    s   zAxes3D.set_zboundemitr   r   axminaxmaxc          
      C   s   |du rt |r|\}}n
|du r| d }|du r&|du r&| d }|dur4|dur2td|}|durB|dur@td|}t |sLt |rWtd| d| d|du rftjd	 rd| j}nd}|| | }	||	8 }||	7 }|j	||||d
S )z%
        Set 3D axis limits.
        Nr   r   z"Cannot pass both 'lower' and 'min'z"Cannot pass both 'upper' and 'max'zAxis limits z, z cannot be infinitezaxes3d.automarginr`  r   )
r   rK  r   r  isinfr   mplrcParamsrL   _set_lim)
ra   r   rN  rO  r`  r   r   ra  rb  rA  rj   rj   rk   
_set_lim3d   s2   


zAxes3D._set_lim3d)r`  r   r   xminxmaxc             
   C      | j | j|||||||dS )aX  
        Set the 3D x-axis view limits.

        Parameters
        ----------
        left : float, optional
            The left xlim in data coordinates. Passing *None* leaves the
            limit unchanged.

            The left and right xlims may also be passed as the tuple
            (*left*, *right*) as the first positional argument (or as
            the *left* keyword argument).

            .. ACCEPTS: (left: float, right: float)

        right : float, optional
            The right xlim in data coordinates. Passing *None* leaves the
            limit unchanged.

        emit : bool, default: True
            Whether to notify observers of limit change.

        auto : bool or None, default: False
            Whether to turn on autoscaling of the x-axis. *True* turns on,
            *False* turns off, *None* leaves unchanged.

        view_margin : float, optional
            The additional margin to apply to the limits.

        xmin, xmax : float, optional
            They are equivalent to left and right respectively, and it is an
            error to pass both *xmin* and *left* or *xmax* and *right*.

        Returns
        -------
        left, right : (float, float)
            The new x-axis limits in data coordinates.

        See Also
        --------
        get_xlim
        set_xbound, get_xbound
        invert_xaxis, xaxis_inverted

        Notes
        -----
        The *left* value may be greater than the *right* value, in which
        case the x-axis values will decrease from *left* to *right*.

        Examples
        --------
        >>> set_xlim(left, right)
        >>> set_xlim((left, right))
        >>> left, right = set_xlim(left, right)

        One limit may be left unchanged.

        >>> set_xlim(right=right_lim)

        Limits may be passed in reverse order to flip the direction of
        the x-axis. For example, suppose ``x`` represents depth of the
        ocean in m. The x-axis limits might be set like the following
        so 5000 m depth is at the left of the plot and the surface,
        0 m, is at the right.

        >>> set_xlim(5000, 0)
        r_  )rh  r~   )ra   leftrightr`  r   r   ri  rj  rj   rj   rk   rU        EzAxes3D.set_xlim)r`  r   r   yminymaxc             
   C   rk  )aV  
        Set the 3D y-axis view limits.

        Parameters
        ----------
        bottom : float, optional
            The bottom ylim in data coordinates. Passing *None* leaves the
            limit unchanged.

            The bottom and top ylims may also be passed as the tuple
            (*bottom*, *top*) as the first positional argument (or as
            the *bottom* keyword argument).

            .. ACCEPTS: (bottom: float, top: float)

        top : float, optional
            The top ylim in data coordinates. Passing *None* leaves the
            limit unchanged.

        emit : bool, default: True
            Whether to notify observers of limit change.

        auto : bool or None, default: False
            Whether to turn on autoscaling of the y-axis. *True* turns on,
            *False* turns off, *None* leaves unchanged.

        view_margin : float, optional
            The additional margin to apply to the limits.

        ymin, ymax : float, optional
            They are equivalent to bottom and top respectively, and it is an
            error to pass both *ymin* and *bottom* or *ymax* and *top*.

        Returns
        -------
        bottom, top : (float, float)
            The new y-axis limits in data coordinates.

        See Also
        --------
        get_ylim
        set_ybound, get_ybound
        invert_yaxis, yaxis_inverted

        Notes
        -----
        The *bottom* value may be greater than the *top* value, in which
        case the y-axis values will decrease from *bottom* to *top*.

        Examples
        --------
        >>> set_ylim(bottom, top)
        >>> set_ylim((bottom, top))
        >>> bottom, top = set_ylim(bottom, top)

        One limit may be left unchanged.

        >>> set_ylim(top=top_lim)

        Limits may be passed in reverse order to flip the direction of
        the y-axis. For example, suppose ``y`` represents depth of the
        ocean in m. The y-axis limits might be set like the following
        so 5000 m depth is at the bottom of the plot and the surface,
        0 m, is at the top.

        >>> set_ylim(5000, 0)
        r_  )rh  r   )ra   bottomtopr`  r   r   ro  rp  rj   rj   rk   rZ  h  rn  zAxes3D.set_ylim)r`  r   r   zminzmaxc             
   C   rk  )aV  
        Set the 3D z-axis view limits.

        Parameters
        ----------
        bottom : float, optional
            The bottom zlim in data coordinates. Passing *None* leaves the
            limit unchanged.

            The bottom and top zlims may also be passed as the tuple
            (*bottom*, *top*) as the first positional argument (or as
            the *bottom* keyword argument).

            .. ACCEPTS: (bottom: float, top: float)

        top : float, optional
            The top zlim in data coordinates. Passing *None* leaves the
            limit unchanged.

        emit : bool, default: True
            Whether to notify observers of limit change.

        auto : bool or None, default: False
            Whether to turn on autoscaling of the z-axis. *True* turns on,
            *False* turns off, *None* leaves unchanged.

        view_margin : float, optional
            The additional margin to apply to the limits.

        zmin, zmax : float, optional
            They are equivalent to bottom and top respectively, and it is an
            error to pass both *zmin* and *bottom* or *zmax* and *top*.

        Returns
        -------
        bottom, top : (float, float)
            The new z-axis limits in data coordinates.

        See Also
        --------
        get_zlim
        set_zbound, get_zbound
        invert_zaxis, zaxis_inverted

        Notes
        -----
        The *bottom* value may be greater than the *top* value, in which
        case the z-axis values will decrease from *bottom* to *top*.

        Examples
        --------
        >>> set_zlim(bottom, top)
        >>> set_zlim((bottom, top))
        >>> bottom, top = set_zlim(bottom, top)

        One limit may be left unchanged.

        >>> set_zlim(top=top_lim)

        Limits may be passed in reverse order to flip the direction of
        the z-axis. For example, suppose ``z`` represents depth of the
        ocean in m. The z-axis limits might be set like the following
        so 5000 m depth is at the bottom of the plot and the surface,
        0 m, is at the top.

        >>> set_zlim(5000, 0)
        r_  )rh  rr   )ra   rq  rr  r`  r   r   rs  rt  rj   rj   rk   r]    rn  zAxes3D.set_zlimc                 C      t | jjS r   )tupler:   rw   ro   rj   rj   rk   get_xlim     zAxes3D.get_xlimc                 C   ru  r   )rv  r:   rx   ro   rj   rj   rk   get_ylim   rx  zAxes3D.get_ylimc                 C   ru  )a  
        Return the 3D z-axis view limits.

        Returns
        -------
        left, right : (float, float)
            The current z-axis limits in data coordinates.

        See Also
        --------
        set_zlim
        set_zbound, get_zbound
        invert_zaxis, zaxis_inverted

        Notes
        -----
        The z-axis may be inverted, in which case the *left* value will
        be greater than the *right* value.
        )rv  r;   rw   ro   rj   rj   rk   get_zlim  s   zAxes3D.get_zlim	get_scaler~   _set_axes_scaler   a  
        Set the {}-axis scale.

        Parameters
        ----------
        value : {{"linear"}}
            The axis scale type to apply.  3D Axes currently only support
            linear scales; other scales yield nonsensical results.

        **kwargs
            Keyword arguments are nominally forwarded to the scale class, but
            none of them is applicable for linear scales.
        get_ticklocs	set_ticksget_majorticklabelsget_minorticklabelsget_ticklabelsset_ticklabelszAxis.set_tickszAxes3D.set_zticks)doc_sub	axis_datez

        Notes
        -----
        This function is merely provided for completeness, but 3D Axes do not
        support dates for ticks, and so this may not work as expected.
        c                 O   r  )z:Currently not implemented for 3D Axes, and returns *None*.Nrj   )ra   rd   re   rj   rj   rk   clabelC     zAxes3D.clabelc                 C   s   d| _ |du r
| j}|du r| j}|du r| j}tjdd t| jD |d}|r7dd | jd 	| D }n| g}|D ]}||_
||_||_||_q<dS )	a  
        Set the elevation and azimuth of the Axes in degrees (not radians).

        This can be used to rotate the Axes programmatically.

        To look normal to the primary planes, the following elevation and
        azimuth angles can be used. A roll angle of 0, 90, 180, or 270 deg
        will rotate these views while keeping the axes at right angles.

        ==========   ====  ====
        view plane   elev  azim
        ==========   ====  ====
        XY           90    -90
        XZ           0     -90
        YZ           0     0
        -XY          -90   90
        -XZ          0     90
        -YZ          0     180
        ==========   ====  ====

        Parameters
        ----------
        elev : float, default: None
            The elevation angle in degrees rotates the camera above the plane
            pierced by the vertical axis, with a positive angle corresponding
            to a location above that plane. For example, with the default
            vertical axis of 'z', the elevation defines the angle of the camera
            location above the x-y plane.
            If None, then the initial value as specified in the `Axes3D`
            constructor is used.
        azim : float, default: None
            The azimuthal angle in degrees rotates the camera about the
            vertical axis, with a positive angle corresponding to a
            right-handed rotation. For example, with the default vertical axis
            of 'z', a positive azimuth rotates the camera about the origin from
            its location along the +x axis towards the +y axis.
            If None, then the initial value as specified in the `Axes3D`
            constructor is used.
        roll : float, default: None
            The roll angle in degrees rotates the camera about the viewing
            axis. A positive angle spins the camera clockwise, causing the
            scene to rotate counter-clockwise.
            If None, then the initial value as specified in the `Axes3D`
            constructor is used.
        vertical_axis : {"z", "x", "y"}, default: "z"
            The axis to align vertically. *azim* rotates about this axis.
        share : bool, default: False
            If ``True``, apply the settings to all Axes with shared views.
        
   Nc                 S   s   i | ]\}}||qS rj   rj   )r   idxnamerj   rj   rk   
<dictcomp>  s    z$Axes3D.view_init.<locals>.<dictcomp>)vertical_axisc                 S   s   h | ]}|qS rj   rj   )r   siblingrj   rj   rk   	<setcomp>  s    z#Axes3D.view_init.<locals>.<setcomp>r   )ru   r6   r5   r7   r   check_getitemr   _axis_namesr@   get_siblingsr   r    r!   _vertical_axis)ra   r   r    r!   r  r   axesaxrj   rj   rk   r>   G  s,   4zAxes3D.view_initc                 C   sx   t jddg|d |dkr%|du rd}n|dkr td| d|| _dS |dtjfvr6td| d	| tj| _dS )
a  
        Set the projection type.

        Parameters
        ----------
        proj_type : {'persp', 'ortho'}
            The projection type.
        focal_length : float, default: None
            For a projection type of 'persp', the focal length of the virtual
            camera. Must be > 0. If None, defaults to 1.
            The focal length can be computed from a desired Field Of View via
            the equation: focal_length = 1/tan(FOV/2)
        r   ortho)r$   Nr   r   zfocal_length = z must be greater than 0z must be None for proj_type = )r   r   r   _focal_lengthr   inf)ra   r$   r%   rj   rj   rk   r8     s   

zAxes3D.set_proj_typearrznp.typing.ArrayLiker   returnc                 C   s,   |rt || jd d S t || jd S )z
        Roll arrays to match the different vertical axis.

        Parameters
        ----------
        arr : ArrayLike
            Array to roll.
        reverse : bool, default: False
            Reverse the direction of the roll.
        r   )r   r!   r  )ra   r  r   rj   rj   rk   r     s   zAxes3D._roll_to_verticalc                 C   sN  |  | j}tjg |  |  |  R d|i}d| }t| j	}t| j
}t|t| }t|t| }t|}|  |||g}	|| j|	  }
| |
\}}}|| _|| _|| _| jtjkr|t||||
}t| j | j}n|| j|	 | j  }t||||}t| j | j| j}t||}t||}|S )z?Create the projection matrix from the current viewing position.	pb_aspect      ?)r   r   r   world_transformationrH  rI  rJ  r   deg2radr   r    cossinru   _calc_view_axes_view_u_view_v_view_wr  r  _view_transformation_uvw_ortho_transformation_persp_transformationdot)ra   r&   worldMRelev_radazim_radp0p1p2pseyeuvwviewMprojM	eye_focalM0rJ   rj   rj   rk   r     sD   

zAxes3D.get_projr   r   c                 C   s:   d| _ t| | _t| | _t| | _dS )a  
        Set the mouse buttons for 3D rotation and zooming.

        Parameters
        ----------
        rotate_btn : int or list of int, default: 1
            The mouse button or buttons to use for 3D rotation of the Axes.
        pan_btn : int or list of int, default: 2
            The mouse button or buttons to use to pan the 3D Axes.
        zoom_btn : int or list of int, default: 3
            The mouse button or buttons to use to zoom the 3D Axes.
        N)button_pressedr   
atleast_1dtolist_rotate_btn_pan_btn	_zoom_btn)ra   
rotate_btnpan_btnzoom_btnrj   rj   rk   rO     s   zAxes3D.mouse_initc                 C   s   | j g g g d dS )z<Disable mouse buttons for 3D rotation, panning, and zooming.)r  r  r  N)rO   ro   rj   rj   rk   disable_mouse_rotation  s   zAxes3D.disable_mouse_rotationc                 C   r  rq   rj   ro   rj   rj   rk   can_zoom  r  zAxes3D.can_zoomc                 C   r  rq   rj   ro   rj   rj   rk   can_pan  r  zAxes3D.can_panc                 C   s   t jt|d | jdur|| jurtd| jd | | || _|jj| j_|jj	| j_	|
 \}}| j||d| d |jj| j_dS )a  
        Share the z-axis with *other*.

        This is equivalent to passing ``sharez=other`` when constructing the
        Axes, and cannot be used if the z-axis is already being shared with
        another Axes.  Note that it is not possible to unshare axes.
        otherNzz-axis is already sharedr   Frc  )r   check_isinstancer   r?   r   r@   rA   rr   majorminorrz  r]  r$  _scale)ra   r  rE  rF  rj   rj   rk   r#     s   zAxes3D.sharezc                 C   sl   t jt|d | jdur|| jurtd| jd | | || _| j|j }| j	|j
|j|j|dd dS )a  
        Share the view angles with *other*.

        This is equivalent to passing ``shareview=other`` when constructing the
        Axes, and cannot be used if the view angles are already being shared
        with another Axes.  Note that it is not possible to unshare axes.
        r  Nzview angles are already sharedr   Tr   r    r!   r  r   )r   r  r   rC   r   r@   rA   r  r  r>   r   r    r!   )ra   r  r  rj   rj   rk   r"   1  s   
zAxes3D.shareviewc                    sx   t    | jtjkrtjd | _nd| _d}t||gd| d| gg| _	t
 | _d| _|   | tjd  d S )Nzaxes.zmarginr(   r*   r   r.   zaxes3d.grid)rF   clearr  r   r  re  rf  r  r
   r<   r9   r=   rL   rM   grid)ra   rf   rh   rj   rk   r  B  s   

zAxes3D.clearc                 C   sl   |j | kr2|j| _|j|j| _| _| jddjj	}|r&|
 d u r&|  |r4||| d S d S d S NTr/   )inaxesbuttonr  xdataydata_sx_syrP   rQ   toolbar
_nav_stackpush_currentset_message_mouse_event_to_messagera   eventr  rj   rj   rk   rU   T  s   
zAxes3D._button_pressc                 C   sJ   d | _ | jddjj}|r|  d u r|  |r#||| d S d S r  )r  rP   rQ   r  get_navigate_moder  r  r  r  rj   rj   rk   rV   ^  s   zAxes3D._button_releasec                 C   s:   |   |  |  |  |  |  d| j| j| jffS )N)r   autoscalex_onr   autoscaley_onr   autoscalez_on)	rw  r   ry  r"  rz  r$  r   r    r!   ro   rj   rj   rk   	_get_viewh  s   zAxes3D._get_viewc                 C   s4   |\}\}}}| j di | || _|| _|| _d S )Nrj   )setr   r    r!   )ra   r   propsr   r    r!   rj   rj   rk   	_set_viewp  s
   
zAxes3D._set_viewc              	   C   s<   z|  |W S  ttfy   | j j}||}| Y S w )z
        Return *z* string formatted.  This function will use the
        :attr:`fmt_zdata` attribute if it is callable, else will fall
        back on the zaxis major formatter
        )rN   rE   r  rr   get_major_formatterformat_data_short)ra   r   funcvalrj   rj   rk   format_zdatax  s   zAxes3D.format_zdatac                 C   s8   d}| j | jv r|  }|S | jdur| |||}|S )z
        Return a string giving the current view rotation angles, or the x, y, z
        coordinates of the point on the nearest axis pane underneath the mouse
        cursor, depending on the mouse button pressed.
         N)r  r  _rotation_coordsrJ   _location_coords)ra   xvyvr   coordsrj   rj   rk   format_coord  s   
zAxes3D.format_coordc                 C   sN   t | j}t | j}t | j}d|dd|dd|dddd}|S )z9
        Return the rotation angles as a string.
        z
elevation=z.0fu   °, azimuth=u	   °, roll=   °-u   −)r   _norm_angler   r    r!   replace)ra   	norm_elev	norm_azim	norm_rollr  rj   rj   rk   r    s   
zAxes3D._rotation_coordsc           
      C   s   |  |||\}}| |d }| |d }| |d }|dkr/d| d| d| }	|	S |dkr@d| d| d| }	|	S |dkrOd| d| d	| }	|	S )
zY
        Return the location on the axis pane underneath the cursor as a string.
        r   r   r   zx pane=z, y=z, z=zx=z	, y pane=z	, z pane=)_calc_coordformat_xdataformat_ydatar  )
ra   r  r  r   r  pane_idxxsyszsr  rj   rj   rk   r    s   zAxes3D._location_coordsc                 C   sn   |   \}}}}}}t|||g}t|||g}| jtjkr#d}	n| j}	|| j| j | | j |	  }
|
S )zJ
        Returns the current camera location in data coordinates.
        g    eA)_get_w_centers_rangesr   r   r  r  r  ru   r   )ra   cxcyczdxdydzcrr%   r  rj   rj   rk   _get_camera_loc  s   zAxes3D._get_camera_locc                 C   s   | j tjkr	d}nd| j  }tt|||| j }|  | }g }| j	
 D ]}| \}	}
||
 q)td}tdD ]}|| dkrNtj||< q@|| ||  ||  ||< q@tt|}|| }|||  }||fS )z
        Given the 2D view coordinates, find the point on the nearest axis pane
        that lies directly below those coordinates. Returns a 3D point in data
        coordinates.
        r   r  r   r   )r  r   r  r   r   inv_transformrK   r*  r  r   r   active_paneappendzerosrangeargminabs)ra   r  r  r   zvr  vec	pane_locsr   r  locscalesr   r  r   r  rj   rj   rk   r    s$   

zAxes3D._calc_coordr   r   c                 C   s   t jd d }t jd | }|| }|| }|| ||  }t|}d| }|d|d   }d|d|   }	||	k rJttd| ||g}
|
S ||k ro|| }t|t|| ||   ||g}
|
tj|
 }
|
S td|| || g}
|
S )au  
        Convert a point (x, y) to a point on a virtual trackball.

        This is Ken Shoemake's arcball (a sphere), modified
        to soften the abrupt edge (optionally).
        See: Ken Shoemake, "ARCBALL: A user interface for specifying
        three-dimensional rotation using a mouse." in
        Proceedings of Graphics Interface '92, 1992, pp. 151-156,
        https://doi.org/10.20380/GI1992.18
        The smoothing of the edge is inspired by Gavin Bell's arcball
        (a sphere combined with a hyperbola), but here, the sphere
        is combined with a section of a cylinder, so it has finite support.
        axes3d.trackballsizer   zaxes3d.trackballborderr   r   )re  rf  r   sqrtr   r   r   )ra   r   r   sbr2r  raaripdrrj   rj   rk   _arcball  s&   
&zAxes3D._arcballc                 C   s  | j sdS |  durdS | jdu rdS |j|j}}|du s$|j| kr&dS || j || j }}| j}| j	}| j | j
v r|dkrH|dkrHdS tjd }|dkrt| j}	||  d t|	 || d t|	  }
||  d t|	 || d t|	  }| j|
 }| j| }| j}	nvtjt| j| j| jf }|dkrtd| | || g}tj|}|tjd  }tt||t| | }n,| | j| | j| }| || || }|dkrt||}ntd|td|  }|| }t| \}}}	| j| j }| j|||	|d	d
 d	| _ n=| j | j!v rF| j"#| j| jg\}}| $||d | %dd|j&|j' | (  n| j | j)v rZ|||  }| *||| ||| _| _| j+d	dj,-  dS )z
        Mouse moving.

        By default, button-1 rotates, button-2 pans, and button-3 zooms;
        these buttons can be modified via `mouse_init`.
        Nr   zaxes3d.mouserotationstyleazel   	trackballr  sphereTr  r   r/   ).r  r  rJ   r  r  r  r  r  r]   r^   r  re  rf  r   r  r!   r  r  r   r    _Quaternionfrom_cardan_anglesr   r   r   r  rotate_from_torad2degas_cardan_anglesr  r  r>   rn   r  	transDatar\   	start_pandrag_panr   r   end_panr  _scale_axis_limitsrP   rQ   	draw_idle)ra   r  r   r   r  r  r  hstyler!   delevdazimr   r    qknkthdqcurrent_vecnew_vecr  pxpyr   rj   rj   rk   rT     sr   

..

 
zAxes3D._on_movec                 C   s\  | j }|j||f|j|jfg\\}}\}}	||| _| _| ||| || ||	 }
}d}|dkr7d}n|dkr=d}
|
dkrG|dkrGd S t	| j
| j| jg}| | j | j }|jt	|
||g }|  \}}}}}}|| |d  }|| |d  }|| |d  }| j|| || d d | j|| || d d | j|| || d d d S )Nr   r   r   r   r   r   )
_pan_starttrans_inverser\   r   r   r  r  r(  r   r   r  r  r  r   ru   Tr  r   r   r   )ra   r  r   r   r   r  r  r  xdata_startydata_startdudvdwr  duvw_projectedr   r   r   r   r   r   r  r  r  rj   rj   rk   r)  f  s0   zAxes3D.drag_panc           	      C   s~   t t| j}t t| j}d| | j }t d}t	|t j
d kr*dnd|| j< t||||\}}}|||fS )z
        Get the unit vectors for the viewing axes in data coordinates.
        `u` is towards the right of the screen
        `v` is towards the top of the screen
        `w` is out of the screen
        r  r   r   r  r   )r   r  r   r  r   r!   r   r   r
  r  pir  r   
_view_axes)	ra   r  r  roll_radr  Vr  r  r  rj   rj   rk   r    s   
 
zAxes3D._calc_view_axesinc                 C   s  |\}}}}	|dkr| j jd }| j jd }	n|dkr'| j jd }| j jd }tt||g| j jd | j jd \}}tt||	g| j jd | j jd \}}	|| d }
||	 d }| j jd | j jd  d }| j jd | j jd  d }| |
|d | dd|| |   t	|| }t	||	 }|| j jd | j jd   }|| j jd | j jd   }t||}|dkrd| }| 
||| dS )z
        Zoom in or out of the bounding box.

        Will center the view in the center of the bounding box, and zoom by
        the ratio of the size of the bounding box to the size of the Axes3D.
        r   r   r   r   r   Nout)bboxminr   r   clipr   r(  r)  r*  r  _zoom_data_limits)ra   rJ  	directionmodetwinxtwinystart_xstart_ystop_xstop_yzoom_center_xzoom_center_yax_center_xax_center_yr  r  scale_uscale_vr   rj   rj   rk   _set_view_from_bbox  s8   
zAxes3D._set_view_from_bboxc           	      C   s   t |||g}t ||sJt | j| j| jg}|t d }t jj|j	| dd}| j
dv rJ| | j
}t t || d }|| | ||< | |d |d |d  dS )a  
        Zoom in or out of a 3D plot.

        Will scale the data limits by the scale factors. These will be
        transformed to the x, y, z data axes based on the current view angles.
        A scale factor > 1 zooms out and a scale factor < 1 zooms in.

        For an Axes that has had its aspect ratio set to 'equal', 'equalxy',
        'equalyz', or 'equalxz', the relevant axes are constrained to zoom
        equally.

        Parameters
        ----------
        scale_u : float
            Scale factor for the u view axis (view screen horizontal).
        scale_v : float
            Scale factor for the v view axis (view screen vertical).
        scale_w : float
            Scale factor for the w view axis (view screen depth).
        r   r   r   r   r   r   N)r   r   allcloser  r  r  r  r   r   r=  r   r   r  r  r+  )	ra   rZ  r[  scale_wr   r  Sax_idxsmin_ax_idxsrj   rj   rk   rM    s   
zAxes3D._zoom_data_limitsc           
      C   s   |   \}}}}}}	| j||| d  ||| d  dd | j||| d  ||| d  dd | j||	| d  ||	| d  dd dS )a  
        Keeping the center of the x, y, and z data axes fixed, scale their
        limits by scale factors. A scale factor > 1 zooms out and a scale
        factor < 1 zooms in.

        Parameters
        ----------
        scale_x : float
            Scale factor for the x data axis.
        scale_y : float
            Scale factor for the y data axis.
        scale_z : float
            Scale factor for the z data axis.
        r   Nr:  )r  r   r   r   )
ra   scale_xscale_yscale_zr  r  r   r  r  r  rj   rj   rk   r+    s   ((,zAxes3D._scale_axis_limitsc                 C   s`   |   \}}}}}}|| d }|| d }|| d }	|| }
|| }|| }|||	|
||fS )z%Get 3D world centers and axis ranges.r   )r  )ra   r   r   r   r   r   r   r  r  r   r  r  r  rj   rj   rk   r    s   zAxes3D._get_w_centers_rangesc                 K   s&   |dur|| j _| j j||fi |S )zI
        Set zlabel.  See doc for `.set_ylabel` for description.
        N)rr   labelpadset_label_text)ra   zlabelfontdictre  re   rj   rj   rk   
set_zlabel  s   zAxes3D.set_zlabelc                 C   s   | j j}| S )z.
        Get the z-label text string.
        )rr   labelget_text)ra   rj  rj   rj   rk   
get_zlabel#  s   zAxes3D.get_zlabelc                 K   s   t |rd}|| _d| _dS )z
        Set / unset 3D grid.

        .. note::

            Currently, this function does not behave the same as
            `.axes.Axes.grid`, but it is intended to eventually support that
            behavior.
        TN)r  
_draw_gridrn   )ra   visiblere   rj   rj   rk   r  1  s   
zAxes3D.gridc                    s   t jg d|d |dv rt j|fi | |dv rBt|}|dd |dd |dd |d	d | jjd
i | dS dS )ax  
        Convenience method for changing the appearance of ticks and
        tick labels.

        See `.Axes.tick_params` for full documentation.  Because this function
        applies to 3D Axes, *axis* can also be set to 'z', and setting *axis*
        to 'both' autoscales all three axes.

        Also, because of how Axes3D objects are drawn very differently
        from regular 2D Axes, some of these settings may have
        ambiguous meaning.  For simplicity, the 'z' axis will
        accept settings as if it was like the 'y' axis.

        .. note::
           Axes3D currently ignores some of these settings.
        )r   r   r   r  r   )r   r   r  r  rr  Nrq  labeltoplabelbottomrj   )r   r   rF   tick_paramsdictrD   rr   set_tick_params)ra   r   re   zkwrh   rj   rk   rq  A  s   zAxes3D.tick_paramsc                 C   s    |   \}}| j||dd dS )z
        Invert the z-axis.

        See Also
        --------
        zaxis_inverted
        get_zlim, set_zlim
        get_zbound, set_zbound
        Nr:  )rz  r]  )ra   rq  rr  rj   rj   rk   invert_zaxis_  s   
zAxes3D.invert_zaxisget_invertedc                 C   s$   |   \}}||k r||fS ||fS )z
        Return the lower and upper z-axis bounds, in increasing order.

        See Also
        --------
        set_zbound
        get_zlim, set_zlim
        invert_zaxis, zaxis_inverted
        )rz  )ra   rN  rO  rj   rj   rk   r\  n  s   
zAxes3D.get_zbound)
axlim_clipc          	         s,   t  j|||fi |}t|||| |S )a  
        Add the text *s* to the 3D Axes at location *x*, *y*, *z* in data coordinates.

        Parameters
        ----------
        x, y, z : float
            The position to place the text.
        s : str
            The text.
        zdir : {'x', 'y', 'z', 3-tuple}, optional
            The direction to be used as the z-direction. Default: 'z'.
            See `.get_dir_vector` for a description of the values.
        axlim_clip : bool, default: False
            Whether to hide text that is outside the axes view limits.

            .. versionadded:: 3.10
        **kwargs
            Other arguments are forwarded to `matplotlib.axes.Axes.text`.

        Returns
        -------
        `.Text3D`
            The created `.Text3D` instance.
        )rF   textr   text_2d_to_3d)	ra   r   r   r   r  zdirrw  re   rx  rh   rj   rk   rx  ~  s   zAxes3D.text)rz  rw  c                   s   |   }|rt|d ts|^}}d|v rtdn|dd}t|||\}}}t j||g|R i |}	|	D ]}
t	j
|
|||d q:t	||||\}}}| |||| |	S )a  
        Plot 2D or 3D data.

        Parameters
        ----------
        xs : 1D array-like
            x coordinates of vertices.
        ys : 1D array-like
            y coordinates of vertices.
        zs : float or 1D array-like
            z coordinates of vertices; either one for all points or one for
            each point.
        zdir : {'x', 'y', 'z'}, default: 'z'
            When plotting 2D data, the direction to use as z.
        axlim_clip : bool, default: False
            Whether to hide data that is outside the axes view limits.

            .. versionadded:: 3.10
        **kwargs
            Other arguments are forwarded to `matplotlib.axes.Axes.plot`.
        r   r  z,plot() for multiple values for argument 'zs'r  rz  rw  )has_datar   strr  rD   r   _broadcast_with_masksrF   plotr   line_2d_to_3djuggle_axesr1  )ra   r  r  rz  rw  rd   re   r0  r  lineslinerh   rj   rk   r    s   zAxes3D.plotr   )whererO  
facecolorsshaderw  c             	   K   sP  t jg d|d |  }t||||||\}}}}}}|	du r'| j g}	tt	|	}	|du r5d}nt
j|td}|j|jkrOtd|j d|j d|t
| @ }|d	krtjt
|| || ft
|| || ft
|| || fd
drd}nd}|
du r|dkrd}
nd}
g }t|D ]\}}||| }||| }||| }||| }||| }||| }t|sq|dkrSt|d }t
|ddf}t
|dd |dd |dd f|dddddf< t
|dd |dd |dd f|dddddf< t
|dd |dd |dd f|dddddf< t
|dd |dd |dd f|dddddf< |g | }q|dkrt
|||f}t
|ddd |ddd |ddd f}t
j||fdd}|| qtj|f|	|
|d|}| | | ||g||g||g| |S )a	  
        Fill the area between two 3D curves.

        The curves are defined by the points (*x1*, *y1*, *z1*) and
        (*x2*, *y2*, *z2*). This creates one or multiple quadrangle
        polygons that are filled. All points must be the same length N, or a
        single value to be used for all points.

        Parameters
        ----------
        x1, y1, z1 : float or 1D array-like
            x, y, and z  coordinates of vertices for 1st line.

        x2, y2, z2 : float or 1D array-like
            x, y, and z coordinates of vertices for 2nd line.

        where : array of bool (length N), optional
            Define *where* to exclude some regions from being filled. The
            filled regions are defined by the coordinates ``pts[where]``,
            for all x, y, and z pts. More precisely, fill between ``pts[i]``
            and ``pts[i+1]`` if ``where[i] and where[i+1]``. Note that this
            definition implies that an isolated *True* value between two
            *False* values in *where* will not result in filling. Both sides of
            the *True* position remain unfilled due to the adjacent *False*
            values.

        mode : {'quad', 'polygon', 'auto'}, default: 'auto'
            The fill mode. One of:

            - 'quad':  A separate quadrilateral polygon is created for each
              pair of subsequent points in the two lines.
            - 'polygon': The two lines are connected to form a single polygon.
              This is faster and can render more cleanly for simple shapes
              (e.g. for filling between two lines that lie within a plane).
            - 'auto': If the points all lie on the same 3D plane, 'polygon' is
              used. Otherwise, 'quad' is used.

        facecolors : list of :mpltype:`color`, default: None
            Colors of each individual patch, or a single color to be used for
            all patches.

        shade : bool, default: None
            Whether to shade the facecolors. If *None*, then defaults to *True*
            for 'quad' mode and *False* for 'polygon' mode.

        axlim_clip : bool, default: False
            Whether to hide data that is outside the axes view limits.

            .. versionadded:: 3.10

        **kwargs
            All other keyword arguments are passed on to `.Poly3DCollection`.

        Returns
        -------
        `.Poly3DCollection`
            A `.Poly3DCollection` containing the plotted polygons.

        )r   quadpolygon)rO  NTr   zwhere size (z) does not match size ()r   g-q=)atolr  r  Fr   r   r   r  r   r   r   )r  r  rw  )r   r   r|  r   r~  _get_patches_for_fillget_next_colorlistmcolorsto_rgba_arrayr   r   r7  sizer   isnanr   _all_points_on_planeconcatenatecontiguous_regionsr  emptyr)  r	  Poly3DCollectionadd_collectionr1  )ra   r?  rC  rF  x2y2z2r  rO  r  r  rw  re   r0  polysidx0idx1x1iy1iz1ix2iy2iz2i	n_polys_ipolys_iline1line2polypolycrj   rj   rk   fill_between  st   > 

::::
.

zAxes3D.fill_between)r   vminvmaxlightsourcerw  c          "         s  |   }
|jdkrtdt|}t|||\}}}|j\}}d|	v p(d|	v }d|	v p0d|	v }|r9|r9td|	dd|	dd|	dd	}|	dd	}t	j
d
 rY|}n| }|rvttt|| dttt|| d|	dd}|	dd}|	d|du }|du rtdg }|d  dkr|d  dkr|du rtjfdd|||fD dd}n\ttd|d |d g }ttd|d |d g }g }t|D ]6\t|D ],\  fdd|||fD }t|j}|| |dur||    qqt|tjr&t| s\g }g }t||D ]"\}}t|t|jdd }t|rQ|| || q0|}|dur\|}|durqtj|f|||||d|	}nn|rtj|fd|i|	}t|tjr|d jdd} n
tdd |D } | |  |dus|dur|!|| |dur|"| n&|	dd}!|!du r| j#$ }!tt%&|!}!tj|f|!|||d|	}| '| | (||||
 |S )a
  
        Create a surface plot.

        By default, it will be colored in shades of a solid color, but it also
        supports colormapping by supplying the *cmap* argument.

        .. note::

           The *rcount* and *ccount* kwargs, which both default to 50,
           determine the maximum number of samples used in each direction.  If
           the input data is larger, it will be downsampled (by slicing) to
           these numbers of points.

        .. note::

           To maximize rendering speed consider setting *rstride* and *cstride*
           to divisors of the number of rows minus 1 and columns minus 1
           respectively. For example, given 51 rows rstride can be any of the
           divisors of 50.

           Similarly, a setting of *rstride* and *cstride* equal to 1 (or
           *rcount* and *ccount* equal the number of rows and columns) can use
           the optimized path.

        Parameters
        ----------
        X, Y, Z : 2D arrays
            Data values.

        rcount, ccount : int
            Maximum number of samples used in each direction.  If the input
            data is larger, it will be downsampled (by slicing) to these
            numbers of points.  Defaults to 50.

        rstride, cstride : int
            Downsampling stride in each direction.  These arguments are
            mutually exclusive with *rcount* and *ccount*.  If only one of
            *rstride* or *cstride* is set, the other defaults to 10.

            'classic' mode uses a default of ``rstride = cstride = 10`` instead
            of the new default of ``rcount = ccount = 50``.

        color : :mpltype:`color`
            Color of the surface patches.

        cmap : Colormap, optional
            Colormap of the surface patches.

        facecolors : list of :mpltype:`color`
            Colors of each individual patch.

        norm : `~matplotlib.colors.Normalize`, optional
            Normalization for the colormap.

        vmin, vmax : float, optional
            Bounds for the normalization.

        shade : bool, default: True
            Whether to shade the facecolors.  Shading is always disabled when
            *cmap* is specified.

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

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

            .. versionadded:: 3.10

        **kwargs
            Other keyword arguments are forwarded to `.Poly3DCollection`.
        r   !Argument Z must be 2-dimensional.rstridecstridercountccount.Cannot specify both stride and count argumentsr  2   _internal.classic_moder   r  Ncmapr  zshade cannot be None.r   c                    s   g | ]	}t | qS rj   )r   _array_patch_perimetersr   r  )r  r  rj   rk   
<listcomp>  s    z'Axes3D.plot_surface.<locals>.<listcomp>r  r   c              	      s.   g | ]}t |d   d  f qS )r   )r   _array_perimeterr  )cscs_nextrsrs_nextrj   rk   r    s     )
edgecolorsr  r  r  rw  rw  ).r   c                 S   s    g | ]}|d d df   qS Nr   )r   )r   r  rj   rj   rk   r    s     color)r  r  r  rw  ))r|  ndimr   r   _to_unmasked_float_arrayr   broadcast_arraysr'  rD   re  rf  intr   ceilgetstackr  r  	itertoolspairwiser   r=  r	  r   ndarrayisfiniteallzip_longestr  r   r  r   	set_arrayset_climset_norm
_get_linesr  r  to_rgbar  r1  )"ra   r-  r.  r/  r   r  r  r  rw  re   r0  rowscols
has_stride	has_countr  r  compute_stridesfcolorsr  r  colsetr  row_indscol_indsr  	new_polys
new_colsetr  colnew_polyr  avg_zr  rj   )r  r  r  r  r  r  rk   plot_surfaceM  s   K
















zAxes3D.plot_surfacec                   s  |   }jdkrtdt \ j\}}d|v p#d|v }	d|v p+d|v }
|	r4|
r4td|dd}|dd}|dd	}|dd	}tjd
 rt|
rs|rat	t
t|| dnd}|rqt	t
t|| dnd}n"|	s|rt	t
t|| dnd}|rt	t
t|| dnd}t tt|rttd||}|dkr|d |d kr||d g7 }ng }|rttd||}|dkr|d |d kr||d g7 }ng }|dkr|dkrtdjdkrg }g } fdd|D }fdd|D }fdd|D }fdd|D }fdd|D }fdd|D }dd t|||D dd t|||D  }tj|fd|i|}| | |  | |S )at  
        Plot a 3D wireframe.

        .. note::

           The *rcount* and *ccount* kwargs, which both default to 50,
           determine the maximum number of samples used in each direction.  If
           the input data is larger, it will be downsampled (by slicing) to
           these numbers of points.

        Parameters
        ----------
        X, Y, Z : 2D arrays
            Data values.

        axlim_clip : bool, default: False
            Whether to hide lines and patches with vertices outside the axes
            view limits.

            .. versionadded:: 3.10

        rcount, ccount : int
            Maximum number of samples used in each direction.  If the input
            data is larger, it will be downsampled (by slicing) to these
            numbers of points.  Setting a count to zero causes the data to be
            not sampled in the corresponding direction, producing a 3D line
            plot rather than a wireframe plot.  Defaults to 50.

        rstride, cstride : int
            Downsampling stride in each direction.  These arguments are
            mutually exclusive with *rcount* and *ccount*.  If only one of
            *rstride* or *cstride* is set, the other defaults to 1.  Setting a
            stride to zero causes the data to be not sampled in the
            corresponding direction, producing a 3D line plot rather than a
            wireframe plot.

            'classic' mode uses a default of ``rstride = cstride = 1`` instead
            of the new default of ``rcount = ccount = 50``.

        **kwargs
            Other keyword arguments are forwarded to `.Line3DCollection`.
        r   r  r  r  r  r  r  r   r  r  r   r  z*Either rstride or cstride must be non zeroc                       g | ]} | qS rj   rj   r   r   )r-  rj   rk   r  }	      z)Axes3D.plot_wireframe.<locals>.<listcomp>c                    r  rj   rj   r  )r.  rj   rk   r  ~	  r  c                    r  rj   rj   r  )r/  rj   rk   r  	  r  c                    r  rj   rj   r  )tXrj   rk   r  	  r  c                    r  rj   rj   r  )tYrj   rk   r  	  r  c                    r  rj   rj   r  )tZrj   rk   r  	  r  c                 S   "   g | ]\}}}t t|||qS rj   r  zipr   xlylzlrj   rj   rk   r  	      c                 S   r  rj   r  r  rj   rj   rk   r  	  r  rw  )r|  r  r   r   r  r'  rD   re  rf  r  r   r  	transposer  r  r  r  r   Line3DCollectionr  r1  )ra   r-  r.  r/  rw  re   r0  r  r  r  r  r  r  r  r  riiciixlinesylineszlinestxlinestylinestzlinesr  linecrj   )r-  r.  r/  r  r  r  rk   plot_wireframe	  sp   ,


    "



zAxes3D.plot_wireframe)r  r   r  r  r  rw  c                O   s  |   }	|du r| j }tt|}|dd}
|d|
du }t	j
|i |\}}}z|d}W n tyB   |^}}Y nw t|}| }|j| }|j| }|| }tj|||fdd}|
rtj|g|R d|i|}|dddddf jd	d}|| |dus|dur||| |dur|| ntj|g|R ||||d
|}| | | |j|j||	 |S )a  
        Plot a triangulated surface.

        The (optional) triangulation can be specified in one of two ways;
        either::

          plot_trisurf(triangulation, ...)

        where triangulation is a `~matplotlib.tri.Triangulation` object, or::

          plot_trisurf(X, Y, ...)
          plot_trisurf(X, Y, triangles, ...)
          plot_trisurf(X, Y, triangles=triangles, ...)

        in which case a Triangulation object will be created.  See
        `.Triangulation` for an explanation of these possibilities.

        The remaining arguments are::

          plot_trisurf(..., Z)

        where *Z* is the array of values to contour, one per point
        in the triangulation.

        Parameters
        ----------
        X, Y, Z : array-like
            Data values as 1D arrays.
        color
            Color of the surface patches.
        cmap
            A colormap for the surface patches.
        norm : `~matplotlib.colors.Normalize`, optional
            An instance of Normalize to map values to colors.
        vmin, vmax : float, optional
            Minimum and maximum value to map.
        shade : bool, default: True
            Whether to shade the facecolors.  Shading is always disabled when
            *cmap* is specified.
        lightsource : `~matplotlib.colors.LightSource`, optional
            The lightsource to use when *shade* is True.
        axlim_clip : bool, default: False
            Whether to hide patches with a vertex outside the axes view limits.

            .. versionadded:: 3.10
        **kwargs
            All other keyword arguments are passed on to
            :class:`~mpl_toolkits.mplot3d.art3d.Poly3DCollection`

        Examples
        --------
        .. plot:: gallery/mplot3d/trisurf3d.py
        .. plot:: gallery/mplot3d/trisurf3d_2.py
        Nr  r  r/  r  r   rw  r   r   )r  r  r  rw  )r|  r  r  r   r   r  r  r  rD   r   get_from_args_and_kwargsKeyErrorr   get_masked_trianglesr   r   r  r   r  r   r  r  r  r  r1  )ra   r  r   r  r  r  rw  rd   re   r0  r  r  trir   	trianglesxtytztvertsr  r  rj   rj   rk   plot_trisurf	  sZ   9






zAxes3D.plot_trisurf   c                    s"  |j d |j d  d }g }g }t|j D ]f\}}| | }g | }	| | }
t|	|| t|	||  td sBqtt	td | d}td d |d  |
 fddtt	|d D  |
|
gt	|d   q| tjt|||dd |  dS )	z4
        Extend a contour in 3D by creating
        r   r   r   c              	      s`   g | ],}d  t |  d  t |d    d  t |d    d  t |  fqS r   r   )roundr  botstepsizerr  rj   rk   r  
  s    ((z-Axes3D._3d_extend_contour.<locals>.<listcomp>T)r  r  r  N)levelsr   	get_paths_iter_connected_componentsget_edgecolorr   _paths_to_3d_segmentsr  r   r	  extendr  add_collection3dr  r   r   remove)ra   csetstrider  	polyvertscolorsr  levelpathsubpathsr  nstepsrj   r
  rk   _3d_extend_contour	  s,   zAxes3D._3d_extend_contourc                 C   s@   d| }|r|  || d S tj||d ur|n|j||d d S )Nr  r{  )r  r   collection_2d_to_3dr  )ra   r  extend3dr  rz  offsetrw  rj   rj   rk   add_contour_set
  s   
zAxes3D.add_contour_setc                C   s   | j ||||d d S )Nrz  r   rw  )_add_contourf_set)ra   r  rz  r   rw  rj   rj   rk   add_contourf_set
  s   

zAxes3D.add_contourf_setc                 C   s   d| }|j dd t|j d  }|jr.|j d t|j dd d  }t|d|}|jrH|j d t|j dd d  }t||}tj||durQ|n|||d |S )z
        Returns
        -------
        levels : `numpy.ndarray`
            Levels at which the filled contours are added.
        r  Nr  r   r   r{  )	r  r   diff_extend_mininsert_extend_maxr	  r   r  )ra   r  rz  r   rw  	midpoints	min_level	max_levelrj   rj   rk   r#  !
  s   ""zAxes3D._add_contourf_set)r  r  rz  r   rw  c                   sd   |   }t||||\}}}t j|||g|	R i |
}| |||||| | |||| |S )a  
        Create a 3D contour plot.

        Parameters
        ----------
        X, Y, Z : array-like,
            Input data. See `.Axes.contour` for supported data shapes.
        extend3d : bool, default: False
            Whether to extend contour in 3D.
        stride : int, default: 5
            Step size for extending contour.
        zdir : {'x', 'y', 'z'}, default: 'z'
            The direction to use.
        offset : float, optional
            If specified, plot a projection of the contour lines at this
            position in a plane normal to *zdir*.
        axlim_clip : bool, default: False
            Whether to hide lines with a vertex outside the axes view limits.

            .. versionadded:: 3.10
        data : indexable object, optional
            DATA_PARAMETER_PLACEHOLDER

        *args, **kwargs
            Other arguments are forwarded to `matplotlib.axes.Axes.contour`.

        Returns
        -------
        matplotlib.contour.QuadContourSet
        )r|  r   rotate_axesrF   contourr!  r1  )ra   r-  r.  r/  r  r  rz  r   rw  rd   re   r0  jXjYjZr  rh   rj   rk   r.  8
  s   "zAxes3D.contourc                   s   |   }tj|i |\}	}}|	j}
|	j}d|v r|d}n|^}}t|
|||\}}}t|||	j|	j	}	t
 j|	|g|R i |}| |||||| | |
||| |S )a  
        Create a 3D contour plot.

        .. note::
            This method currently produces incorrect output due to a
            longstanding bug in 3D PolyCollection rendering.

        Parameters
        ----------
        X, Y, Z : array-like
            Input data. See `.Axes.tricontour` for supported data shapes.
        extend3d : bool, default: False
            Whether to extend contour in 3D.
        stride : int, default: 5
            Step size for extending contour.
        zdir : {'x', 'y', 'z'}, default: 'z'
            The direction to use.
        offset : float, optional
            If specified, plot a projection of the contour lines at this
            position in a plane normal to *zdir*.
        axlim_clip : bool, default: False
            Whether to hide lines with a vertex outside the axes view limits.

            .. versionadded:: 3.10
        data : indexable object, optional
            DATA_PARAMETER_PLACEHOLDER
        *args, **kwargs
            Other arguments are forwarded to `matplotlib.axes.Axes.tricontour`.

        Returns
        -------
        matplotlib.tri._tricontour.TriContourSet
        r/  )r|  r   r  r   r   rD   r   r-  r  maskrF   
tricontourr!  r1  )ra   r  r  rz  r   rw  rd   re   r0  r   r-  r.  r/  r/  r0  r1  r  rh   rj   rk   r3  e
  s"   %zAxes3D.tricontourc                    s>   d|d|d|||i  fdddD }| j g ||R   d S )Nr   r   r   c                    s(   g | ]}t  | t  | fqS rj   r   nanminnanmax)r   dimdim_valsrj   rk   r  
  s     z/Axes3D._auto_scale_contourf.<locals>.<listcomp>r   )r1  )ra   r-  r.  r/  rz  r  r0  limitsrj   r8  rk   _auto_scale_contourf
  s
   
zAxes3D._auto_scale_contourfr"  c                   sd   |   }	t||||\}
}}t j|
||g|R i |}| ||||}| ||||||	 |S )aG  
        Create a 3D filled contour plot.

        Parameters
        ----------
        X, Y, Z : array-like
            Input data. See `.Axes.contourf` for supported data shapes.
        zdir : {'x', 'y', 'z'}, default: 'z'
            The direction to use.
        offset : float, optional
            If specified, plot a projection of the contour lines at this
            position in a plane normal to *zdir*.
        axlim_clip : bool, default: False
            Whether to hide lines with a vertex outside the axes view limits.

            .. versionadded:: 3.10
        data : indexable object, optional
            DATA_PARAMETER_PLACEHOLDER
        *args, **kwargs
            Other arguments are forwarded to `matplotlib.axes.Axes.contourf`.

        Returns
        -------
        matplotlib.contour.QuadContourSet
        )r|  r   r-  rF   contourfr#  r;  )ra   r-  r.  r/  rz  r   rw  rd   re   r0  r/  r0  r1  r  r  rh   rj   rk   r<  
  s   zAxes3D.contourfc                   s   |   }tj|i |\}}}|j}|j}	d|v r|d}
n|^}
}t||	|
|\}}}t|||j|j	}t
 j||g|R i |}| ||||}| ||	|
||| |S )a  
        Create a 3D filled contour plot.

        .. note::
            This method currently produces incorrect output due to a
            longstanding bug in 3D PolyCollection rendering.

        Parameters
        ----------
        X, Y, Z : array-like
            Input data. See `.Axes.tricontourf` for supported data shapes.
        zdir : {'x', 'y', 'z'}, default: 'z'
            The direction to use.
        offset : float, optional
            If specified, plot a projection of the contour lines at this
            position in a plane normal to zdir.
        axlim_clip : bool, default: False
            Whether to hide lines with a vertex outside the axes view limits.

            .. versionadded:: 3.10
        data : indexable object, optional
            DATA_PARAMETER_PLACEHOLDER
        *args, **kwargs
            Other arguments are forwarded to
            `matplotlib.axes.Axes.tricontourf`.

        Returns
        -------
        matplotlib.tri._tricontour.TriContourSet
        r/  )r|  r   r  r   r   rD   r   r-  r  r2  rF   tricontourfr#  r;  )ra   rz  r   rw  rd   re   r0  r   r-  r.  r/  r/  r0  r1  r  r  rh   rj   rk   r=  
  s"    zAxes3D.tricontourfc          
         s  |   }t|}|jrt|nd}t|tju r)tj	||||d |
| n+t|tju r?tj||||d |
| nt|tju rTtj||||d |
| |rt|tjrk| jt|j d|i nt|tjr| j|jdd d|i nt|tjr	 t |}	|	S )a  
        Add a 3D collection object to the plot.

        2D collection types are converted to a 3D version by
        modifying the object and adding z coordinate information,
        *zs* and *zdir*.

        Supported 2D collection types are:

        - `.PolyCollection`
        - `.LineCollection`
        - `.PatchCollection` (currently not supporting *autolim*)

        Parameters
        ----------
        col : `.Collection`
            A 2D collection object.
        zs : float or array-like, default: 0
            The z-positions to be used for the 2D objects.
        zdir : {'x', 'y', 'z'}, default: 'z'
            The direction to use for the z-positions.
        autolim : bool, default: True
            Whether to update the data limits.
        axlim_clip : bool, default: False
            Whether to hide the scatter points outside the axes view limits.

            .. versionadded:: 3.10
        r   r{  r0  Nr  )r|  r   r  r  rK  typer   PolyCollectionr   poly_collection_2d_to_3dset_sort_zposLineCollectionline_collection_2d_to_3dPatchCollectionpatch_collection_2d_to_3dr   r  r1  r   _segments3dr  r  _vecPatch3DCollectionrF   r  )
ra   r  r  rz  autolimrw  r0  zvalszsortval
collectionrh   rj   rk   r    s>   




zAxes3D.add_collection3d)	r  r  r  r  r  r  	facecolorr  r  )replace_names   c                   s   |   }|}t|||\}}}tj|}t||||||
dd\}}}}}}|
ddur5||
d< t||r?|	 }t
 j||g|	R ||d|
}tj|||||d | jdk ri|jdkri| d | |||| |S )a  
        Create a scatter plot.

        Parameters
        ----------
        xs, ys : array-like
            The data positions.
        zs : float or array-like, default: 0
            The z-positions. Either an array of the same length as *xs* and
            *ys* or a single value to place all points in the same plane.
        zdir : {'x', 'y', 'z', '-x', '-y', '-z'}, default: 'z'
            The axis direction for the *zs*. This is useful when plotting 2D
            data on a 3D Axes. The data must be passed as *xs*, *ys*. Setting
            *zdir* to 'y' then plots the data to the x-z-plane.

            See also :doc:`/gallery/mplot3d/2dcollections3d`.

        s : float or array-like, default: 20
            The marker size in points**2. Either an array of the same length
            as *xs* and *ys* or a single value to make all markers the same
            size.
        c : :mpltype:`color`, sequence, or sequence of colors, optional
            The marker color. Possible values:

            - A single color format string.
            - A sequence of colors of length n.
            - A sequence of n numbers to be mapped to colors using *cmap* and
              *norm*.
            - A 2D array in which the rows are RGB or RGBA.

            For more details see the *c* argument of `~.axes.Axes.scatter`.
        depthshade : bool, default: True
            Whether to shade the scatter markers to give the appearance of
            depth. Each call to ``scatter()`` will perform its depthshading
            independently.
        axlim_clip : bool, default: False
            Whether to hide the scatter points outside the axes view limits.

            .. versionadded:: 3.10
        data : indexable object, optional
            DATA_PARAMETER_PLACEHOLDER
        **kwargs
            All other keyword arguments are passed on to `~.axes.Axes.scatter`.

        Returns
        -------
        paths : `~matplotlib.collections.PathCollection`
        r  N)r  r  )r  rz  
depthshaderw  皙?r   )r|  r   r~  r   mar*  delete_masked_pointsr  may_share_memorycopyrF   scatterr   rE  r  r  r  r1  )ra   r  r  r  rz  r  r  rP  rw  rd   re   r0  zs_origr  patchesrh   rj   rk   rV  H  s(   7"

zAxes3D.scatterc                   s   |   }t j||g|R i |}	tj|t|dd}g }
g }t|	|D ]+\}}t|}|
|	 7 }
||gt| 7 }t
|||| d|v rP||d  q%t|
dkr^t|
 \}}ng g }}t||||\}}}| |||| |	S )a  
        Add 2D bar(s).

        Parameters
        ----------
        left : 1D array-like
            The x coordinates of the left sides of the bars.
        height : 1D array-like
            The height of the bars.
        zs : float or 1D array-like, default: 0
            Z coordinate of bars; if a single value is specified, it will be
            used for all bars.
        zdir : {'x', 'y', 'z'}, default: 'z'
            When plotting 2D data, the direction to use as z ('x', 'y' or 'z').
        axlim_clip : bool, default: False
            Whether to hide bars with points outside the axes view limits.

            .. versionadded:: 3.10
        data : indexable object, optional
            DATA_PARAMETER_PLACEHOLDER
        **kwargs
            Other keyword arguments are forwarded to
            `matplotlib.axes.Axes.bar`.

        Returns
        -------
        mpl_toolkits.mplot3d.art3d.Patch3DCollection
        T)subokalphar   )r|  rF   barr   broadcast_tor  r  r   _get_patch_vertsr  patch_2d_to_3d	set_alphar  r1  )ra   rl  r   r  rz  rw  rd   re   r0  rX  r  verts_zsr  r   vsr  r  rh   rj   rk   r[    s&   

z
Axes3D.baraveragec                O   s  |   }tt||||||\}}}}}}t|}t|| }t|}t|| }t|}t|| }tg d}t|j|j }d||fd||fd||ffD ]%\}}}|dtj	tj	f }|dtj	tj	f }|||d|f   |d|f< qY|
d|jdd  }g }|du r| j g}tt|}t|t|kr|D ]
}||gd  qn|}t|t|k r|dt| 9 }tj|g|R |||	|
|d	|}| | | ||f||f||f| |S )
aR  
        Generate a 3D barplot.

        This method creates three-dimensional barplot where the width,
        depth, height, and color of the bars can all be uniquely set.

        Parameters
        ----------
        x, y, z : array-like
            The coordinates of the anchor point of the bars.

        dx, dy, dz : float or array-like
            The width, depth, and height of the bars, respectively.

        color : sequence of colors, optional
            The color of the bars can be specified globally or
            individually. This parameter can be:

            - A single color, to color all bars the same color.
            - An array of colors of length N bars, to color each bar
              independently.
            - An array of colors of length 6, to color the faces of the
              bars similarly.
            - An array of colors of length 6 * N bars, to color each face
              independently.

            When coloring the faces of the boxes specifically, this is
            the order of the coloring:

            1. -Z (bottom of box)
            2. +Z (top of box)
            3. -Y
            4. +Y
            5. -X
            6. +X

        zsort : {'average', 'min', 'max'}, default: 'average'
            The z-axis sorting scheme passed onto `~.art3d.Poly3DCollection`

        shade : bool, default: True
            When true, this shades the dark sides of the bars (relative
            to the plot's source of light).

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

        axlim_clip : bool, default: False
            Whether to hide the bars with points outside the axes view limits.

            .. versionadded:: 3.10

        data : indexable object, optional
            DATA_PARAMETER_PLACEHOLDER

        **kwargs
            Any additional keyword arguments are passed onto
            `~.art3d.Poly3DCollection`.

        Returns
        -------
        collection : `~.art3d.Poly3DCollection`
            A collection of three-dimensional polygons representing the bars.
        ))r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )rc  rf  rh  rg  )rd  rj  ri  re  )rc  rg  rj  rd  )rf  re  ri  rh  r   r   r   .)r  N   )zsortr  r  r  rw  )r|  r   r  r  rK  r   r   r  r'  newaxisreshaper  r  r  r  r  r  r  r   r  r  r1  )ra   r   r   r   r  r  r  r  rl  r  r  rw  rd   re   r0  r   r   r   r   r   r   cuboidr  r   r  dpr  r  r  rj   rj   rk   bar3d  sT   D


.&
zAxes3D.bar3dcenterc                    s<   t  j|f||d|}| j \}}| jd|  |S )N)rh  r  gq=
ףp?)rF   	set_titletitler   set_y)ra   rj  rh  r  re   retr   r   rh   rj   rk   rs    s   zAxes3D.set_titleg333333?tail)lengtharrow_length_ratiopivot	normalizerw  c             	   K   s  dd }|   }tj||||||dd}tdd |D r-tjg fi |}| | |S tjd|gt	d}|| }t
jg d	|	d
 |	dkrL||8 }n
|	dkrV||d 8 }t|dd }t|dd t	}|
rtjj|dd}d||dk< ||d }t|dkr|tj|| dd}||}|ddddf tj|| }|t|ddf}|dd}g ||ddd |ddd }ng }tj|fd|i|}| | | |dddf |dddf |dddf | |S )a  
        Plot a 3D field of arrows.

        The arguments can be array-like or scalars, so long as they can be
        broadcast together. The arguments can also be masked arrays. If an
        element in any of argument is masked, then that corresponding quiver
        element will not be plotted.

        Parameters
        ----------
        X, Y, Z : array-like
            The x, y and z coordinates of the arrow locations (default is
            tail of arrow; see *pivot* kwarg).

        U, V, W : array-like
            The x, y and z components of the arrow vectors.

        length : float, default: 1
            The length of each quiver.

        arrow_length_ratio : float, default: 0.3
            The ratio of the arrow head with respect to the quiver.

        pivot : {'tail', 'middle', 'tip'}, default: 'tail'
            The part of the arrow that is at the grid point; the arrow
            rotates about this point, hence the name *pivot*.

        normalize : bool, default: False
            Whether all arrows are normalized to have the same length, or keep
            the lengths defined by *u*, *v*, and *w*.

        axlim_clip : bool, default: False
            Whether to hide arrows with points outside the axes view limits.

            .. versionadded:: 3.10

        data : indexable object, optional
            DATA_PARAMETER_PLACEHOLDER

        **kwargs
            Any additional keyword arguments are delegated to
            :class:`.Line3DCollection`
        c              
   S   sX  | d d df }| d d df }t jj| d d d df dd}t j|||dkt |d}t j| ||dkt |d}td}t|}t	|}|| }	|| }
|| d|  }t 
||d d|   ||	g|||d d|   |
 g|	 |
t ||gg}| }|g dg df  d	9  < t d
|| }t d
|| }t j||gddS )Nr   r   r   r   )r  rI     )r   r   r   r   )r   r   r   r   r  zij...,...j->...i)r   r   r   divide
zeros_like	ones_likemathradiansr  r  r   	full_likerU  einsumr  )UVWr   r   r   x_py_prangler  r  r13r32r12RposRneg	Rpos_vecs	Rneg_vecsrj   rj   rk   calc_arrows  s,    


z"Axes3D.quiver.<locals>.calc_arrowsT)compressc                 s   s    | ]	}t |d kV  qdS )r   N)r  )r   r  rj   rj   rk   r         z Axes3D.quiver.<locals>.<genexpr>r(   r   )rw  middletip)rz  rw  r  r   Nr   r   r   r   )r  r   r  rw  )r|  r   r~  anyr   r  r  r   r   r   r   r   r)  astyper   r   rn  r  multiplyouterswapaxesr1  )ra   r-  r.  r/  UrG  Wrx  ry  rz  r{  rw  re   r  r0  
input_argsr  shaft_dtarrow_dtXYZr  r   shafts	head_dirsheadsr  rj   rj   rk   quiver  sD   0

"&
4zAxes3D.quiverr  r  r  r  rw  c          2   	      s  t |dkrdd }ndd }||i |\}	}jdkr"tdtjjtjd}
t|
d  |	du r>t \}}}n fd	d
|	D \}}}fdd}|du rY| j	
 }||d}||d}| ||| tjg dg dg dg dgtjd}tt}dd }|dD ]}|j|
\}}}t|}t|}t|}||j}|ddd }|D ]}|D ]}|||dg}t|}| r|| ||  t|D ]C\}} ||||g}!|||| g}"t|!}#t|"}$|# r|$ s||# |"|  q׈|# s|$ r||$ |"|  q||||d g}%||||g}&t|%}'|' r?||' |&|  qqqi }(| D ]u\})}*|	du rT|*}+nHg }+|*D ]C},|,dddf |,dddf |,dddf f}-t|,j}.||- |.dddf< ||- |.dddf< ||- |.dddf< |+|. qX||) }/||) }0tj|+f|/|0|||d|}1| |1 |1|(|)< qH|(S )a/  
        ax.voxels([x, y, z,] /, filled, facecolors=None, edgecolors=None, **kwargs)

        Plot a set of filled voxels

        All voxels are plotted as 1x1x1 cubes on the axis, with
        ``filled[0, 0, 0]`` placed with its lower corner at the origin.
        Occluded faces are not plotted.

        Parameters
        ----------
        filled : 3D np.array of bool
            A 3D array of values, with truthy values indicating which voxels
            to fill

        x, y, z : 3D np.array, optional
            The coordinates of the corners of the voxels. This should broadcast
            to a shape one larger in every dimension than the shape of
            *filled*.  These can be used to plot non-cubic voxels.

            If not specified, defaults to increasing integers along each axis,
            like those returned by :func:`~numpy.indices`.
            As indicated by the ``/`` in the function signature, these
            arguments can only be passed positionally.

        facecolors, edgecolors : array-like, optional
            The color to draw the faces and edges of the voxels. Can only be
            passed as keyword arguments.
            These parameters can be:

            - A single color value, to color all voxels the same color. This
              can be either a string, or a 1D RGB/RGBA array
            - ``None``, the default, to use a single color for the faces, and
              the style default for the edges.
            - A 3D `~numpy.ndarray` of color names, with each item the color
              for the corresponding voxel. The size must match the voxels.
            - A 4D `~numpy.ndarray` of RGB/RGBA data, with the components
              along the last axis.

        shade : bool, default: True
            Whether to shade the facecolors.

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

        axlim_clip : bool, default: False
            Whether to hide voxels with points outside the axes view limits.

            .. versionadded:: 3.10

        **kwargs
            Additional keyword arguments to pass onto
            `~mpl_toolkits.mplot3d.art3d.Poly3DCollection`.

        Returns
        -------
        faces : dict
            A dictionary indexed by coordinate, where ``faces[i, j, k]`` is a
            `.Poly3DCollection` of the faces drawn for the voxel
            ``filled[i, j, k]``. If no faces were drawn for a given voxel,
            either because it was not asked to be drawn, or it is fully
            occluded, then ``(i, j, k) not in faces``.

        Examples
        --------
        .. plot:: gallery/mplot3d/voxels.py
        .. plot:: gallery/mplot3d/voxels_rgb.py
        .. plot:: gallery/mplot3d/voxels_torus.py
        .. plot:: gallery/mplot3d/voxels_numpy_logo.py
        r   c                 [   s   | ||f||fS r   rj   )
_Axes3D__x
_Axes3D__y
_Axes3D__zfilledre   rj   rj   rk   voxelsX  s   zAxes3D.voxels.<locals>.voxelsc                 [   s
   d | |fS r   rj   )r  re   rj   rj   rk   r  [  s   
z%Argument filled must be 3-dimensionalr   r   Nc                 3   s    | ]	}t | V  qd S r   )r   r\  )r   r  )coord_shaperj   rk   r   j  r  z Axes3D.voxels.<locals>.<genexpr>c                    sp   t | dv rt |  jt |  S t | dv r0t | d d  jkr.td| d| S td| d)Nr  )r   r   r   zWhen multidimensional, z must match the shape of filledzInvalid z	 argument)r   r  r\  r'  r   )r  r  )r  rj   rk   _broadcast_color_argl  s   
z+Axes3D.voxels.<locals>._broadcast_color_argr  r  rc  rf  re  rd  c                 s   s:    t j| t jd}t| D ]}|V  t j|ddd}qdS )z%Generate cyclic permutation matrices.r   r   r   r   N)r   r  intpr  r!   )nmatr   rj   rj   rk   permutation_matrices  s   z+Axes3D.voxels.<locals>.permutation_matricesr  r   r   r  )r  r  r   r   r   r'  r  rv  indicesr  r  r1  r   r  r=  r  aranger	  r  r  itemsr  r   r  r  )2ra   r  r  r  r  rw  rd   re   r  xyzr  r   r   r   r  squarevoxel_facesr  permutepcqcrcpindsqindsrindssquare_rot_possquare_rot_negr  r1  r  i0r1r  r  r  i1i2pkpk2ikpolygonscoord
faces_indsfaces	face_indsindfacerM  	edgecolorr  rj   )r  r  rk   r  
  s   L




	



"
.
zAxes3D.voxels)r   r   r   xerryerrzerrr  c           D         sX  |   }t|tj}dd | D }|dd | jd|fd|fd|fg|dd	 t	|r2|n|g}t	|r<|n|g}t	|rF|n|g}t
|t
|  kr\t
|ksatd
 td
| ||	|dd}d|d< | jj| |dkr}||fn|||f|dd\\}}tj|||d |r||d d  n	||d d  | dkr| | nd}|d d|vrd|d< |
du r|d }
dD ]}||d qi |d|
i}|r||d< n
d|v r|d |d< dD ]}||v r|| ||< qi |ddi}|du rtjd }|dkrd| |d< |dur"||d< |
|d< d d! }fd"d# g g g }}} g }!d$d$d%d&}"dd'dd(|dtjd) d }#|#| jdd*jd+ 9 }#| j d,|#|#fg}#ttj|#dd-}#tj| dddd. tj !| " }$W d   n	1 sw   Y  t#|$|#dddgd' }#|#d/9 }#i ||#d'd0}%|%dd t$g d(|||g|||g|||g|||gD ]\}&}'t%|&|& }(du rqt	sgt
|' t&t't
|'(t)t't
|'(t) fd1d2t*|||gD })|)\\}*}+\},}-\}.}/B  }0|0+ ry|dkry||*|,|.g|0@ }1||+|-|/g|0@ }2tj,|1d|"|( |d3|}3tj,|2d|"|( |d3|}4| |3 | |4 |-|3 |-|4 + r||+|-|/g@ \}5}6}7| j.|5|6|7gR i |% + r||*|,|.g@ \}8}9}:| j.|8|9|:g R i |% tj/t0|)j1fd4|i|};| 2|; |-|; |!-|) qt0|!}!fd5d6}<|<|!d\}=}>|<|!d\}?}@|<|!d\}A}B| 3|=|>f|?|@f|A|Bf| t4j5|t6|t6|f|dup|du|du|d7}C| j7-|C ||| fS )8ag  
        Plot lines and/or markers with errorbars around them.

        *x*/*y*/*z* define the data locations, and *xerr*/*yerr*/*zerr* define
        the errorbar sizes. By default, this draws the data markers/lines as
        well the errorbars. Use fmt='none' to draw errorbars only.

        Parameters
        ----------
        x, y, z : float or array-like
            The data positions.

        xerr, yerr, zerr : float or array-like, shape (N,) or (2, N), optional
            The errorbar sizes:

            - scalar: Symmetric +/- values for all data points.
            - shape(N,): Symmetric +/-values for each data point.
            - shape(2, N): Separate - and + values for each bar. First row
              contains the lower errors, the second row contains the upper
              errors.
            - *None*: No errorbar.

            Note that all error arrays should have *positive* values.

        fmt : str, default: ''
            The format for the data points / data lines. See `.plot` for
            details.

            Use 'none' (case-insensitive) to plot errorbars without any data
            markers.

        ecolor : :mpltype:`color`, default: None
            The color of the errorbar lines.  If None, use the color of the
            line connecting the markers.

        elinewidth : float, default: None
            The linewidth of the errorbar lines. If None, the linewidth of
            the current style is used.

        capsize : float, default: :rc:`errorbar.capsize`
            The length of the error bar caps in points.

        capthick : float, default: None
            An alias to the keyword argument *markeredgewidth* (a.k.a. *mew*).
            This setting is a more sensible name for the property that
            controls the thickness of the error bar cap in points. For
            backwards compatibility, if *mew* or *markeredgewidth* are given,
            then they will over-ride *capthick*. This may change in future
            releases.

        barsabove : bool, default: False
            If True, will plot the errorbars above the plot
            symbols. Default is below.

        xlolims, ylolims, zlolims : bool, default: False
            These arguments can be used to indicate that a value gives only
            lower limits. In that case a caret symbol is used to indicate
            this. *lims*-arguments may be scalars, or array-likes of the same
            length as the errors. To use limits with inverted axes,
            `~.set_xlim`, `~.set_ylim`, or `~.set_zlim` must be
            called before `errorbar`. Note the tricky parameter names: setting
            e.g. *ylolims* to True means that the y-value is a *lower* limit of
            the True value, so, only an *upward*-pointing arrow will be drawn!

        xuplims, yuplims, zuplims : bool, default: False
            Same as above, but for controlling the upper limits.

        errorevery : int or (int, int), default: 1
            draws error bars on a subset of the data. *errorevery* =N draws
            error bars on the points (x[::N], y[::N], z[::N]).
            *errorevery* =(start, N) draws error bars on the points
            (x[start::N], y[start::N], z[start::N]). e.g. *errorevery* =(6, 3)
            adds error bars to the data at (x[6], x[9], x[12], x[15], ...).
            Used to avoid overlapping error bars when two series share x-axis
            values.

        axlim_clip : bool, default: False
            Whether to hide error bars that are outside the axes limits.

            .. versionadded:: 3.10

        Returns
        -------
        errlines : list
            List of `~mpl_toolkits.mplot3d.art3d.Line3DCollection` instances
            each containing an errorbar line.
        caplines : list
            List of `~mpl_toolkits.mplot3d.art3d.Line3D` instances each
            containing a capline object.
        limmarks : list
            List of `~mpl_toolkits.mplot3d.art3d.Line3D` instances each
            containing a marker with an upper or lower limit.

        Other Parameters
        ----------------
        data : indexable object, optional
            DATA_PARAMETER_PLACEHOLDER

        **kwargs
            All other keyword arguments for styling errorbar lines are passed
            `~mpl_toolkits.mplot3d.art3d.Line3DCollection`.

        Examples
        --------
        .. plot:: gallery/mplot3d/errorbar3d.py
        c                 S   s   i | ]\}}|d ur||qS r   rj   )r   r2  r  rj   rj   rk   r  V  s    z#Axes3D.errorbar.<locals>.<dictcomp>r   r   r   r   r   F)convertz)'x', 'y', and 'z' must have the same sizerj  N
_nolegend_r  T)return_kwargs)r  rw  g?noner  C0)marker
markersizemarkerfacecolormarkeredgewidthmarkeredgecolor	markevery	linestyle	fillstyle	drawstyledash_capstyledash_joinstylesolid_capstylesolid_joinstyle	linewidth)r\   rZ  r   
rasterizedr  Nonezerrorbar.capsizer   r   r  r  c                    s    fdd| D S )Nc                    s   g | ]
}g t | qS rj   )r  r  )r   r   r2  rj   rk   r    s    z8Axes3D.errorbar.<locals>._apply_mask.<locals>.<listcomp>rj   )arraysr2  rj   r  rk   _apply_mask  s   z$Axes3D.errorbar.<locals>._apply_maskc                    sZ   t | jdkr| \}}n| | }}t|  B ||| }t|  B ||| }||fS r  )r  r'  r   r  )errdatalomaskhimasklow_errhigh_errlowshighs)	everymaskrj   rk   _extract_errs  s   

z&Axes3D.errorbar.<locals>._extract_errs|_r   r   r   zlines.markersizer/   H   r4   r   )r   r    r!   gV&,t=?)rx  ry  c                    s&   g | ]\}} |  |qS rj   rj   )r   r   r  )r  
dir_vectorr  lolimsuplimsrj   rk   r    s    z#Axes3D.errorbar.<locals>.<listcomp>)lsr  rw  rw  c              	      sL   t | d d  | d d d d f t | d d  | d d d d f fS r   r4  )err_arrcoord_label)i_xyzrj   rk   _digout_minmax  s   $$z'Axes3D.errorbar.<locals>._digout_minmax)has_xerrhas_yerrrj  )8r|  r   normalize_kwargsr5  r6  r  
setdefault_process_unit_infor   rK  r  r   _errorevery_to_maskrD   r  
_plot_argsr   r  
set_zorderrN  add_linere  rf  r  rP   dpi	transAxesr[   r\   r   r&  _setattr_cmr   r   r   r  r  get_dir_vectorr  r\  r  r7  r   r  Line3Dr	  r  r  r   r=  r  r1  
mcontainerErrorbarContainerrv  
containers)Dra   r   r   r   r  r  r  fmt	barsabove
erroreveryecolor
elinewidthcapsizecapthickxlolimsxuplimsylolimsyuplimszlolimszuplimsrw  re   r0  rj  	data_line
base_styler   eb_lines_styleeb_cap_styler  errlinescaplineslimmarks	coorderrs	capmarker
quiversizerK   eb_quiver_stylerz  r  i_zdircoorderrr  xhr  yhr  zhnolimslo_caps_xyzhi_caps_xyzcap_locap_hixh0yh0zh0xl0yl0zl0errliner  r   r   r   r   r   r   errorbar_containerrj   )r  r  r  r  r  r  r  rk   errorbar  s  q




















zAxes3D.errorbarcall_axes_locatorbbox_extra_artistsfor_layout_onlyc          	         s^   t  j||||d}|g}| jr)| j D ]}| r(t||}|r(|| qt	j
|S )Nr9  )rF   get_tightbboxrm   r   r   r   martist_get_tightbbox_for_layout_onlyr	  r   r
   union)	ra   r   r:  r;  r<  rv  batchr   axis_bbrh   rj   rk   r=  .  s    
zAxes3D.get_tightbboxzC0-C0ozC3-)linefmt	markerfmtbasefmtrq  rj  orientationrw  c                   s  ddl m} |  }tjg d|	d t|t|f}t|t|f}t|t|f}|	dkrM||}}||}} fddt|||D }n3|	dkri||}}||}} fd	dt|||D }n||}}||}} fd
dt|||D }t	|\}}}|du rt
jd }| j||| |	dd\}tj|||d|
d}| | | j||||dd\}||||f|d}| | t||  g|	\}}}| g ||g ||g ||| |S )a	  
        Create a 3D stem plot.

        A stem plot draws lines perpendicular to a baseline, and places markers
        at the heads. By default, the baseline is defined by *x* and *y*, and
        stems are drawn vertically from *bottom* to *z*.

        Parameters
        ----------
        x, y, z : array-like
            The positions of the heads of the stems. The stems are drawn along
            the *orientation*-direction from the baseline at *bottom* (in the
            *orientation*-coordinate) to the heads. By default, the *x* and *y*
            positions are used for the baseline and *z* for the head position,
            but this can be changed by *orientation*.

        linefmt : str, default: 'C0-'
            A string defining the properties of the vertical lines. Usually,
            this will be a color or a color and a linestyle:

            =========  =============
            Character  Line Style
            =========  =============
            ``'-'``    solid line
            ``'--'``   dashed line
            ``'-.'``   dash-dot line
            ``':'``    dotted line
            =========  =============

            Note: While it is technically possible to specify valid formats
            other than color or color and linestyle (e.g. 'rx' or '-.'), this
            is beyond the intention of the method and will most likely not
            result in a reasonable plot.

        markerfmt : str, default: 'C0o'
            A string defining the properties of the markers at the stem heads.

        basefmt : str, default: 'C3-'
            A format string defining the properties of the baseline.

        bottom : float, default: 0
            The position of the baseline, in *orientation*-coordinates.

        label : str, optional
            The label to use for the stems in legends.

        orientation : {'x', 'y', 'z'}, default: 'z'
            The direction along which stems are drawn.

        axlim_clip : bool, default: False
            Whether to hide stems that are outside the axes limits.

            .. versionadded:: 3.10

        data : indexable object, optional
            DATA_PARAMETER_PLACEHOLDER

        Returns
        -------
        `.StemContainer`
            The container may be treated like a tuple
            (*markerline*, *stemlines*, *baseline*)

        Examples
        --------
        .. plot:: gallery/mplot3d/stem3d_demo.py
        r   )StemContainerr   )rG  r   c                    s&   g | ]\}}} ||f|||fgqS rj   rj   r   thisxthisythiszrq  rj   rk   r        zAxes3D.stem.<locals>.<listcomp>r   c                    s&   g | ]\}}}| |f|||fgqS rj   rj   rI  rM  rj   rk   r    rN  c                    s&   g | ]\}}}|| f|||fgqS rj   rj   rI  rM  rj   rk   r    rN  Nzlines.linestyler  )r  rz  rj  )
linestylesr  rj  rw  )rj  )matplotlib.containerrH  r|  r   r   r   rK  r   r  r	   re  rf  r  r   r  r  add_containerr  r1  )ra   r   r   r   rD  rE  rF  rq  rj  rG  rw  rH  r0  r   r   r   basexbasexlimbaseybaseylimr  r  
linemarker	linecolorbaseline	stemlines
markerlinestem_containerjxjyjzrj   rM  rk   stem>  sX   G
















(zAxes3D.stemr   )NNF)Tr  N)NN)NTTT)NNN)NNNr   F)F)r   r   r   )rH  NFF)T)r  )r  )Fr  r   NF)r   N)r   NF)r   r   T)r   r   rO  NT)r   r   )Nrb  TN)Nrr  )NNNr  Fr   NNNNFFFFFFF)__name__
__module____qualname____doc__r  r  r   Grouperr   r@   rG   rH   rI   rt   rW   r   r   r   get_zgridlinesget_zticklinesr   r   r   r   r   r>  allow_rasterizationr   r  r	  r$  r#  r  r  r  r&  r1  rM   r  rR  r;  r<  r=  rh  rU  rZ  r]  r   r   r   rw  ry  rz  
get_zscale
set_xscale
set_yscale
set_zscalemapformat
get_zticks
set_zticksget_zmajorticklabelsget_zminorticklabelsget_zticklabelsset_zticklabels
zaxis_datetextwrapdedentr  r>   r8   r7  r   r  r   r   rO   r  r  r  r#   r"   r  rU   rV   r  r  r  r  r  r  r  r  r   r  rT   r)  r  r\  rM  r+  r  ri  rl  get_frame_onset_frame_onr  rq  ru  r^  r\  rx  text3Dtext2Dr  plot3Dr  r  r  r  r  r!  r$  r#  r   r.  	contour3Dr3  r;  r<  
contourf3Dr=  r  rV  	scatter3Dr[  rq  rs  r  quiver3Dr  r8  r=  r_  stem3D__classcell__rj   rj   rh   rk   r   )   s   	
 

V);

$#; HHH









M
;

%!^$0&
,  H|f
*
9
$4CP; ( X  Nzr   rQ  c                 C   s   t dd|  }}t ||\}}t |d |d   d dt j  }t |d d d |d d d   d dt j d d  }|| }|d }|d }|d }|||fS )	z,Return a tuple X, Y, Z with a test data set.g      g      @r   r   g      ?r  r  i  )r   r  meshgridexprD  )rA  r   r   r-  r.  Z1Z2r/  rj   rj   rk   get_test_data  s   &*
r  c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zed
d Z	dd Z
dd Zdd ZeZdd Zdd Zdd Zedd Zedd Zdd ZdS )r"  zb
    Quaternions
    consisting of scalar, along 1, and vector, with components along i, j, k
    c                 C   s   || _ t|| _d S r   )scalarr   r   vector)ra   r  r  rj   rj   rk   rG     s   z_Quaternion.__init__c                 C   s   |  | j | j S r   ri   r  r  ro   rj   rj   rk   __neg__  s   z_Quaternion.__neg__c                 C   sH   |  | j|j t| j|j | j|j | j|j  t| j|j S )a  
        Product of two quaternions
        i*i = j*j = k*k = i*j*k = -1
        Quaternion multiplication can be expressed concisely
        using scalar and vector parts,
        see <https://en.wikipedia.org/wiki/Quaternion#Scalar_and_vector_parts>
        )ri   r  r   r  r  crossra   r  rj   rj   rk   __mul__  s   z_Quaternion.__mul__c                 C   s   |  | j| j S )z5The conjugate quaternion -(1/2)*(q+i*q*i+j*q*j+k*q*k)r  ro   rj   rj   rk   	conjugate  s   z_Quaternion.conjugatec                 C   s   | j | j  t| j| j S )zThe 2-norm, q*q', a scalar)r  r   r  r  ro   rj   rj   rk   r     s   z_Quaternion.normc                 C   s$   t | j}| | j| | j| S )zScaling such that norm equals 1)r   r  r   ri   r  r  ra   r  rj   rj   rk   r{    s   z_Quaternion.normalizec                 C   s    | j }| | j| | j | S )z.The reciprocal, 1/q = q'/(q*q') = q' / norm(q))r   ri   r  r  r  rj   rj   rk   
reciprocal  s   z_Quaternion.reciprocalc                 C   s   | |   S r   )r  r  rj   rj   rk   __div__  s   z_Quaternion.__div__c                 C   s   |  d|}| | |  }|jS )Nr   )ri   r  )ra   r  rj   rj   rk   rotate  s   z_Quaternion.rotatec                 C   s   | j |j ko| j|jkjS r   )r  r  r  r  rj   rj   rk   __eq__  s   z_Quaternion.__eq__c                 C   s   d t| jt| jS )Nz_Quaternion({}, {}))rm  reprr  r  ro   rj   rj   rk   __repr__  s   z_Quaternion.__repr__c                 C   s   t ||}t j|}t |t ||}|d }|dkrWt ||dk rNtd t d}d|t 	|| < t ||}|t j| }| d|}|S | dg d}|S | t 
||t | | }|S )a  
        The quaternion for the shortest rotation from vector r1 to vector r2
        i.e., q = sqrt(r2*r1'), normalized.
        If r1 and r2 are antiparallel, then the result is ambiguous;
        a normal vector will be returned, and a warning will be issued.
        r   r   z6Rotation defined by anti-parallel vectors is ambiguousr   r   rc  )r   r  r   r   arctan2r  warningswarnr
  r  r  r  )clsr  r  r2  r3  r4  r1  rj   rj   rk   r$    s"   


z_Quaternion.rotate_from_toc                 C   s   t |d t |d }}t |d t |d }}t |d t |d }}	|| | || |	  }
|| |	 || |  }|| | || |	  }|| |	 || |  }| |
|||gS )z
        Converts the angles to a quaternion
            q = exp((roll/2)*e_x)*exp((elev/2)*e_y)*exp((-azim/2)*e_z)
        i.e., the angles are a kind of Tait-Bryan angles, -z,y',x".
        The angles should be given in radians, not degrees.
        r   )r   r  r  )r  r   r    r!   casacesecrsrqwqxqyqzrj   rj   rk   r#  %  s   z_Quaternion.from_cardan_anglesc                 C   s   | j }| jdddf \}}}td| | ||   || ||  ||  ||  }ttd|| ||   || ||  ||  ||   dd}td|| ||   || ||  ||  ||  }|||fS )z
        The inverse of `from_cardan_angles()`.
        Note that the angles returned are in radians, not degrees.
        The angles are not sensitive to the quaternion's norm().
        .Nr   r  r   )r  r  r   r  arcsinrL  )ra   r  r  r  r  r    r   r!   rj   rj   rk   r&  7  s   :D8
z_Quaternion.as_cardan_anglesN)r`  ra  rb  rc  rG   r  r  r  propertyr   r{  r  r  __truediv__r  r  r  classmethodr$  r#  r&  rj   rj   rj   rk   r"    s(    


r"  )rQ  )7rc  collectionsr   r  r  ru  r  numpyr   
matplotlibre  r   r   r   r   matplotlib.artistr   r>  matplotlib.collectionsr   matplotlib.colorsr  r  matplotlib.imageimager3  matplotlib.linesr  r5  matplotlib.patchesrX  r   rP  	containerr  matplotlib.transforms
transformsr   matplotlib.axesr   matplotlib.axes._baser   r	   r
   matplotlib.tri._triangulationr   r  r   r   r   interpddefine_aliasesr   r  r"  rj   rj   rj   rk   <module>   s|                                   
/