3
#ßL]– ã               @   s  d Z ddlmZ ddlmZ ddlZddlZddlm	Z	 ddl
jZddljZddljZddljZddljZddljZddljZddljZddl
mZ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&m(Z( d
dl&m)Z) dd„ Z*G dd„ deƒZ+ddd„Z,ej-j.e+ƒ d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.
é    )Údefaultdict)ÚreduceN)Úartist)ÚAxesÚrcParams)Ú	NormalizeÚLightSource)ÚBbox)ÚTriangulationé   )Úart3d)Úproj3d)Úaxis3dc              C   s   t tjddgddggƒƒ} | S )Nr   r   )r	   ÚnpÚarray)Zbox© r   úC/tmp/pip-install-edjban26/matplotlib/mpl_toolkits/mplot3d/axes3d.pyÚ	unit_bbox%   s    r   c                   s  e Zd ZdZdZejƒ Zej	dßdàdddddœ‡ fdd	„ƒZ
d
d„ Zdd„ Zdd„ Zdd„ Zdá‡ fdd„	Z‡ fdd„Zdd„ Zdd„ Z‡ fdd„Zdâdd„Zdãdd„Zdäd d!„Zej‡ fd"d#„ƒZd$d%„ Zdåd'd(„Zd)d*„ Z‡ fd+d,„Zd-d.„ Z‡ fd/d0„Zd1d2„ Z d3d4„ Z!dddd5d6œd7d8„Z"dæd:d;„Z#dçd<d=„Z$dèd>d?„Z%d@dA„ Z&dédBdC„Z'dêdddDœdEdF„Z(e(Z)dëdddGœdHdI„Z*e*Z+dìdddJœdKdL„Z,e,Z-dMdN„ Z.e/j0j1je._e.Z1e1jdk	�rÂe1 jdO7  _dPdQ„ Z2e/j0j3je2_e2Z3e3jdk	�rôe3 jdR7  _dSdT„ Z4e4Z5dUdV„ Z6dWdX„ Z7e/j0j7jdk	�r0e/j0j7jdY e7_dZd[„ Z8e/j0j8jdk	�rXe/j0j8jdY e8_d\d]„ Z9d^d_„ Z:díd`da„Z;dbdc„ Z<ddde„ Z=dfdg„ Z>dîdhdi„Z?dïdjdk„Z@dldm„ ZAdndo„ ZBdðdpdq„ZCdrds„ ZDdtdu„ ZEdñdxdy„ZFdzd{„ ZGd|d}„ ZH‡ fd~d„ZId€d�„ ZJd‚dƒ„ ZKd„d…„ ZLd†d‡„ ZMdˆd‰„ ZNdŠd‹„ ZOdòdŒd�„ZPdŽd�„ ZQd�d‘„ ZRd’d“„ ZSdód”d•„ZTd–ddd9d—œd˜d™„ZUdôdšd›„ZVdõ‡ fdœd�„	ZWdždŸ„ ZXd d¡„ ZYd¢d£„ ZZdöd¤d¥„Z[d÷‡ fd¦d§„	Z\e\Z]e0j\Z^d¨d©œ‡ fdªd«„
Z_e_Z`ddddd¬œd­d®„Zad¯d°„ Zbdød±d²„Zcd³d´„ Zdddddddµœd¶d·„Zedùd¹dº„Zfdúd»d¼„Zgdûd½d¾„Zhd&d¸d¨dd¿œ‡ fdÀdÁ„
ZieiZjd&d¸d¨dd¿œ‡ fdÂdÃ„
Zkd¨ddÄœ‡ fdÅdÆ„
ZlelZmd¨ddÄœ‡ fdÇdÈ„
Zndü‡ fdÊdË„	Zodý‡ fdÍdÎ„	ZpepZqdþ‡ fdÏdÐ„	ZrdÿdÒdÓ„Zs�d ‡ fdÕdÖ„	Ztdvd×dØd&dÙœdÚdÛ„ZueuZvddd5ddÜœdÝdÞ„Zw‡  ZxS (  ÚAxes3Dz
    3D axes object.
    Z3dNé<   é   Úpersp)ÚazimÚelevÚzscaleÚsharezÚ	proj_typec               s†  |dkrddddg}g ˆ _ |ˆ _|ˆ _ˆ j|ƒ tƒ ˆ _tƒ ˆ _tƒ ˆ _tƒ ˆ _ˆ j	ˆ jˆ jƒ dˆ _
|ˆ _|dk	rˆˆ jjˆ |ƒ dˆ _tƒ j||f|žddi|	—Ž tƒ jƒ  ˆ jƒ  dˆ _dˆ _|dk	rÖˆ j|ƒ ˆ jdk	rüˆ jjjd‡ fd	d
„ƒˆ _ndˆ _dˆ _
ˆ jƒ  ˆ jƒ  ˆ jjdƒ ˆ jjƒ j ddgƒ}
|
d |
d  \ˆ _!ˆ _"ˆ j#j$ˆ ƒ x$ˆ j%j&ƒ D ]}ˆ j%| j'dƒ �qhW dS )a  
        Parameters
        ----------
        fig : Figure
            The parent figure.
        rect : (float, float, float, float)
            The ``(left, bottom, width, height)`` axes position.
        azim : float, optional
            Azimuthal viewing angle, defaults to -60.
        elev : float, optional
            Elevation viewing angle, defaults to 30.
        zscale : [%(scale)s], optional
            The z scale.  Note that currently, only a linear scale is
            supported.
        sharez : Axes3D, optional
            Other axes to share z-limits with.
        proj_type : {'persp', 'ortho'}
            The projection type, default 'persp'.

        Notes
        -----
        .. versionadded:: 1.2.1
            The *sharez* parameter.
        Ng        g      ð?r   ZdatalimZframeonTzunits finalizec                  s   ˆ j dd�S )NT)Úscalez)Ú_on_units_changedr   )Úselfr   r   Ú<lambda>t   s    z!Axes3D.__init__.<locals>.<lambda>r   F)r   r   )r   r   )(Ú_cidsÚinitial_azimÚinitial_elevÚset_proj_typer   Ú
xy_viewLimÚ
zz_viewLimÚ
xy_dataLimÚ
zz_dataLimÚ	view_initÚ_readyÚ_sharezÚ_shared_z_axesÚjoinZ_adjustableÚsuperÚ__init__Úset_axis_offÚset_axis_onÚMÚ	fmt_zdataÚ
set_zscaleÚzaxisÚ	callbacksÚconnectZ_zcidÚ
mouse_initÚset_top_viewÚpatchZset_linewidthZtransLimitsÚinvertedZ	transformÚ	_pseudo_wÚ	_pseudo_hÚfigureZadd_axesZspinesÚkeysZset_visible)r   ZfigZrectr   r   r   r   r   ÚargsÚkwargsZpseudo_bboxÚk)Ú	__class__)r   r   r/   1   sH    



zAxes3D.__init__c             C   s   d| _ d| _d S )NFT)Ú	_axis3donÚstale)r   r   r   r   r0   ˆ   s    zAxes3D.set_axis_offc             C   s   d| _ d| _d S )NT)rD   rE   )r   r   r   r   r1   Œ   s    zAxes3D.set_axis_onc             C   s   | j jƒ p| jjƒ p| jjƒ S )zN
        Return *True* if units are set on the *x*, *y*, or *z* axes

        )ÚxaxisÚ
have_unitsÚyaxisr5   )r   r   r   r   rG   �   s    zAxes3D.have_unitsc             C   s   | j j|ƒS )z–
        For artists in an axes, if the zaxis has units support,
        convert *z* using zaxis unit type

        .. versionadded :: 1.2.1

        )r5   Zconvert_units)r   Úzr   r   r   Úconvert_zunits˜   s    zAxes3D.convert_zunitsc                sš   t ƒ j|||d� | jdks0| jdks0| jdkr4dS |dk	rR| jjƒ sR| jj|ƒ |dk	r–|jd| jjƒ}|| jjkr–| jj	|ƒ |dk	r–| jj|ƒ dS )zT
        Look for unit *kwargs* and update the axis instances as necessary

        )ÚxdataÚydatarA   NÚzunits)
r.   Ú_process_unit_inforF   rH   r5   rG   Zupdate_unitsÚpopZunitsZ	set_units)r   rK   rL   ÚzdatarA   rM   )rC   r   r   rN   ¢   s    
zAxes3D._process_unit_infoc                sT   d| j  }d| j  }d| j  }d| j  }tƒ j| |d d� tƒ j| |d d� d S )Ngffffffî?gÍÌÌÌÌÌì?)Úauto)Údistr.   Úset_xlimÚset_ylim)r   ZxdwlZxdwZydwlZydw)rC   r   r   r9   ¼   s    



zAxes3D.set_top_viewc             C   sŒ   t jd| jj| jj| ƒ| _t jd| jj| jj| ƒ| _t j	d| j
j| jj| ƒ| _| j| _| j| _| j| _x | j| j| jfD ]}|jƒ  qxW dS )z4Init 3D axes; overrides creation of regular X/Y axesÚxÚyrI   N)r   ZXAxisr%   Ú	intervalxr'   rF   ZYAxisÚ	intervalyrH   ZZAxisr&   r(   r5   Zw_xaxisZw_yaxisZw_zaxisZinit3d)r   Zaxr   r   r   Ú
_init_axisÉ   s    zAxes3D._init_axisc             C   s   | j S )z0Return the ``ZAxis`` (`~.axis3d.Axis`) instance.)r5   )r   r   r   r   Ú	get_zaxisÙ   s    zAxes3D.get_zaxisc                s   t ƒ jƒ | jf S )N)r.   Ú_get_axis_listr5   )r   )rC   r   r   r[   Ý   s    zAxes3D._get_axis_listc          
   C   s\   |p
| j ƒ \}}}}}}|||f|||f|||f|||f|||f|||f|||f|||fgS )N)Ú
get_w_lims)r   ÚvalsÚminxÚmaxxÚminyÚmaxyÚminzÚmaxzr   r   r   Ú	unit_cubeà   s    zAxes3D.unit_cubec             C   s(   |d kr| j }| j|ƒ}tj||ƒ}|S )N)r2   rd   r   Zproj_points)r   r]   r2   ZxyzsZtcuber   r   r   Ú
tunit_cubeë   s
    
zAxes3D.tunit_cubec             C   s¼   | j ||ƒ}|d |d f|d |d f|d |d f|d |d f|d |d f|d |d f|d |d f|d |d f|d |d f|d |d f|d |d f|d |d fg}|S )	Nr   r   é   é   é   é   é   é   )re   )r   r]   r2   ÚtcÚedgesr   r   r   Útunit_edgesò   s    zAxes3D.tunit_edgesc       	         s:  | j jˆ ƒ d| _| jƒ }|r4|| ˆ ƒ}| j|ƒ n| jƒ  | jƒ | _| jˆ _| jˆ _| jˆ _| j	ˆ _	t
dd„ | jƒ D ƒƒd }x2tt| j‡ fdd„dd�ƒD ]\}}|| |_qžW x2tt| j‡ fd	d„dd�ƒD ]\}}|| |_qÒW | j�r*x| jƒ D ]}|jˆ ƒ qúW x| jƒ D ]}|jˆ ƒ �qW tƒ jˆ ƒ d S )
NFc             s   s   | ]}|j ƒ V  qd S )N)Z
get_zorder)Ú.0Úaxisr   r   r   ú	<genexpr>  s   zAxes3D.draw.<locals>.<genexpr>r   c                s
   | j ˆ ƒS )N)Údo_3d_projection)Úcol)Úrendererr   r   r    #  s    zAxes3D.draw.<locals>.<lambda>T)ÚkeyÚreversec                s
   | j ˆ ƒS )N)rr   )r:   )rt   r   r   r    (  s    )r:   ÚdrawÚ_frameonZget_axes_locatorZapply_aspectÚget_projr2   ÚvvecÚeyeÚget_axis_positionÚmaxr[   Ú	enumerateÚsortedÚcollectionsZzorderÚpatchesrD   Z	draw_paner.   )	r   rt   ÚlocatorÚposZzorder_offsetÚirs   r:   rp   )rC   )rt   r   rw     s<    



zAxes3D.drawc             C   sh   | j ƒ }| j|| jƒ}|d d |d d k}|d d |d d k}|d d |d d k}|||fS )Nr   rf   rg   r   )r\   re   r2   )r   r]   rl   ZxhighZyhighZzhighr   r   r   r|   7  s    zAxes3D.get_axis_positionFc             C   s   | j ƒ  | j|||d� dS )z‚
        Callback for processing changes to axis units.

        Currently forces updates of data limits and view limits.
        )ÚscalexÚscaleyr   N)ZrelimÚautoscale_view)r   r…   r†   r   r   r   r   r   ?  s    zAxes3D._on_units_changedc             K   s   d S )Nr   )r   ZxysrA   r   r   r   Úupdate_datalimH  s    zAxes3D.update_datalimc                s   t ƒ jƒ o| jƒ S )zÁ
        Get whether autoscaling is applied for all axes on plot commands

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        )r.   Úget_autoscale_onÚget_autoscalez_on)r   )rC   r   r   r‰   K  s    zAxes3D.get_autoscale_onc             C   s   | j S )zÃ
        Get whether autoscaling for the z-axis is applied on plot commands

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        )Ú_autoscaleZon)r   r   r   r   rŠ   T  s    zAxes3D.get_autoscalez_onc                s   t ƒ j|ƒ | j|ƒ dS )zì
        Set whether autoscaling is applied on plot commands

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.

        Parameters
        ----------
        b : bool
        N)r.   Úset_autoscale_onÚset_autoscalez_on)r   Úb)rC   r   r   rŒ   ]  s    zAxes3D.set_autoscale_onc             C   s
   || _ dS )zû
        Set whether autoscaling for the z-axis is applied on plot commands

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.

        Parameters
        ----------
        b : bool
        N)r‹   )r   rŽ   r   r   r   r�   k  s    zAxes3D.set_autoscalez_onc             C   s(   |dk s|dkrt dƒ‚|| _d| _dS )aU  
        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.

        accepts: float in range 0 to 1

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        r   r   zmargin must be in range 0 to 1TN)Ú
ValueErrorÚ_zmarginrE   )r   Úmr   r   r   Úset_zmarginx  s    zAxes3D.set_zmarginT)rU   rV   rI   Útightc            G   s  |r&|dk	r&|dk	r&|dk	r&t dƒ‚nBt|ƒdkrD|d  } }}n$t|ƒdkr\|\}}}n|rht dƒ‚|dkrª|dkrª|dkrª|dk	rštjd|›d	�ƒ | j| j| jfS |dk	r¼| j|ƒ |dk	rÎ| j|ƒ |dk	rà| j	|ƒ | j
||dk	|dk	|dk	d
� dS )aS  
        Convenience method to set or retrieve autoscaling margins.

        signatures::
            margins()

        returns xmargin, ymargin, zmargin

        ::

            margins(margin)

            margins(xmargin, ymargin, zmargin)

            margins(x=xmargin, y=ymargin, z=zmargin)

            margins(..., tight=False)

        All forms above set the xmargin, ymargin and zmargin
        parameters. All keyword parameters are optional.  A single
        positional argument specifies xmargin, ymargin and zmargin.
        Passing both positional and keyword arguments for xmargin,
        ymargin, and/or zmargin is invalid.

        The *tight* parameter
        is passed to :meth:`autoscale_view`, which is executed after
        a margin is changed; the default here is *True*, on the
        assumption that when margins are specified, no additional
        padding to match tick marks is usually desired.  Setting
        *tight* to *None* will preserve the previous setting.

        Specifying any margin changes only the autoscaling; for example,
        if *xmargin* is not None, then *xmargin* times the X data
        interval will be added to each end of that interval before
        it is used in autoscaling.

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        NzECannot pass both positional and keyword arguments for x, y, and/or z.r   r   rg   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“   r…   r†   r   )Ú	TypeErrorÚlenÚcbookÚ_warn_externalÚ_xmarginÚ_ymarginr�   Zset_xmarginZset_ymarginr’   r‡   )r   rU   rV   rI   r“   Úmarginsr   r   r   rš   ‰  s*    (



zAxes3D.marginsÚbothc             C   s€   |dkrd}d}d}nT|d	kr.t |ƒ | _}nd}|d
krJt |ƒ | _}nd}|dkrft |ƒ | _}nd}| j||||d� dS )a¨  
        Convenience method for simple axis view autoscaling.
        See :meth:`matplotlib.axes.Axes.autoscale` for full explanation.
        Note that this function behaves the same, but for all
        three axes.  Therefore, 'z' can be passed for *axis*,
        and 'both' applies to all three axes.

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        NTrU   r›   FrV   rI   )r“   r…   r†   r   )rU   r›   )rV   r›   )rI   r›   )ÚboolÚ_autoscaleXonÚ_autoscaleYonr‹   r‡   )r   Úenablerp   r“   r…   r†   r   r   r   r   Ú	autoscaleÍ  s    
zAxes3D.autoscalec             C   sl   t j|dƒ}t j|dƒ}| jjt j||gƒ| ƒ |d k	r`t j|dƒ}| jjt j||gƒ| ƒ | jƒ  d S )Nr   éÿÿÿÿr¡   r¡   )r   Úreshaper'   Zupdate_from_data_xyÚcolumn_stackr(   r‡   )r   ÚXÚYÚZÚhad_datar   r   r   Úauto_scale_xyzì  s    zAxes3D.auto_scale_xyzc             C   sò  | j s
dS |dkrL| jpHt| jƒdkoHt| jƒt| jƒ  koDdkn  }nt|ƒ }| _|rÜ| jrÜ| jj	ƒ  | j
j\}}| jjƒ }|j||ƒ\}}| jdkr¼|| | j }	||	8 }||	7 }|sÐ|j||ƒ\}}| j||ƒ |oä| j�rd| jj	ƒ  | j
j\}
}| jjƒ }|j|
|ƒ\}
}| jdk�rB||
 | j }	|
|	8 }
||	7 }|�sX|j|
|ƒ\}
}| j|
|ƒ |�rî| j�rî| jj	ƒ  | jj\}}| jjƒ }|j||ƒ\}}| jdk�rÌ|| | j }	||	8 }||	7 }|�sâ|j||ƒ\}}| j||ƒ dS )a  
        Autoscale the view limits using the data limits.
        See :meth:`matplotlib.axes.Axes.autoscale_view` for documentation.
        Note that this function applies to the 3D axes, and as such
        adds the *scalez* to the function arguments.

        .. versionchanged :: 1.1.0
            Function signature was changed to better match the 2D version.
            *tight* is now explicitly a kwarg and placed first.

        .. versionchanged :: 1.2.1
            This is now fully functional.

        Nr   )r*   Ú_tightr•   ZimagesÚlinesr�   rœ   r�   Ú_shared_x_axesÚcleanr'   rW   rF   Úget_major_locatorÚnonsingularr˜   Zview_limitsZ
set_xboundrž   Ú_shared_y_axesrX   rH   r™   Z
set_yboundr‹   r,   r(   r5   r�   Ú
set_zbound)r   r“   r…   r†   r   r©   Úx0Úx1ZxlocatorÚdeltaÚy0Úy1ZylocatorÚz0Úz1Zzlocatorr   r   r   r‡   ú  sV    &







zAxes3D.autoscale_viewc             C   s4   | j ƒ \}}| jƒ \}}| jƒ \}}||||||fS )zGet 3D world limits.)Ú
get_xlim3dÚ
get_ylim3dÚ
get_zlim3d)r   r^   r_   r`   ra   rb   rc   r   r   r   r\   >  s    zAxes3D.get_w_limsc             O   s:   |d krt j|ƒr|\}}||kr2|d8 }|d7 }||fS )Ngš™™™™™©?)r   Úiterable)r   ÚxminÚxmaxr@   rA   r   r   r   Ú_determine_limsE  s    zAxes3D._determine_lims)r¼   r½   c            C   s¶  |dkrt j|ƒr|\}}|dk	rHtjddddd� |dk	rDtdƒ‚|}|dk	rvtjddd	dd� |dk	rrtd
ƒ‚|}| j||fd� | j|| jƒ}| j|| jƒ}| jƒ \}}|dkrº|}|dkrÆ|}||kràtj	d|› d�ƒ ||k}	| j
jƒ j||ƒ\}}| j
j||ƒ\}}t||g|	d�\}}||f| j_|dk	�rDt|ƒ| _|�r¨| jjd| ƒ xN| jj| ƒD ]>}
|
| k	�rf|
j| jjd|d� |
j| jk�rf|
jjjƒ  �qfW d| _||fS )zn
        Set 3D x limits.

        See :meth:`matplotlib.axes.Axes.set_xlim` for full documentation.

        Nz3.0z`xmin`z`left`Úargument)ÚnameÚalternativeÚobj_typez"Cannot pass both `xmin` and `left`z`xmax`z`right`z#Cannot pass both `xmax` and `right`)rK   z-Attempting to set identical left == right == z> results in singular transformations; automatically expanding.)rv   Zxlim_changedF)ÚemitrQ   T)r   r»   r–   Úwarn_deprecatedr”   rN   Ú_validate_converted_limitsZconvert_xunitsÚget_xlimr—   rF   r­   r®   Úlimit_range_for_scaler   r%   rW   rœ   r�   r6   Úprocessr«   Úget_siblingsrS   r>   ÚcanvasÚ	draw_idlerE   )r   ÚleftÚrightrÃ   rQ   r¼   r½   Zold_leftZ	old_rightrv   Úotherr   r   r   Ú
set_xlim3dM  sT    






zAxes3D.set_xlim3d)ÚyminÚymaxc            C   s²  |dkrt j|ƒr|\}}|dk	rHtjddddd� |dk	rDtdƒ‚|}|dk	rvtjddd	dd� |dk	rrtd
ƒ‚|}| j||fd� | j|| jƒ}| j|| jƒ}| jƒ \}}|dkrº|}|dkrÆ|}||kràtj	d|› d�ƒ ||k}	| j
jƒ j||ƒ\}}| j
j||ƒ\}}|	�r || }}||f| j_|dk	�r@t|ƒ| _|�r¤| jjd| ƒ xN| jj| ƒD ]>}
|
| k	�rb|
j| jjd|d� |
j| jk�rb|
jjjƒ  �qbW d| _||fS )zn
        Set 3D y limits.

        See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation.

        Nz3.0z`ymin`z`bottom`r¿   )rÀ   rÁ   rÂ   z$Cannot pass both `ymin` and `bottom`z`ymax`z`top`z!Cannot pass both `ymax` and `top`)rL   z-Attempting to set identical bottom == top == z> results in singular transformations; automatically expanding.Zylim_changedF)rÃ   rQ   T)r   r»   r–   rÄ   r”   rN   rÅ   Zconvert_yunitsÚget_ylimr—   rH   r­   r®   rÇ   r%   rX   rœ   rž   r6   rÈ   r¯   rÉ   rT   r>   rÊ   rË   rE   )r   ÚbottomÚtoprÃ   rQ   rÐ   rÑ   Ú
old_bottomÚold_topÚswappedrÎ   r   r   r   Ú
set_ylim3dˆ  sV    







zAxes3D.set_ylim3d)ÚzminÚzmaxc            C   s²  |dkrt j|ƒr|\}}|dk	rHtjddddd� |dk	rDtdƒ‚|}|dk	rvtjddd	dd� |dk	rrtd
ƒ‚|}| j||fd� | j|| jƒ}| j|| jƒ}| jƒ \}}|dkrº|}|dkrÆ|}||kràtj	d|› d�ƒ ||k}	| j
jƒ j||ƒ\}}| j
j||ƒ\}}|	�r || }}||f| j_|dk	�r@t|ƒ| _|�r¤| jjd| ƒ xN| jj| ƒD ]>}
|
| k	�rb|
j| jjd|d� |
j| jk�rb|
jjjƒ  �qbW d| _||fS )zm
        Set 3D z limits.

        See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation

        Nz3.0z`zmin`z`bottom`r¿   )rÀ   rÁ   rÂ   z$Cannot pass both `zmin` and `bottom`z`zmax`z`top`z!Cannot pass both `zmax` and `top`)rP   z-Attempting to set identical bottom == top == z> results in singular transformations; automatically expanding.Zzlim_changedF)rÃ   rQ   T)r   r»   r–   rÄ   r”   rN   rÅ   rJ   Úget_zlimr—   r5   r­   r®   rÇ   r&   rW   rœ   r‹   r6   rÈ   r,   rÉ   Úset_zlimr>   rÊ   rË   rE   )r   rÓ   rÔ   rÃ   rQ   rÙ   rÚ   rÕ   rÖ   r×   rÎ   r   r   r   Ú
set_zlim3dÅ  sV    







zAxes3D.set_zlim3dc             C   s   t | jjƒS )N)Útupler%   rW   )r   r   r   r   r¸     s    zAxes3D.get_xlim3dzn
        .. versionchanged :: 1.1.0
            This function now correctly refers to the 3D x-limits
        c             C   s   t | jjƒS )N)rÞ   r%   rX   )r   r   r   r   r¹     s    zAxes3D.get_ylim3dzo
        .. versionchanged :: 1.1.0
            This function now correctly refers to the 3D y-limits.
        c             C   s   t | jjƒS )zGet 3D z limits.)rÞ   r&   rW   )r   r   r   r   rº     s    zAxes3D.get_zlim3dc             C   s   ddj tjƒ ƒ  | jjƒ S )Nz3
        Return the zaxis scale string %s

        z, )r-   ÚmscaleZget_scale_namesr5   Ú	get_scale)r   r   r   r   Ú
get_zscale  s    zAxes3D.get_zscalec             K   s*   | j j|f|Ž | jddd� | jƒ  d S )NF)r†   r   )rF   Ú
_set_scaler‡   Ú_update_transScale)r   ÚvaluerA   r   r   r   Ú
set_xscale$  s    zAxes3D.set_xscalezw
        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        c             K   s0   | j j|f|Ž | jddd� | jƒ  d| _d S )NF)r…   r   T)rH   râ   r‡   rã   rE   )r   rä   rA   r   r   r   Ú
set_yscale.  s    zAxes3D.set_yscalec             K   s0   | j j|f|Ž | jddd� | jƒ  d| _dS )a¸  
        Set the z-axis scale.

        Parameters
        ----------
        value : {"linear", "log", "symlog", "logit", ...}
            The axis scale type to apply.

        **kwargs
            Different keyword arguments are accepted, depending on the scale.
            See the respective class keyword arguments:

            - `matplotlib.scale.LinearScale`
            - `matplotlib.scale.LogScale`
            - `matplotlib.scale.SymmetricalLogScale`
            - `matplotlib.scale.LogitScale`

        Notes
        -----
        Currently, Axes3D objects only supports linear scales.
        Other scales may or may not work, and support for these
        is improving with each release.

        By default, Matplotlib supports the above mentioned scales.
        Additionally, custom scales may be registered using
        `matplotlib.scale.register_scale`. These scales may then also
        be used here as support is added.
        F)r…   r†   TN)r5   râ   r‡   rã   rE   )r   rä   rA   r   r   r   r4   9  s    zAxes3D.set_zscalec             O   s   | j j||ŽS )zÑ
        Set z-axis tick locations.
        See :meth:`matplotlib.axes.Axes.set_yticks` for more details.

        .. note::
            Minor ticks are not supported.

        .. versionadded:: 1.1.0
        )r5   Z	set_ticks)r   r@   rA   r   r   r   Ú
set_zticks[  s    
zAxes3D.set_zticksc             C   s   | j j|d�S )zà
        Return the z ticks as a list of locations
        See :meth:`matplotlib.axes.Axes.get_yticks` for more details.

        .. note::
            Minor ticks are not supported.

        .. versionadded:: 1.1.0
        )Úminor)r5   Zget_ticklocs)r   rè   r   r   r   Ú
get_zticksg  s    
zAxes3D.get_zticksc             C   s   t jd| jjƒ ƒS )zd
        Get the ztick labels as a list of Text instances

        .. versionadded :: 1.1.0
        zText zticklabel)r–   Úsilent_listr5   Zget_majorticklabels)r   r   r   r   Úget_zmajorticklabelss  s    zAxes3D.get_zmajorticklabelsc             C   s   t jd| jjƒ ƒS )zÝ
        Get the ztick labels as a list of Text instances

        .. note::
            Minor ticks are not supported. This function was added
            only for completeness.

        .. versionadded :: 1.1.0
        zText zticklabel)r–   rê   r5   Zget_minorticklabels)r   r   r   r   Úget_zminorticklabels|  s    
zAxes3D.get_zminorticklabelsc             O   s   | j j||ŽS )zå
        Set z-axis tick labels.
        See :meth:`matplotlib.axes.Axes.set_yticklabels` for more details.

        .. note::
            Minor ticks are not supported by Axes3D objects.

        .. versionadded:: 1.1.0
        )r5   Zset_ticklabels)r   r@   rA   r   r   r   Úset_zticklabels‰  s    
zAxes3D.set_zticklabelsc             C   s   t jd| jj|d�ƒS )zé
        Get ztick labels as a list of Text instances.
        See :meth:`matplotlib.axes.Axes.get_yticklabels` for more details.

        .. note::
            Minor ticks are not supported.

        .. versionadded:: 1.1.0
        zText zticklabel)rè   )r–   rê   r5   Zget_ticklabels)r   rè   r   r   r   Úget_zticklabels•  s    
zAxes3D.get_zticklabelsc             C   s   | j j|ƒ dS )aï  
        Sets up z-axis ticks and labels that treat the z data as dates.

        *tz* is a timezone string or :class:`tzinfo` instance.
        Defaults to rc value.

        .. note::
            This function is merely provided for completeness.
            Axes3D objects do not officially support dates for ticks,
            and so this may or may not work as expected.

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        N)r5   Z	axis_date)r   Útzr   r   r   Ú
zaxis_date¢  s    zAxes3D.zaxis_datec             C   s
   | j jƒ S )zä
        Get ztick lines as a list of Line2D instances.
        Note that this function is provided merely for completeness.
        These lines are re-calculated as the display changes.

        .. versionadded:: 1.1.0
        )r5   Zget_ticklines)r   r   r   r   Úget_zticklines³  s    zAxes3D.get_zticklinesc             O   s   dS )za
        This function is currently not implemented for 3D axes.
        Returns *None*.
        Nr   )r   r@   rA   r   r   r   Úclabel½  s    zAxes3D.clabelc             C   s:   d| _ |dkr| j| _n|| _|dkr0| j| _n|| _dS )a¯  
        Set the elevation and azimuth of the axes in degrees (not radians).

        This can be used to rotate the axes programmatically.

        'elev' stores the elevation angle in the z plane (in degrees).
        'azim' stores the azimuth angle in the x,y plane (in degrees).

        if elev or azim are None (default), then the initial value
        is used which was specified in the :class:`Axes3D` constructor.
        é
   N)rR   r#   r   r"   r   )r   r   r   r   r   r   r)   Ä  s    

zAxes3D.view_initc             C   s4   |dkrt j| _n|dkr$t j| _ntd| ƒ‚dS )z§
        Set the projection type.

        Parameters
        ----------
        proj_type : str
            Type of projection, accepts 'persp' and 'ortho'.

        r   Zorthozunrecognized projection: %sN)r   Zpersp_transformationÚ_projectionZortho_transformationr�   )r   r   r   r   r   r$   Ý  s
    


zAxes3D.set_proj_typec             C   sl  t j| j d t j| j d  }}| jƒ \}}| jƒ \}}| jƒ \}}tj||||||ƒ}	t j	dddgƒ}
|
d t j
|ƒt j
|ƒ | j  }|
d t j|ƒt j
|ƒ | j  }|
d t j|ƒ| j  }t j	|||fƒ}|| _|
| | _| jt jj| jƒ | _t|ƒt jd k�rt j	dƒ}n
t j	dƒ}| j | j }}tj||
|ƒ}| j||ƒ}t j||	ƒ}t j||ƒ}|S )	a  
        Create the projection matrix from the current viewing position.

        elev stores the elevation angle in the z plane
        azim stores the azimuth angle in the x,y plane

        dist is the distance of the eye viewing point from the object
        point.

        é´   g      à?r   r   rf   r¡   )r   r   r¡   )r   r   r   )r   Úpir   r   r¸   r¹   rº   r   Zworld_transformationr   ÚcosrR   Úsinr{   rz   ÚlinalgÚnormÚabsZview_transformationrô   Údot)r   ZrelevZrazimr¼   r½   rÐ   rÑ   rÙ   rÚ   ZworldMÚRZxpZypZzpÚEÚVZzfrontZzbackZviewMZprojMZM0r2   r   r   r   ry   î  s0    """

zAxes3D.get_projr   rg   c             C   s`   d| _ | jjjd| jƒ| jjjd| jƒ| jjjd| jƒg| _tj	|ƒj
ƒ | _tj	|ƒj
ƒ | _dS )aÞ  
        Initializes mouse button callbacks to enable 3D rotation of the axes.
        Also optionally sets the mouse buttons for 3D rotation and zooming.

        Parameters
        ----------
        rotate_btn : int or list of int
            The mouse button or buttons to use for 3D rotation of the axes;
            defaults to 1.
        zoom_btn : int or list of int
            The mouse button or buttons to use to zoom the 3D axes; defaults to
            3.
        NZmotion_notify_eventZbutton_press_eventZbutton_release_event)Úbutton_pressedr>   rÊ   Zmpl_connectÚ_on_moveÚ_button_pressÚ_button_releaser!   r   Ú
atleast_1dÚtolistÚ_rotate_btnÚ	_zoom_btn)r   Z
rotate_btnZzoom_btnr   r   r   r8     s    zAxes3D.mouse_initc             C   s   dS )z‘
        Return *True* if this axes supports the zoom box button functionality.

        3D axes objects do not use the zoom box button.
        Fr   )r   r   r   r   Úcan_zoom:  s    zAxes3D.can_zoomc             C   s   dS )z‘
        Return *True* if this axes supports the pan/zoom button functionality.

        3D axes objects do not use the pan/zoom button.
        Fr   )r   r   r   r   Úcan_panB  s    zAxes3D.can_panc                sÀ   t ƒ jƒ  | jjƒ  | jdk	rp| jjj| j_| jjj| j_| jjƒ \}}| j||ddd� | jj| jjj	ƒ ƒ n2| jjdƒ y| jddƒ W n t
k
r    Y nX d| _d| _| jtd ƒ dS )	z
        Clear axes
        NF)rÃ   rQ   Zlinearr   r   Tzaxes3d.grid)r.   Úclar5   r+   Úmajorrè   rÛ   rÜ   râ   rà   r”   r‹   r�   Úgridr   )r   r¶   r·   )rC   r   r   r
  J  s     


z
Axes3D.clac             C   s(   x| j D ]}| jjj|ƒ qW g | _ dS )z(Disable mouse button callbacks.
        N)r!   r>   rÊ   Zmpl_disconnect)r   Zcidr   r   r   Údisable_mouse_rotationf  s    zAxes3D.disable_mouse_rotationc             C   s(   |j | kr$|j| _|j|j | _| _d S )N)ZinaxesÚbuttonr   rK   rL   ÚsxÚsy)r   Úeventr   r   r   r  o  s    
zAxes3D._button_pressc             C   s
   d | _ d S )N)r   )r   r  r   r   r   r  t  s    zAxes3D._button_releasec             C   s<   y
| j |ƒS  ttfk
r6   | jjƒ j}||ƒ}|S X dS )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
        N)r3   ÚAttributeErrorr”   r5   Zget_major_formatterZformat_data_short)r   rI   ÚfuncÚvalr   r   r   Úformat_zdataw  s    
zAxes3D.format_zdatac                sè   | j dkrdS | j| jkr*dj| j| jƒS t| jƒ ‡ ‡fdd„d�\}}|\}}}|\}}	}
tj	|ˆ  |ˆ ƒ}tj	|ˆ  |	ˆ ƒ}|| }|| | || |
  }t
jˆ ˆ|| j ƒ\}}}| j|ƒ}| j|ƒ}| j|ƒ}d|||f S )zå
        Given the 2D view coordinates attempt to guess a 3D coordinate.
        Looks for the nearest edge to the point and then assumes that
        the point is at the same z location as the nearest point on the edge.
        NÚ z)azimuth={:.0f} deg, elevation={:.0f} deg c                s   t j| d | d ˆ ˆfƒS )Nr   r   )r   Z_line2d_seg_dist)Zedge)ÚxdÚydr   r   r    •  s   z%Axes3D.format_coord.<locals>.<lambda>)ru   zx=%s, y=%s, z=%s)r2   r   r  Úformatr   r   Úminrn   r   Úhypotr   Zinv_transformZformat_xdataZformat_ydatar  )r   r  r  Úp0Úp1r±   r´   r¶   r²   rµ   r·   Zd0Zd1ÚdtrI   rU   rV   ÚxsÚysÚzsr   )r  r  r   Úformat_coord„  s$    





zAxes3D.format_coordc             C   s|  | j s
dS | jdkrdS |j|j }}|dkr2dS || j || j  }}| j}| j}|| | _| _| j | jkrÒ|dkr‚|dkr‚dS t	j
| j|| d  ƒ| _t	j
| j|| d  ƒ| _| jƒ  d| _| jjjƒ  n¦| j | jk�rx| jƒ \}}	}
}}}d|| |  }|	| | }||
 | }|| | }| j|| |	| ƒ | j|
| || ƒ | j|| || ƒ | jƒ  | jjjƒ  dS )z®Mouse moving

        button-1 rotates by default.  Can be set explicitly in mouse_init().
        button-3 zooms by default.  Can be set explicitly in mouse_init().
        Nr   rõ   Tr   )r   r2   rK   rL   r  r  r<   r=   r  r   Z_norm_angler   r   ry   rE   r>   rÊ   rË   r  r\   rÏ   rØ   rÝ   )r   r  rU   rV   ÚdxÚdyÚwÚhr^   r_   r`   ra   rb   rc   ZdfÚdzr   r   r   r  §  s<    
	zAxes3D._on_movec             K   s"   |dk	r|| j _| j j||f|ŽS )zN
        Set zlabel.  See doc for :meth:`set_ylabel` for description.
        N)r5   ÚlabelpadZset_label_text)r   ZzlabelÚfontdictr(  rA   r   r   r   Ú
set_zlabelß  s    zAxes3D.set_zlabelc             C   s   | j jƒ }|jƒ S )z�
        Get the z-label text string.

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        )r5   Z	get_labelZget_text)r   Úlabelr   r   r   Ú
get_zlabelç  s    
zAxes3D.get_zlabelc             C   s   | j S )z]
        Get whether the 3D axes panels are drawn.

        .. versionadded :: 1.1.0
        )rx   )r   r   r   r   Úget_frame_onó  s    zAxes3D.get_frame_onc             C   s   t |ƒ| _d| _dS )z•
        Set whether the 3D axes panels are drawn.

        .. versionadded :: 1.1.0

        Parameters
        ----------
        b : bool
        TN)rœ   rx   rE   )r   rŽ   r   r   r   Úset_frame_onû  s    

zAxes3D.set_frame_onc             K   s   t |ƒrd}|| _d| _dS )aa  
        Set / unset 3D grid.

        .. note::

            Currently, this function does not behave the same as
            :meth:`matplotlib.axes.Axes.grid`, but it is intended to
            eventually support that behavior.

        .. versionchanged :: 1.1.0
            This function was changed, but not tested. Please report any bugs.
        TN)r•   Z
_draw_gridrE   )r   rŽ   rA   r   r   r   r    s    zAxes3D.gridr  )ÚstyleÚ	scilimitsÚ	useOffsetrp   c            C   s¶  |j ƒ }|j ƒ }|dk	rRy|\}}|| d  W n  ttfk
rP   tdƒ‚Y nX |dd… dkrhd}n$|dkrvd}n|d	kr„d}ntd
ƒ‚�y|dk	rà|dkr°| jjjj|ƒ |dkrÈ| jjjj|ƒ |dkrà| jjjj|ƒ |dk	�r8|dk�r| jjjj	|ƒ |dk�r| jjjj	|ƒ |dk�r8| jjjj	|ƒ |dk	�r�|dk�r\| jjjj
|ƒ |dk�rv| jjjj
|ƒ |dk�r�| jjjj
|ƒ W n tk
�r°   tdƒ‚Y nX dS )a$  
        Convenience method for manipulating the ScalarFormatter
        used by default for linear axes in Axed3D objects.

        See :meth:`matplotlib.axes.Axes.ticklabel_format` for full
        documentation.  Note that this version applies to all three
        axes of the Axes3D object.  Therefore, the *axis* argument
        will also accept a value of 'z' and the value of 'both' will
        apply to all three axes.

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        Nr   z*scilimits must be a sequence of 2 integersrg   ZsciTÚplainFr  z%s is not a valid style valuer›   rI   rV   rU   z0This method only works with the ScalarFormatter.)r›   rI   )r›   rV   )r›   rI   )r›   rU   )r›   rV   )r›   rI   )r›   rU   )r›   rV   )r›   rI   )Úlowerr�   r”   rF   r  Ú	formatterZset_scientificrH   r5   Zset_powerlimitsZset_useOffsetr  )r   r/  r0  r1  rp   r‘   ÚnZsbr   r   r   Úticklabel_format  sP    







zAxes3D.ticklabel_formatc             K   sp   |dk}|dk}|d	k}|r.| j jƒ jf |Ž |rD| jjƒ jf |Ž |rZ| jjƒ jf |Ž | j||||d� dS )
a   
        Convenience method for controlling tick locators.

        See :meth:`matplotlib.axes.Axes.locator_params` for full
        documentation.  Note that this is for Axes3D objects,
        therefore, setting *axis* to 'both' will result in the
        parameters being set for all three axes.  Also, *axis*
        can also take a value of 'z' to apply parameters to the
        z axis.

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        rU   r›   rV   rI   )r“   r…   r†   r   N)rU   r›   )rV   r›   )rI   r›   )rF   r­   Z
set_paramsrH   r5   r‡   )r   rp   r“   rA   Ú_xZ_yZ_zr   r   r   Úlocator_paramsT  s    zAxes3D.locator_paramsc                s€   t jddddg|d� |dkr.tƒ j|f|Ž |dkr|t|ƒ}|jddƒ |jddƒ |jd	dƒ |jd
dƒ | jjf |Ž dS )a(  
        Convenience method for changing the appearance of ticks and
        tick labels.

        See :meth:`matplotlib.axes.Axes.tick_params` for more complete
        documentation.

        The only difference is that setting *axis* to 'both' will
        mean that the settings are applied to all three axes. Also,
        the *axis* parameter also accepts a value of 'z', which
        would mean to apply to only the z-axis.

        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::
            While this function is currently implemented, the core part
            of the Axes3D object may ignore some of these settings.
            Future releases will fix this. Priority will be given to
            those who file bugs.

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        rU   rV   rI   r›   )rp   rÔ   NrÓ   ZlabeltopZlabelbottom)rU   rV   r›   )rI   r›   )r–   Z_check_in_listr.   Útick_paramsÚdictrO   r5   Zset_tick_params)r   rp   rA   Zzkw)rC   r   r   r9  m  s    zAxes3D.tick_paramsc             C   s    | j ƒ \}}| j||dd� dS )z“
        Invert the z-axis.

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        N)rQ   )rÛ   rÜ   )r   rÓ   rÔ   r   r   r   Úinvert_zaxis•  s    zAxes3D.invert_zaxisc             C   s   | j ƒ \}}||k S )z¨
        Returns True if the z-axis is inverted.

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        )rÛ   )r   rÓ   rÔ   r   r   r   Úzaxis_invertedŸ  s    zAxes3D.zaxis_invertedc             C   s(   | j ƒ \}}||k r||fS ||fS dS )zÏ
        Returns the z-axis numerical bounds where::

          lowerBound < upperBound

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        N)rÛ   )r   rÓ   rÔ   r   r   r   Ú
get_zbound©  s    	zAxes3D.get_zboundc             C   s    |dkrt j|ƒr|\}}| jƒ \}}|dkr2|}|dkr>|}| jƒ rr||k r`| j||dd� qœ| j||dd� n*||k rŒ| j||dd� n| j||dd� dS )aE  
        Set the lower and upper numerical bounds of the z-axis.
        This method will honor axes inversion regardless of parameter order.
        It will not change the :attr:`_autoscaleZon` attribute.

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        N)rQ   )r   r»   r=  r<  rÜ   )r   r3  ÚupperZ	old_lowerZ	old_upperr   r   r   r°   ¸  s    	zAxes3D.set_zboundc                s&   t ƒ j|||f|Ž}tj|||ƒ |S )zµ
        Add text to the plot. kwargs will be passed on to Axes.text,
        except for the `zdir` keyword, which sets the direction to be
        used as the z direction.
        )r.   Útextr   Ztext_2d_to_3d)r   rU   rV   rI   ÚsÚzdirrA   r?  )rC   r   r   r?  Ô  s    zAxes3D.textrI   )rA  c      
         s¼   | j ƒ }|rBt|d tƒ rB|d }|dd… }d|krNtdƒ‚n|jddƒ}tj|t|ƒƒ}tƒ j	||f|ž|Ž}x|D ]}	t
j|	||d� qzW t
j||||ƒ\}}}| j||||ƒ |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 : scalar or 1D array-like
            z coordinates of vertices; either one for all points or one for
            each point.
        zdir : {'x', 'y', 'z'}
            When plotting 2D data, the direction to use as z ('x', 'y' or 'z');
            defaults to 'z'.
        **kwargs
            Other arguments are forwarded to `matplotlib.axes.Axes.plot`.
        r   r   Nr!  z+plot() for multiple values for argument 'z')r!  rA  )Úhas_dataÚ
isinstanceÚstrr”   rO   r   Úbroadcast_tor•   r.   Úplotr   Zline_2d_to_3dÚjuggle_axesr¨   )
r   r  r   rA  r@   rA   r§   r!  rª   Úline)rC   r   r   rF  á  s    

zAxes3D.plot)rú   ÚvminÚvmaxÚlightsourcec               sN  | j ƒ }
|jdkrtdƒ‚tjtj|ƒƒr4tjdƒ tj|||ƒ\}}}|j	\}}d|	kp`d|	k}d|	kppd|	k}|r‚|r‚tdƒ‚|	j
dd	ƒ}|	j
dd	ƒ}|	j
dd
ƒ}|	j
dd
ƒ}td rÀ|}n| }|rútttj|| ƒdƒƒ}tttj|| ƒdƒƒ}d|	k�r|	j
dƒ}n4|	j
ddƒ}|dk�r0| jjƒ }tjtj|ƒƒ}d}|	jddƒ}|	j
d|dkƒ}|dk�rxtjddd� ttd|d |ƒƒ|d g }ttd|d |ƒƒ|d g }g }g }x¢t|dd… |dd… ƒD ]„\‰‰xxt|dd… |dd… ƒD ]Z\‰ ‰‡ ‡‡‡fdd„|||fD ƒ}tj|ƒj}|j|ƒ |dk	�rü|j|ˆ ˆ  ƒ �qüW �qØW tj|f|ž|	Ž}|dk	�r¬|�r–| j|| j|ƒ|ƒ}|j|ƒ |j |ƒ n„|�rtjdd„ |D ƒƒ}|j!|ƒ |dk	�sä|dk	�rð|j"||ƒ |dk	�r0|j#|ƒ n*|�r"| j|| j|ƒ|ƒ}n|}|j|ƒ | j$|ƒ | j%||||
ƒ |S )a…  
        Create a surface plot.

        By default it will be colored in shades of a solid color, but it also
        supports color mapping 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.

        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.

            .. versionadded:: 2.0

        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 : color-like
            Color of the surface patches.

        cmap : Colormap
            Colormap of the surface patches.

        facecolors : array-like of colors.
            Colors of each individual patch.

        norm : Normalize
            Normalization for the colormap.

        vmin, vmax : float
            Bounds for the normalization.

        shade : bool
            Whether to shade the facecolors. Defaults to True. Shading is
            always disabled when `cmap` is specified.

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

        **kwargs
            Other arguments are forwarded to `.Poly3DCollection`.
        rf   z!Argument Z must be 2-dimensional.z>Z contains NaN values. This may result in rendering artifacts.ÚrstrideÚcstrideÚrcountÚccountz.Cannot specify both stride and count argumentsró   é2   z_internal.classic_moder   Ú
facecolorsÚcolorNÚcmapÚshadez3.1z°Passing shade=None to Axes3D.plot_surface() is deprecated since matplotlib 3.1 and will change its semantic or raise an error in matplotlib 3.3. Please use shade=False instead.)Úmessager   c                s.   g | ]&}t j|ˆˆd  …ˆ ˆd  …f ƒ‘qS )r   )r–   Z_array_perimeter)ro   Úa)ÚcsÚcs_nextÚrsÚrs_nextr   r   ú
<listcomp>Ž  s   z'Axes3D.plot_surface.<locals>.<listcomp>c             S   s    g | ]}|d d …df j ƒ ‘qS )Nrf   )Úmean)ro   Úpsr   r   r   r[  ¤  s    r¡   r¡   )&rB  Úndimr�   r   ÚanyÚisnanr–   r—   Úbroadcast_arraysÚshaperO   r   Úintr}   ÚceilÚ
_get_linesÚget_next_colorr   ÚmcolorsÚto_rgbaÚgetrÄ   ÚlistÚrangeÚzipÚTÚappendr   ÚPoly3DCollectionÚ_shade_colorsÚ_generate_normalsÚset_facecolorsZset_edgecolorsÚ	set_arrayÚset_climÚset_normÚadd_collectionr¨   )r   r¤   r¥   r¦   rú   rI  rJ  rK  r@   rA   r§   ÚrowsÚcolsÚ
has_strideÚ	has_countrL  rM  rN  rO  Zcompute_stridesZfcolorsrR  rS  rT  Zrow_indsZcol_indsÚcolsetÚpolysr]  ÚpolycÚavg_zr   )rW  rX  rY  rZ  r   Úplot_surface  sŠ    =





$$







zAxes3D.plot_surfacec       
      C   s>  t |tjƒr||jd }d|d d| d   }}}|d|dd…f |d|dd…f  }|d|dd…f |d|dd…f  }n¶tjt|ƒdfƒ}tjt|ƒdfƒ}x�t|ƒD ]„\}}	t|	ƒ}d|d d| d   }}}|	|dd…f |	|dd…f  ||dd…f< |	|dd…f |	|dd…f  ||dd…f< qªW tj||ƒS )a°  
        Takes a list of polygons and return an array of their normals.

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

        Uses three points equally spaced around the polygon.
        This normal of course might not make sense for polygons with more than
        three points not lying in a plane, but it's a plausible and fast
        approximation.

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

        Returns
        -------
        normals: (..., 3) array_like
            A normal vector estimated for the polygon.

        rf   r   rg   .Néþÿÿÿ)rC  r   Zndarrayrb  Úemptyr•   r~   Zcross)
r   Úpolygonsr5  Úi1Úi2Zi3Zv1Zv2Zpoly_ir]  r   r   r   rq  ·  s    
$&,0zAxes3D._generate_normalsc       	         sâ   |dkrt ddd�}tjdd��" |tjj|ddd	� |j }W dQ R X tj|ƒ }|jƒ rÐtddƒ‰ td
dƒj	‰‡ ‡fdd„}d|| < t
j|ƒ}|dd…df }||ƒdd…tjf | }||dd…df< ntj|ƒjƒ }|S )zŽ
        Shade *color* using normal vectors given by *normals*.
        *color* can also be an array of the same length as *normals*.
        Néá   gà-� x3@)ZazdegZaltdegÚignore)Úinvalidr   T)rp   Zkeepdimsg333333Ó?c                s   ˆˆ | ƒƒS )Nr   )rU   )Úin_normÚout_normr   r   rú   ö  s    z"Axes3D._shade_colors.<locals>.normr   rg   r¡   )r   r   Zerrstaterù   rú   Ú	directionr`  r_  r   Zinverserg  Úto_rgba_arrayÚnewaxisZ
asanyarrayÚcopy)	r   rR  ÚnormalsrK  rT  Úmaskrú   ÚalphaÚcolorsr   )rˆ  r‰  r   rp  ã  s"    


zAxes3D._shade_colorsc                sÖ  | j ƒ }ˆjdkrtdƒ‚tjˆ ˆˆƒ\‰ ‰‰ˆj\}}d|kpFd|k}	d|kpVd|k}
|	rh|
rhtdƒ‚|jddƒ}|jddƒ}|jdd	ƒ}|jdd	ƒ}td
 ræ|
rä|rÀtt	tj
|| ƒdƒƒnd}|ràtt	tj
|| ƒdƒƒnd}nJ|	�s0|�r
tt	tj
|| ƒdƒƒnd}|�r,tt	tj
|| ƒdƒƒnd}tjˆ ƒtjˆƒtjˆƒ  ‰‰‰|�r”ttd||ƒƒ}|dk�r˜|d |d k�r˜||d g7 }ng }|�rÚttd||ƒƒ}|dk�rÞ|d |d k�rÞ||d g7 }ng }|dk�rú|dk�rútdƒ‚ˆjdk�rg }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|ž|Ž}| j|ƒ | jˆ ˆˆ|ƒ |S )aÚ  
        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.

        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.

            .. versionadded:: 2.0

        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 arguments are forwarded to `.Line3DCollection`.
        rf   z!Argument Z must be 2-dimensional.rL  rM  rN  rO  z.Cannot specify both stride and count argumentsr   rP  z_internal.classic_moder   z*Either rstride or cstride must be non zeroc                s   g | ]}ˆ | ‘qS r   r   )ro   r„   )r¤   r   r   r[  l  s    z)Axes3D.plot_wireframe.<locals>.<listcomp>c                s   g | ]}ˆ | ‘qS r   r   )ro   r„   )r¥   r   r   r[  m  s    c                s   g | ]}ˆ | ‘qS r   r   )ro   r„   )r¦   r   r   r[  n  s    c                s   g | ]}ˆ | ‘qS r   r   )ro   r„   )ÚtXr   r   r[  p  s    c                s   g | ]}ˆ | ‘qS r   r   )ro   r„   )ÚtYr   r   r[  q  s    c                s   g | ]}ˆ | ‘qS r   r   )ro   r„   )ÚtZr   r   r[  r  s    c             S   s"   g | ]\}}}t t|||ƒƒ‘qS r   )rj  rl  )ro   ÚxlÚylÚzlr   r   r   r[  t  s   c             S   s"   g | ]\}}}t t|||ƒƒ‘qS r   )rj  rl  )ro   r•  r–  r—  r   r   r   r[  v  s   r¡   r¡   )rB  r^  r�   r   ra  rb  rO   r   rc  r}   rd  Z	transposerj  rk  Úsizerl  r   ÚLine3DCollectionrv  r¨   )r   r¤   r¥   r¦   r@   rA   r§   rw  rx  ry  rz  rL  rM  rN  rO  ZriiZciiZxlinesZylinesZzlinesZtxlinesZtylinesZtzlinesrª   Úlinecr   )r¤   r¥   r¦   r’  r“  r”  r   Úplot_wireframe  sd    (

 """"
zAxes3D.plot_wireframe)rR  rú   rI  rJ  rK  c            O   sŠ  | j ƒ }|dkr| jjƒ }tjtj|ƒƒ}|jddƒ}	|jd|	dkƒ}
t	j
||Ž\}}}d|krrtj|jdƒƒ}ntj|d ƒ}|dd… }|jƒ }|j| }|j| }|| }tj|||fd	d�}tj|f|ž|Ž}|	�r:|dd…dd…df jdd�}|j|ƒ |dk	�s|dk	�r$|j||ƒ |dk	�rh|j|ƒ n.|
�rZ| j|ƒ}| j|||ƒ}n|}|j|ƒ | j|ƒ | j|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 :class:`~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
        :class:`~matplotlib.tri.Triangulation` for a 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 : Normalize
            An instance of Normalize to map values to colors.
        vmin, vmax : scalar, optional, default: None
            Minimum and maximum value to map.
        shade : bool
            Whether to shade the facecolors. Defaults to True. Shading is
            always disabled when *cmap* is specified.
        lightsource : `~matplotlib.colors.LightSource`
            The lightsource to use when *shade* is True.
        **kwargs
            All other arguments are passed on to
            :class:`~mpl_toolkits.mplot3d.art3d.Poly3DCollection`

        Examples
        --------

        .. plot:: gallery/mplot3d/trisurf3d.py
        .. plot:: gallery/mplot3d/trisurf3d_2.py

        .. versionadded:: 1.2.0
            This plotting function was added for the v1.2.0 release.
        NrS  rT  r¦   r   r   )rp   rf   r¡   )rB  re  rf  r   r   rg  rh  ri  rO   r
   Úget_from_args_and_kwargsZasarrayZget_masked_trianglesrU   rV   Ústackr   ro  r\  rs  rt  ru  rq  rp  rr  rv  r¨   )r   rR  rú   rI  rJ  rK  r@   rA   r§   rS  rT  ÚtrirI   Ú	trianglesZxtZytZztÚvertsr}  r~  rŽ  r{  r   r   r   Úplot_trisurf  s@    ;







zAxes3D.plot_trisurfri   c             C   s¶  |j }|j}|d |d  d }�xrt||ƒD �]b\}}|jƒ }|sFq.tj||| ƒ}	tj||| ƒ}
|jƒ d }g }g }tjt	|	d ƒ| ƒ}|dkr°t	|	d ƒdkr.d}nq.t	|	d ƒd |d  }xxt
ttj|ƒƒd ƒD ]^}ttj|| ƒƒ}ttj|d | ƒƒ}|j|	d | |	d | |
d | |
d | gƒ qàW tj|ƒ}| j|ƒ}| j||ƒ}| j||ƒ}tj|||d�}|j|ƒ | j|ƒ q.W x|D ]}| jj|ƒ �qœW dS )z4
        Extend a contour in 3D by creating
        r   r   rf   )rQ  Ú
edgecolorsN)Úlevelsr€   rl  Ú	get_pathsr   Z_paths_to_3d_segmentsZ	get_colorr   Úroundr•   rk  rc  rn  r   rq  rp  ro  Úset_sort_zposÚadd_collection3dÚremove)r   ÚcsetÚstrider£  Zcollsr'  rI   rš  ÚpathsZtopvertsZbotvertsrR  Z	polyvertsrŽ  ZnstepsZstepsizer„   rƒ  r„  r‘  Zcolors2Zpolycolrs   r   r   r   Ú_3d_extend_contourê  sH    





zAxes3D._3d_extend_contourc             C   sV   d| }|r| j ||ƒ n8x6t|j|jƒD ]$\}}|d k	r>|}tj|||d� q*W d S )Nú-)rA  )r¬  rl  r£  r€   r   Úline_collection_2d_to_3d)r   r©  Úextend3drª  rA  ÚoffsetrI   rš  r   r   r   Úadd_contour_set  s    zAxes3D.add_contour_setc             C   sN   d| }x@t |j|jƒD ].\}}|d k	r,|}tj|||d� |j|ƒ qW d S )Nr­  )rA  )rl  r£  r€   r   Úpoly_collection_2d_to_3dr¦  )r   r©  rA  r°  rI   rš  r   r   r   Úadd_contourf_set(  s    zAxes3D.add_contourf_set)r¯  rª  rA  r°  c               s\   | j ƒ }
tj||||ƒ\}}}tƒ j|||f|ž|	Ž}| j|||||ƒ | j||||
ƒ |S )a´  
        Create a 3D contour plot.

        Parameters
        ----------
        X, Y, Z : array-likes
            Input data.
        extend3d : bool
            Whether to extend contour in 3D; defaults to False.
        stride : int
            Step size for extending contour.
        zdir : {'x', 'y', 'z'}
            The direction to use; defaults to 'z'.
        offset : scalar
            If specified, plot a projection of the contour lines at this
            position in a plane normal to zdir
        *args, **kwargs
            Other arguments are forwarded to `matplotlib.axes.Axes.contour`.

        Returns
        -------
        matplotlib.contour.QuadContourSet
        )rB  r   Úrotate_axesr.   Úcontourr±  r¨   )r   r¤   r¥   r¦   r¯  rª  rA  r°  r@   rA   r§   ÚjXÚjYÚjZr©  )rC   r   r   rµ  0  s    zAxes3D.contourc               s²   | j ƒ }tj||Ž\}}}|j}	|j}
d|kr:|jdƒ}n|d }|dd… }tj|	|
||ƒ\}}}t|||j|j	ƒ}t
ƒ j||f|ž|Ž}| j|||||ƒ | j|	|
||ƒ |S )a©  
        Create a 3D contour plot.

        .. versionchanged:: 1.3.0
            Added support for custom triangulations

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

        Parameters
        ----------
        X, Y, Z : array-likes
            Input data.
        extend3d : bool
            Whether to extend contour in 3D; defaults to False.
        stride : int
            Step size for extending contour.
        zdir : {'x', 'y', 'z'}
            The direction to use; defaults to 'z'.
        offset : scalar
            If specified, plot a projection of the contour lines at this
            position in a plane normal to zdir
        *args, **kwargs
            Other arguments are forwarded to `matplotlib.axes.Axes.tricontour`.

        Returns
        -------
        matplotlib.tri.tricontour.TriContourSet
        r¦   r   r   N)rB  r
   rœ  rU   rV   rO   r   r´  rŸ  r�  r.   Ú
tricontourr±  r¨   )r   r¯  rª  rA  r°  r@   rA   r§   rž  r¤   r¥   r¦   r¶  r·  r¸  r©  )rC   r   r   r¹  T  s     zAxes3D.tricontour)rA  r°  c               sX   | j ƒ }tj||||ƒ\}	}
}tƒ j|	|
|f|ž|Ž}| j|||ƒ | j||||ƒ |S )a�  
        Create a 3D filled contour plot.

        Parameters
        ----------
        X, Y, Z : array-likes
            Input data.
        zdir : {'x', 'y', 'z'}
            The direction to use; defaults to 'z'.
        offset : scalar
            If specified, plot a projection of the contour lines at this
            position in a plane normal to zdir
        *args, **kwargs
            Other arguments are forwarded to `matplotlib.axes.Axes.contourf`.

        Returns
        -------
        matplotlib.contour.QuadContourSet

        Notes
        -----
        .. versionadded:: 1.1.0
            The *zdir* and *offset* parameters.
        )rB  r   r´  r.   Úcontourfr³  r¨   )r   r¤   r¥   r¦   rA  r°  r@   rA   r§   r¶  r·  r¸  r©  )rC   r   r   rº  Š  s    zAxes3D.contourfc               s®   | j ƒ }tj||Ž\}}}|j}|j}d|kr:|jdƒ}	n|d }	|dd… }tj|||	|ƒ\}
}}t|
||j|j	ƒ}t
ƒ j||f|ž|Ž}| j|||ƒ | j|||	|ƒ |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-likes
            Input data.
        zdir : {'x', 'y', 'z'}
            The direction to use; defaults to 'z'.
        offset : scalar
            If specified, plot a projection of the contour lines at this
            position in a plane normal to zdir
        *args, **kwargs
            Other arguments are forwarded to
            `matplotlib.axes.Axes.tricontourf`.

        Returns
        -------
        matplotlib.tri.tricontour.TriContourSet

        Notes
        -----
        .. versionadded:: 1.1.0
            The *zdir* and *offset* parameters.
        .. versionchanged:: 1.3.0
            Added support for custom triangulations
        r¦   r   r   N)rB  r
   rœ  rU   rV   rO   r   r´  rŸ  r�  r.   Útricontourfr³  r¨   )r   rA  r°  r@   rA   r§   rž  r¤   r¥   r¦   r¶  r·  r¸  r©  )rC   r   r   r»  ®  s     zAxes3D.tricontourfr   c                sª   t j|ƒ}|jrt j|ƒnd}t|ƒtjkrHtj|||d� |j	|ƒ nRt|ƒtj
krrtj|||d� |j	|ƒ n(t|ƒtjkrštj|||d� |j	|ƒ tƒ j|ƒ d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.

        Supported are:
            - PolyCollection
            - LineCollection
            - PatchCollection
        r   )r!  rA  N)r   r  r˜  r  ÚtypeÚmcollZPolyCollectionr   r²  r¦  ZLineCollectionr®  ZPatchCollectionÚpatch_collection_2d_to_3dr.   rv  )r   rs   r!  rA  ZzvalsZzsortval)rC   r   r   r§  ä  s    

zAxes3D.add_collection3dé   c                s´   | j ƒ }
tjdd„ |||gD ƒŽ \}}}tjj|ƒ}tj|||||ƒ\}}}}}tƒ j||f|ž||dœ|	—Ž}t	j
||||d� | jdk r |jdkr | jdƒ | j||||
ƒ |S )a¨  
        Create a scatter plot.

        Parameters
        ----------
        xs, ys : array-like
             The data positions.
        zs : float or array-like, optional, 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'}, optional, 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 : scalar or array-like, optional, 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 : color, sequence, or sequence of color, optional
            The marker color. Possible values:

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

            For more details see the *c* argument of `~.axes.Axes.scatter`.
        depthshade : bool, optional, default: True
            Whether to shade the scatter markers to give the appearance of
            depth.
        **kwargs
            All other arguments are passed on to `~.axes.Axes.scatter`.

        Returns
        -------
        paths : `~matplotlib.collections.PathCollection`
        c             S   s"   g | ]}t jt jj|t jƒƒ‘qS r   )r   ÚravelÚmaÚfilledÚnan)ro   Útr   r   r   r[  2	  s    z"Axes3D.scatter.<locals>.<listcomp>)r@  Úc)r!  rA  Ú
depthshadegš™™™™™©?r   )rB  r   ra  rÁ  rÀ  r–   Zdelete_masked_pointsr.   Úscatterr   r¾  r�   r˜  r’   r¨   )r   r  r   r!  rA  r@  rÅ  rÆ  r@   rA   r§   r�   )rC   r   r   rÇ  	  s    , 

zAxes3D.scatterc                sè   | j ƒ }tƒ j||f|ž|Ž}tj|t|ƒƒ}g }	g }
xbt||ƒD ]T\}}tj|ƒ}|	|j	ƒ 7 }	|
|gt|ƒ 7 }
tj
|||ƒ d|krB|j|d ƒ qBW t|	ƒdkr´t|	Ž \}}n
g g  }}tj|||
|ƒ\}}}
| j|||
|ƒ |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 : scalar or 1D array-like
            Z coordinate of bars; if a single value is specified, it will be
            used for all bars.
        zdir : {'x', 'y', 'z'}
            When plotting 2D data, the direction to use as z ('x', 'y' or 'z');
            defaults to 'z'.
        **kwargs
            Other arguments are forwarded to `matplotlib.axes.Axes.bar`.

        Returns
        -------
        mpl_toolkits.mplot3d.art3d.Patch3DCollection
        r�  r   )rB  r.   Úbarr   rE  r•   rl  r   Z_get_patch_vertsr  Zpatch_2d_to_3dZ	set_alpharG  r¨   )r   rÌ   Úheightr!  rA  r@   rA   r§   r�   r   Zverts_zsÚprI   Úvsr  r   )rC   r   r   rÈ  D	  s$    

z
Axes3D.barÚaveragec
             O   s
  | j ƒ }tjtj|ƒ|||||ƒ\}}}}}}tj|ƒ}tj|| ƒ}tj|ƒ}tj|| ƒ}tj|ƒ}tj|| ƒ}tjddddd d%gƒ}tj|j|j ƒ}xld||fd||fd||fgD ]L\}}}|dtj	tj	f }|dtj	tj	f }|||d|f   |d|f< � q¼W |j
d'|jdd…  ƒ}g }|dk�r>| jjƒ g}t|ƒt|ƒk�rrxP|D ]}|j|gd ƒ �qVW n0ttj|ƒƒ}t|ƒt|ƒk �r¢|dt|ƒ 9 }|	�rÀ| j|ƒ}| j||ƒ}n|}tj|f|
ž||dœ|—Ž}| j|ƒ | j||f||f||f|ƒ |S )(a  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 : scalar or array-like
            The width, depth, and height of the bars, respectively.

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

              - A single color value, 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 : str, optional
            The z-axis sorting scheme passed onto `~.art3d.Poly3DCollection`

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

        **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   rf   .Nrj   )ÚzsortÚ	facecolor©r   r   r   ©r   r   r   ©r   r   r   ©r   r   r   )rÏ  rÐ  rÑ  rÒ  ©r   r   r   ©r   r   r   ©r   r   r   ©r   r   r   )rÓ  rÔ  rÕ  rÖ  ©r   r   r   ©r   r   r   ©r   r   r   ©r   r   r   )r×  rØ  rÙ  rÚ  ©r   r   r   ©r   r   r   ©r   r   r   ©r   r   r   )rÛ  rÜ  rÝ  rÞ  ©r   r   r   ©r   r   r   ©r   r   r   ©r   r   r   )rß  rà  rá  râ  ©r   r   r   ©r   r   r   ©r   r   r   ©r   r   r   )rã  rä  rå  ræ  r¡   )r¡   )rB  r   ra  r  r  r}   r   r�  rb  rŒ  r¢   Ú_get_patches_for_fillrf  r•   Úextendrj  rg  r‹  rq  rp  r   ro  rv  r¨   )r   rU   rV   rI   r#  r$  r'  rR  rÍ  rT  r@   rA   r§   r^   r_   r`   ra   rb   rc   Zcuboidr|  r„   rÊ  ZdprQ  rÅ  rŽ  Zsfacecolorsrs   r   r   r   Úbar3dx	  st    7"


                  ("



zAxes3D.bar3dÚcenterc                s<   t ƒ j|f||dœ|—Ž}| jjƒ \}}| jjd| ƒ |S )N)r)  Úlocgq=
×£pí?)r.   Ú	set_titleÚtitleÚget_positionZset_y)r   r+  r)  rë  rA   ÚretrU   rV   )rC   r   r   rì  
  s    zAxes3D.set_titleg333333Ó?Útail)ÚlengthÚarrow_length_ratioÚpivotÚ	normalizec               s–  ddd„‰ | j ƒ }d}t|ƒ|k r6td|t|ƒf ƒ‚|d|… }	dd„ |	D ƒ}
tj|	|
žŽ }|d|… }	||d… }
|
ršttj|
ƒ‰‡fd	d„|	D ƒ}	nd
d„ |	D ƒ}	tdd„ |	D ƒƒrâtj	g f||d… ž|Ž}| j
|ƒ |S tjd|gƒ}|| }|dk�r||8 }n2|dk�r$||d 8 }n|dk�r>tdt|ƒ ƒ‚tj|	dd… ƒ}tj|	d|… ƒjtƒ}tjj|dd�}|dk‰|ˆ }|�r¦|ˆ |ˆ jdƒ }n|ˆ }t|ƒdk�r6|tjj||ƒ jddƒ}tj‡ fdd„|D ƒƒ}|dd…dd…f tjj||ƒ }t|ƒddf|_|jddƒ}||•}ng }tj	|f||d… ž|Ž}| j
|ƒ | j|dd…df |dd…df |dd…df |ƒ |S )a÷  
        ax.quiver(X, Y, Z, U, V, W, /, length=1, arrow_length_ratio=.3, pivot='tail', normalize=False, **kwargs)

        Plot a 3D field of arrows.

        The arguments could be array-like or scalars, so long as they
        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
            The length of each quiver, default to 1.0, the unit is
            the same with the axes

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

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

        normalize : bool
            When True, all of the arrows will be the same length. This
            defaults to False, where the arrows will be different lengths
            depending on the values of u,v,w.

        **kwargs
            Any additional keyword arguments are delegated to
            :class:`~matplotlib.collections.LineCollection`
        é   c       
      S   s  t jj| dd… ƒ}|dkr8| d | }| d  | }nd\}}tj|ƒ}tj|ƒ}tj|ƒ}t j||d d|   || d|  || g|| d|  ||d d|   | | g| | || |ggƒ}|jƒ }	|	ddddgddddgf  |	ddddgddddgf< |j	| ƒ|	j	| ƒfS )zu
            To calculate the arrow head. uvw should be a unit vector.
            We normalize it here:
            Nrf   r   r   )r   r   )
r   rù   rú   ÚmathÚradiansr÷   rø   r   r�  rü   )
ZuvwZanglerú   rU   rV   ÚrarÅ  r@  ZRposZRnegr   r   r   Ú
calc_arrowH
  s    


,*6z!Axes3D.quiver.<locals>.calc_arrowrj   z-Wrong number of arguments. Expected %d got %dNc             S   s    g | ]}t |tjjƒr|j‘qS r   )rC  r   rÁ  ZMaskedArrayr�  )ro   rB   r   r   r   r[  r
  s    z!Axes3D.quiver.<locals>.<listcomp>c                s    g | ]}t jj|ˆ d �jƒ ‘qS ))r�  )r   rÁ  r   Ú
compressed)ro   rB   )r�  r   r   r[  |
  s   c             S   s   g | ]}t j|ƒ‘qS r   )r   rÀ  )ro   rB   r   r   r   r[  
  s    c             s   s   | ]}t |ƒd kV  qdS )r   N)r•   )ro   Úvr   r   r   rq   �
  s    z Axes3D.quiver.<locals>.<genexpr>r   rð  Zmiddleg       @ZtipzInvalid pivot argument: rg   r   )rp   c                s   g | ]}ˆ |ƒ‘qS r   r   )ro   Úd)rù  r   r   r[  £
  s    rf   )rõ  r¡   )r¡   r   r¡   )rB  r•   r�   r   ra  r   Ú
logical_orr_  r   r™  rv  r   rD  r£   ZastypeÚfloatrù   rú   r¢   ÚmultiplyÚouterZswapaxesrb  r¨   )r   rñ  rò  ró  rô  r@   rA   r§   ZargiZ
input_argsÚmasksZbcastrš  Zshaft_dtZarrow_dtZXYZZUVWrú   ZshaftsZ	head_dirsZheadsrª   r   )rù  r�  r   Úquiver
  s`    -







"

4zAxes3D.quiver)rQ  r¢  rT  rK  c      2         sú  t |ƒdkrdd„ }ndd„ }|||Ž\}‰}ˆjdkr@tdƒ‚tjˆjtjd�}	t|	d ƒ‰ |dkrxtjˆ ƒ\}
}}n‡ fd	d
„|D ƒ\}
}}‡fdd„}|dkr®| j	j
ƒ }||dƒ}||dƒ}| j|
||ƒ tjdddgdddgdddgdddggtjd�}ttƒ}dd„ }�x®|dƒD �] }|jj|	ƒ\}}}tj|ƒ}tj|ƒ}tj|ƒ}|j|jƒ}|ddd… }�xL|D �]B}�x8|D �].}|j||dgƒ}t|ƒ}ˆ| �r¼|| j|| ƒ xªt|dd… |dd… ƒD ]Œ\}}|j|||gƒ} |j|||gƒ}!t| ƒ}"t|!ƒ}#ˆ|" �r:ˆ|#  �r:||" j|!| ƒ n(ˆ|"  �rØˆ|# �rØ||# j|!| ƒ �qØW |j|||d gƒ}$|j|||gƒ}%t|$ƒ}&ˆ|& �r‚||& j|%| ƒ �q‚W �qtW �qW i }'�x,|jƒ D �]\}(})|dk�rì|)}*n”g }*xŽ|)D ]†}+|+dd…df |+dd…df |+dd…df f},tj|+jƒ}-|
|, |-dd…df< ||, |-dd…df< ||, |-dd…df< |*j|-ƒ �qöW ||( }.||( }/|�rÆ| j|*ƒ}0| j|.|0|ƒ}.|/dk	�rÆ| j|/|0|ƒ}/tj|*f|.|/dœ|—Ž}1| j|1ƒ |1|'|(< �qÒW |'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.

        .. versionadded:: 2.1

        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.
            This parameter 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 ndarray of color names, with each item the color for the
                corresponding voxel. The size must match the voxels.
              - A 4D ndarray of rgb/rgba data, with the components along the
                last axis.

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

            .. versionadded:: 3.1

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

            .. versionadded:: 3.1

        **kwargs
            Additional keyword arguments to pass onto
            :func:`~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
        rg   c             [   s   | ||f||fS )Nr   )Z
_Axes3D__xZ
_Axes3D__yZ
_Axes3D__zrÂ  rA   r   r   r   Úvoxels  s    zAxes3D.voxels.<locals>.voxelsc             [   s
   d | |fS )Nr   )rÂ  rA   r   r   r   r    s    z%Argument filled must be 3-dimensional)Údtyper   Nc             3   s   | ]}t j|ˆ ƒV  qd S )N)r   rE  )ro   rÅ  )Úcoord_shaper   r   rq     s    z Axes3D.voxels.<locals>.<genexpr>c                sp   t j| ƒdkr&t j| ˆ jt j| ƒ ƒS t j| ƒdkr^t j| ƒd d… ˆ jkrZtdj|ƒƒ‚| S tdj|ƒƒ‚d S )	Nr   r   rg   rh   z8When multidimensional, {} must match the shape of filledzInvalid {} argument)r   r   )rg   rh   )r   r^  rE  rb  r�   r  )rR  rÀ   )rÂ  r   r   Ú_broadcast_color_arg  s    z+Axes3D.voxels.<locals>._broadcast_color_argrQ  r¢  r   c             s   s<   t j| t jd�}x&t| ƒD ]}|V  t j|ddd�}qW dS )z)Generator of cyclic permutation matrices.)r  r   r   )rp   N)r   r{   Úintprk  Zroll)r5  Úmatr„   r   r   r   Úpermutation_matrices?  s    z+Axes3D.voxels.<locals>.permutation_matricesrf   )rQ  r¢  r¡   r¡   )r•   r^  r�   r   r   rb  r  rÞ   Úindicesrç  rf  r¨   r   rj  rm  rü   Úarangern  rl  Úitemsr�  rq  rp  r   ro  r§  )2r   rQ  r¢  rT  rK  r@   rA   r  Zxyzr˜  rU   rV   rI   r  ZsquareZvoxel_facesr	  ZpermuteZpcZqcÚrcZpindsZqindsZrindsZsquare_rot_posZsquare_rot_negrÊ  Úqr  Zi0Zr1Zr2r  Úp2rƒ  r„  ÚpkZpk2Zikr‚  ZcoordZ
faces_indsZfacesZ	face_indsÚindÚfacerÎ  Z	edgecolorrŽ  Úpolyr   )r  rÂ  r   r  ¸
  sž    N






	



$
$

.



zAxes3D.voxels)NiÄÿÿÿ)NNNN)N)NN)NN)FFF)Tr›   N)NN)NTTT)NN)NNTF)NNTF)NNTF)F)F)N)NN)r   rg   )NN)T)r›   N)r›   )NN)N)N)ri   )Fri   rI   N)rI   N)r   rI   )r   rI   r¿  NT)r   rI   )NrÌ  T)Nrê  )yÚ__name__Ú
__module__Ú__qualname__Ú__doc__rÀ   r–   ZGrouperr,   Ú	docstringZdedent_interpdr/   r0   r1   rG   rJ   rN   r9   rY   rZ   r[   rd   re   rn   r   Zallow_rasterizationrw   r|   r   rˆ   r‰   rŠ   rŒ   r�   r’   rš   r    r¨   r‡   r\   r¾   rÏ   rS   rØ   rT   rÝ   rÜ   r¸   Úmaxesr   rÆ   r¹   rÒ   rº   rÛ   rá   rå   ræ   r4   rç   ré   rë   rì   rí   rî   rð   rñ   rò   r)   r$   ry   r8   r  r	  r
  r  r  r  r  r"  r  r*  r,  r-  r.  r  r6  r8  r9  r;  r<  r=  r°   r?  Ztext3DZtext2DrF  Zplot3Dr  rq  rp  r›  r¡  r¬  r±  r³  rµ  Z	contour3Dr¹  rº  Z
contourf3Dr»  r§  rÇ  Z	scatter3DrÈ  ré  rì  r  Zquiver3Dr  Ú__classcell__r   r   )rC   r   r   *   s  T
 


3
			D

 
C
8::	"
	



/
	#8

8
(



+ ),
$xj
4


	!5"6?4 
  r   çš™™™™™©?c             C   s°   t jdd| ƒ }}t j||ƒ\}}t j|d |d   d ƒdt j  }t j|d d d |d d d   d ƒdt j d d  }|| }|d }|d }|d }|||fS )	z6
    Return a tuple X, Y, Z with a test data set.
    g      @rf   r   g      ø?g      à?ró   iô  g      À)r   r  ZmeshgridÚexprö   )r³   rU   rV   r¤   r¥   ZZ1ZZ2r¦   r   r   r   Úget_test_dataš  s    &*r  )r  )/r  r€   r   Ú	functoolsr   rö  Znumpyr   Z
matplotlibr   Zmatplotlib.axesZaxesr  Zmatplotlib.cbookr–   Zmatplotlib.collectionsr½  Zmatplotlib.colorsr‘  rg  Zmatplotlib.docstringr  Zmatplotlib.projectionsZprojectionsÚprojZmatplotlib.scaleZscalerß   Zmatplotlib.transformsZ
transformsZmtransformsr   r   r   r   r	   Zmatplotlib.tri.triangulationr
   r  r   r   r   r   r   r  Zprojection_registryÚregisterr   r   r   r   Ú<module>   s^   







                       
