B
    ]”t\Ð’ ã               @   s.  d Z ddlmZ ddlmZ ddlZddlZddl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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*ddl+m,Z- e-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.
é    )Úreduce)ÚdefaultdictN)Úartist)ÚAxesÚrcParams)Ú	NormalizeÚLightSource)ÚBbox)ÚTriangulationé   )Úart3d)Úproj3d)Úaxis3dc              C   s   t t ddgddgg¡ƒ} | S )Nr   r   )r	   ÚnpÚarray)Zbox© r   ú:lib/python3.7/site-packages/mpl_toolkits/mplot3d/axes3d.pyÚ	unit_bbox%   s    r   c                   s  e Zd ZdZdZe ¡ Z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‡ f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-j.j/je,_e,Z/e/jdk	rÀe/ jdO7  _dPdQ„ Z0e-j.j1je0_e0Z1e1jdk	ròe1 jdR7  _dSdT„ Z2e2Z3dUdV„ Z4dWdX„ Z5e-j.j5jdk	r.e-j.j5jdY e5_dZd[„ Z6e-j.j6jdk	rVe-j.j6jdY e6_e7j8d\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„ ZQdd‘„ 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]e.j\Z^d¨d©œ‡ fdªd«„
Z_e_Z`ddddd¬œd­d®„Zad¯d°„ Zbd±d²„ Zcd³d´„ Zddµd¶„ Zedddddd·œd¸d¹„Zfdùd»d¼„Zgdúd½d¾„Zhdûd¿dÀ„Zid&dºd¨ddÁœ‡ fdÂdÃ„
ZjejZkd&dºd¨ddÁœ‡ fdÄdÅ„
Zld¨ddÆœ‡ fdÇdÈ„
ZmemZnd¨ddÆœ‡ fdÉdÊ„
Zodü‡ fdÌdÍ„	Zpdý‡ fdÏdÐ„	ZqeqZrdþ‡ fdÑdÒ„	ZsdÿdÔdÕ„Ztd ‡ fd×dØ„	Zue-j.jujeu_dvdÙdÚd&dÛœdÜdÝ„ZvevZwdddÞœdßdà„Zx‡  ZyS (  ÚAxes3Dz
    3D axes object.
    Z3dNiÄÿÿÿé   Úpersp)ÚazimÚelevÚzscaleÚsharezÚ	proj_typec               s¨  ddd  dd„ t ¡ D ƒ¡i  |d kr4ddddg}g ˆ _|ˆ _|ˆ _ˆ  |¡ tƒ ˆ _tƒ ˆ _	tƒ ˆ _
tƒ ˆ _ˆ  ˆ jˆ j¡ dˆ _|ˆ _|d k	r¨ˆ j  ˆ |¡ d	ˆ _tƒ j||f|žd
di|	—Ž tƒ  ¡  ˆ  ¡  d ˆ _d ˆ _|d k	röˆ  |¡ ˆ jd k	rˆ jj d‡ fdd„¡ˆ _nd ˆ _dˆ _ˆ  ¡  ˆ  ¡  ˆ j d¡ ˆ j  !¡  "ddg¡}
|
d |
d  \ˆ _#ˆ _$ˆ j% &ˆ ¡ x$ˆ j' (¡ D ]}ˆ j'|  )d¡ qŠW d S )Na^  
        Build an :class:`Axes3D` instance in
        :class:`~matplotlib.figure.Figure` *fig* with
        *rect=[left, bottom, width, height]* in
        :class:`~matplotlib.figure.Figure` coordinates

        Optional keyword arguments:

          ================   =========================================
          Keyword            Description
          ================   =========================================
          *azim*             Azimuthal viewing angle (default -60)
          *elev*             Elevation viewing angle (default 30)
          *zscale*           [%(scale)s]
          *sharez*           Other axes to share z-limits with
          *proj_type*        'persp' or 'ortho' (default 'persp')
          ================   =========================================

        .. versionadded :: 1.2.1
            *sharez*

        Úscalez | c             S   s   g | ]}t |ƒ‘qS r   )Úrepr)Ú.0Úxr   r   r   ú
<listcomp>J   s    z#Axes3D.__init__.<locals>.<listcomp>g        g      ð?r   ZdatalimZframeonTzunits finalizec                  s   ˆ j ddS )NT)Úscalez)Ú_on_units_changedr   )Úselfr   r   Ú<lambda>q   s    z!Axes3D.__init__.<locals>.<lambda>r   )r   r   )r   r   F)*ÚjoinÚmscaleÚget_scale_namesÚ_cidsÚinitial_azimÚinitial_elevÚset_proj_typer   Ú
xy_viewLimÚ
zz_viewLimÚ
xy_dataLimÚ
zz_dataLimÚ	view_initÚ_readyÚ_sharezÚ_shared_z_axesZ_adjustableÚsuperÚ__init__Úset_axis_offÚset_axis_onÚMÚ	fmt_zdataÚ
set_zscaleÚzaxisÚ	callbacksZ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   r5   1   sJ     


zAxes3D.__init__c             C   s   d| _ d| _d S )NFT)Ú	_axis3donÚstale)r#   r   r   r   r6   …   s    zAxes3D.set_axis_offc             C   s   d| _ d| _d S )NT)rI   rJ   )r#   r   r   r   r7   ‰   s    zAxes3D.set_axis_onc             C   s   | j  ¡ p| j ¡ p| j ¡ S )zN
        Return *True* if units are set on the *x*, *y*, or *z* axes

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

        .. versionadded :: 1.2.1

        )r;   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 ¡ sR| j |¡ |dk	r–| d| jj¡}|| jjkr–| j 	|¡ |dk	r–| j |¡ dS )zT
        Look for unit *kwargs* and update the axis instances as necessary

        )ÚxdataÚydatarF   NÚzunits)
r4   Ú_process_unit_inforK   rM   r;   rL   Zupdate_unitsÚpopZunitsZ	set_units)r#   rP   rQ   ÚzdatarF   rR   )rH   r   r   rS   Ÿ   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)Údistr4   Úset_xlimÚset_ylim)r#   ZxdwlZxdwZydwlZydw)rH   r   r   r>   ¹   s    



zAxes3D.set_top_viewc             C   sŒ   t  d| jj| jj| ¡| _| j| _t  d| jj| jj| ¡| _	| j	| _
t  d| jj| jj| ¡| _| j| _x | j| j
| jfD ]}| ¡  qxW dS )z4Init 3D axes; overrides creation of regular X/Y axesr   ÚyrN   N)r   ZXAxisr,   Ú	intervalxr.   Zw_xaxisrK   ZYAxisÚ	intervalyZw_yaxisrM   ZZAxisr-   r/   Zw_zaxisr;   Zinit3d)r#   Zaxr   r   r   Ú
_init_axisÆ   s    zAxes3D._init_axisc                s   | j gtƒ  ¡  S )N)r;   r4   Úget_children)r#   )rH   r   r   r^   Õ   s    zAxes3D.get_childrenc                s   t ƒ  ¡ | jf S )N)r4   Ú_get_axis_listr;   )r#   )rH   r   r   r_   Ø   s    zAxes3D._get_axis_listc          
   C   s\   |p
|   ¡ \}}}}}}|||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 }|  |¡}t ||¡}|S )N)r8   rh   r   Zproj_points)r#   ra   r8   ZxyzsZtcuber   r   r   Ú
tunit_cubeæ   s
    
zAxes3D.tunit_cubec             C   s¼   |   ||¡}|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   é   é   é   é   é   é   )ri   )r#   ra   r8   ÚtcZedgesr   r   r   Útunit_edgesí   s    zAxes3D.tunit_edgesc       	         s:  | j  ˆ ¡ d| _|  ¡ }|r4|| ˆ ƒ}|  |¡ n|  ¡  |  ¡ | _| jˆ _| jˆ _| jˆ _| j	ˆ _	t
dd„ |  ¡ 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|  ¡ D ]}| ˆ ¡ qúW x|  ¡ D ]}| ˆ ¡ qW tƒ  ˆ ¡ d S )
NFc             s   s   | ]}|  ¡ V  qd S )N)Z
get_zorder)r   Úaxisr   r   r   ú	<genexpr>  s   zAxes3D.draw.<locals>.<genexpr>r   c                s
   |   ˆ ¡S )N)Údo_3d_projection)Úcol)Úrendererr   r   r$     s    zAxes3D.draw.<locals>.<lambda>T)ÚkeyÚreversec                s
   |   ˆ ¡S )N)rt   )r?   )rv   r   r   r$   #  s    )r?   ÚdrawÚ_frameonZget_axes_locatorZapply_aspectÚget_projr8   ÚvvecÚeyeÚget_axis_positionÚmaxr_   Ú	enumerateÚsortedÚcollectionsZzorderÚpatchesrI   Z	draw_paner4   )	r#   rv   ZlocatorÚposZzorder_offsetÚiru   r?   rr   )rH   )rv   r   ry   ÿ   s<    



zAxes3D.drawc             C   sh   |   ¡ }|  || j¡}|d d |d d k}|d d |d d k}|d d |d d k}|||fS )Nr   rj   rk   r   )r`   ri   r8   )r#   ra   rp   ZxhighZyhighZzhighr   r   r   r~   2  s    zAxes3D.get_axis_positionFc             C   s   |   ¡  | 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xysrF   r   r   r   Úupdate_datalimC  s    zAxes3D.update_datalimc                s   t ƒ  ¡ o|  ¡ 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.
        )r4   Úget_autoscale_onÚget_autoscalez_on)r#   )rH   r   r   rŠ   F  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‹   O  s    zAxes3D.get_autoscalez_onc                s   t ƒ  |¡ |  |¡ 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)r4   Úset_autoscale_onÚset_autoscalez_on)r#   Úb)rH   r   r   r   X  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Ž   f  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Ú_zmarginrJ   )r#   Úmr   r   r   Úset_zmargins  s    zAxes3D.set_zmarginT)r   rZ   rN   Ú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 d|f ¡ | j| j| jfS |dk	rº|  |¡ |dk	rÌ|  |¡ |dk	rÞ|  	|¡ | 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   rk   zYMust pass a single positional argument for all margins, or one for each margin (x, y, z).Tzignoring tight=%r in get mode)r”   r†   r‡   r!   )Ú	TypeErrorÚlenÚwarningsÚwarnÚ_xmarginÚ_ymarginr‘   Zset_xmarginZset_ymarginr“   rˆ   )r#   r   rZ   rN   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.
        NT)r   rœ   F)rZ   rœ   )rN   rœ   )r”   r†   r‡   r!   )ÚboolÚ_autoscaleXonÚ_autoscaleYonrŒ   rˆ   )r#   Úenablerr   r”   r†   r‡   r!   r   r   r   Ú	autoscaleÈ  s    
zAxes3D.autoscalec             C   s¢   t tj|||fƒ\}}}y&| ¡ | ¡  }}|d k	r<| ¡ }W n tk
rT   ‚ Y nX | j t ||g¡j| ¡ |d k	r–| j	 t ||g¡j| ¡ |  
¡  d S )N)Úmapr   ÚasarrayÚflattenÚAttributeErrorr.   Zupdate_from_data_xyr   ÚTr/   rˆ   )r#   ÚXÚYÚZÚhad_datar   rZ   rN   r   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 ¡ }y| ||¡\}}W n* tk
rÆ   tj||ddd\}}Y nX | jdkrð|| | j }	||	8 }||	7 }|s| ||¡\}}|  ||¡ |rÎ| jrÎ| j 	¡  | j
j\}
}| j ¡ }y| |
|¡\}
}W n, tk
r€   tj|
|ddd\}
}Y nX | jdkr¬||
 | j }	|
|	8 }
||	7 }|sÂ| |
|¡\}
}|  |
|¡ |rŠ| jrŠ| j 	¡  | jj\}}| j ¡ }y| ||¡\}}W n, tk
r<   tj||ddd\}}Y nX | jdkrh|| | j }	||	8 }||	7 }|s~| ||¡\}}|  ||¡ 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   Fgš™™™™™©?)Ú
increasingZexpander) r1   Ú_tightr–   ZimagesÚlinesrƒ   r   rž   Ú_shared_x_axesZcleanr.   r[   rK   Úget_major_locatorÚnonsingularr¥   Úmtransformsr™   Zview_limitsZ
set_xboundrŸ   Ú_shared_y_axesr\   rM   rš   Z
set_yboundrŒ   r3   r/   r;   r‘   Ú
set_zbound)r#   r”   r†   r‡   r!   r­   Úx0Úx1ZxlocatorÚdeltaÚy0Úy1ZylocatorÚz0Úz1Zzlocatorr   r   r   rˆ   ú  sn    &









zAxes3D.autoscale_viewc             C   s4   |   ¡ \}}|  ¡ \}}|  ¡ \}}||||||fS )zGet 3D world limits.)Ú
get_xlim3dÚ
get_ylim3dÚ
get_zlim3d)r#   rb   rc   rd   re   rf   rg   r   r   r   r`   J  s    zAxes3D.get_w_limsc             O   s:   |d krt  |¡r|\}}||kr2|d8 }|d7 }||fS )Ngš™™™™™©?)ÚcbookÚiterable)r#   ÚxminÚxmaxrE   rF   r   r   r   Ú_determine_limsQ  s    zAxes3D._determine_lims)rÁ   rÂ   c      
      C   s¦  |dkrt  |¡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¡}|  ¡ \}}|dkrº|}|dkrÆ|}||kràt 	d||f ¡ t
j||dd\}}| j ||¡\}}||f| j_|dk	r&t|ƒ| _|r˜| j d| ¡ x\| j | ¡D ]L}	|	| k	rH|	j| jjd|d |	j| jkrH|	jjdk	rH|	jj ¡  qHW 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`)rP   zwAttempting to set identical left==right results
in singular transformations; automatically expanding.
left=%s, right=%sF)r¬   Zxlim_changed)ÚemitrV   T)r¿   rÀ   Úwarn_deprecatedr•   rS   Ú_validate_converted_limitsZconvert_xunitsÚget_xlimr—   r˜   r²   r±   rK   Úlimit_range_for_scaler,   r[   r   rž   r<   Úprocessr¯   Úget_siblingsrX   rC   ÚcanvasÚ	draw_idlerJ   )
r#   ÚleftÚrightrÈ   rV   rÁ   rÂ   Zold_leftZ	old_rightÚotherr   r   r   Ú
set_xlim3dY  sR    






zAxes3D.set_xlim3d)ÚyminÚymaxc      
      C   s¦  |dkrt  |¡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¡}|  ¡ \}}|dkrº|}|dkrÆ|}||kràt 	d||f ¡ t
j||dd\}}| j ||¡\}}||f| j_|dk	r&t|ƒ| _|r˜| j d| ¡ x\| j | ¡D ]L}	|	| k	rH|	j| jjd|d |	j| jkrH|	jjdk	rH|	jj ¡  qHW 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`)rQ   zwAttempting to set identical bottom==top results
in singular transformations; automatically expanding.
bottom=%s, top=%sF)r¬   Zylim_changed)rÈ   rV   T)r¿   rÀ   rÉ   r•   rS   rÊ   Zconvert_yunitsÚget_ylimr—   r˜   r²   r±   rM   rÌ   r,   r\   r   rŸ   r<   rÍ   r³   rÎ   rY   rC   rÏ   rÐ   rJ   )
r#   ÚbottomÚtoprÈ   rV   rÕ   rÖ   Ú
old_bottomÚold_toprÓ   r   r   r   Ú
set_ylim3d“  sR    






zAxes3D.set_ylim3d)ÚzminÚzmaxc      
      C   s¦  |dkrt  |¡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¡}|  ¡ \}}|dkrº|}|dkrÆ|}||kràt 	d||f ¡ t
j||dd\}}| j ||¡\}}||f| j_|dk	r&t|ƒ| _|r˜| j d| ¡ x\| j | ¡D ]L}	|	| k	rH|	j| jjd|d |	j| jkrH|	jjdk	rH|	jj ¡  qHW 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`)rU   zwAttempting to set identical bottom==top results
in singular transformations; automatically expanding.
bottom=%s, top=%sF)r¬   Zzlim_changed)rÈ   rV   T)r¿   rÀ   rÉ   r•   rS   rÊ   rO   Úget_zlimr—   r˜   r²   r±   r;   rÌ   r-   r[   r   rŒ   r<   rÍ   r3   rÎ   Úset_zlimrC   rÏ   rÐ   rJ   )
r#   rØ   rÙ   rÈ   rV   rÝ   rÞ   rÚ   rÛ   rÓ   r   r   r   Ú
set_zlim3dÍ  sR    






zAxes3D.set_zlim3dc             C   s   t | jjƒS )N)Útupler,   r[   )r#   r   r   r   r¼     s    zAxes3D.get_xlim3dzz
            .. versionchanged :: 1.1.0
                This function now correctly refers to the 3D x-limits
            c             C   s   t | jjƒS )N)râ   r,   r\   )r#   r   r   r   r½     s    zAxes3D.get_ylim3dz{
            .. 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-   r[   )r#   r   r   r   r¾     s    zAxes3D.get_zlim3dc             C   s   dd  t ¡ ¡  | j ¡ S )Nz¡
        Return the zaxis scale string %s

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        z, )r%   r&   r'   r;   Ú	get_scale)r#   r   r   r   Ú
get_zscale   s    zAxes3D.get_zscalec             K   s*   | j j|f|Ž | jddd |  ¡  d S )NF)r‡   r!   )rK   Ú
_set_scalerˆ   Ú_update_transScale)r#   ÚvaluerF   r   r   r   Ú
set_xscale+  s    zAxes3D.set_xscalez„

            .. 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 |  ¡  d| _d S )NF)r†   r!   T)rM   rå   rˆ   ræ   rJ   )r#   rç   rF   r   r   r   Ú
set_yscale6  s    zAxes3D.set_yscalec             K   s0   | j j|f|Ž | jddd |  ¡  d| _dS )aå  
        Set the scaling of the z-axis: %(scale)s

        ACCEPTS: [%(scale)s]

        Different kwargs are accepted, depending on the scale:
        %(scale_docs)s

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

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        F)r†   r‡   TN)r;   rå   rˆ   ræ   rJ   )r#   rç   rF   r   r   r   r:   B  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
        )r;   Z	set_ticks)r#   rE   rF   r   r   r   Ú
set_zticksY  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)r;   Zget_ticklocs)r#   rë   r   r   r   Ú
get_ztickse  s    
zAxes3D.get_zticksc             C   s   t  d| j ¡ ¡S )zd
        Get the ztick labels as a list of Text instances

        .. versionadded :: 1.1.0
        zText zticklabel)r¿   Úsilent_listr;   Zget_majorticklabels)r#   r   r   r   Úget_zmajorticklabelsq  s    zAxes3D.get_zmajorticklabelsc             C   s   t  d| 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í   r;   Zget_minorticklabels)r#   r   r   r   Úget_zminorticklabelsz  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
        )r;   Zset_ticklabels)r#   rE   rF   r   r   r   Úset_zticklabels‡  s    
zAxes3D.set_zticklabelsc             C   s   t  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í   r;   Zget_ticklabels)r#   rë   r   r   r   Úget_zticklabels“  s    
zAxes3D.get_zticklabelsc             C   s   | 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)r;   Z	axis_date)r#   Ztzr   r   r   Ú
zaxis_date   s    zAxes3D.zaxis_datec             C   s
   | 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
        )r;   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#   rE   rF   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.

        This can be used to rotate the axes programmatically.

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

        if elev or azim are None (default), then the initial value
        is used which was specified in the :class:`Axes3D` constructor.
        é
   N)rW   r*   r   r)   r   )r#   r   r   r   r   r   r0   Â  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   sj  t j| j d t j| j d  }}|  ¡ \}}|  ¡ \}}|  ¡ \}}t ||||||¡}	t  	dddg¡}
|
d t  
|¡t  
|¡ | j  }|
d t  |¡t  
|¡ | j  }|
d t  |¡| j  }t  	|||f¡}|| _|
| | _| jt | j¡ | _t|ƒt jd krt  	d¡}n
t  	d¡}| j | j }}t ||
|¡}|  ||¡}t  ||	¡}t  ||¡}|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   rj   )r   r   éÿÿÿÿ)r   r   r   )r   Úpir   r   r¼   r½   r¾   r   Zworld_transformationr   ÚcosrW   Úsinr}   r|   ÚmodÚ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M0r8   r   r   r   r{   ì  s0    """

zAxes3D.get_projr   rk   c             C   s|   d| _ | jj}|dk	rN| d| j¡}| d| j¡}| d| j¡}|||g| _n
t 	d¡ t
 |¡ ¡ | _t
 |¡ ¡ | _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.

        ============  =======================================================
        Argument      Description
        ============  =======================================================
        *rotate_btn*  The integer or list of integers specifying which mouse
                      button or buttons to use for 3D rotation of the axes.
                      Default = 1.

        *zoom_btn*    The integer or list of integers specifying which mouse
                      button or buttons to use to zoom the 3D axes.
                      Default = 3.
        ============  =======================================================

        NZmotion_notify_eventZbutton_press_eventZbutton_release_eventzcAxes3D.figure.canvas is 'None', mouse rotation disabled.  Set canvas then call Axes3D.mouse_init().)Úbutton_pressedrC   rÏ   Zmpl_connectÚ_on_moveÚ_button_pressÚ_button_releaser(   r—   r˜   r   Ú
atleast_1dÚtolistÚ_rotate_btnÚ	_zoom_btn)r#   Z
rotate_btnZzoom_btnZcanvZc1Zc2Zc3r   r   r   r=     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_panG  s    zAxes3D.can_panc                sÀ   t ƒ  ¡  | j ¡  | jdk	rp| jjj| j_| jjj| j_| j ¡ \}}| j||ddd | j | jj 	¡ ¡ n2| j d¡ y|  dd¡ W n t
k
r    Y nX d| _d| _|  td ¡ dS )	z
        Clear axes
        NF)rÈ   rV   Zlinearr   r   Tzaxes3d.grid)r4   Úclar;   r2   Úmajorrë   rß   rà   rå   rã   r•   rŒ   r‘   Úgridr   )r#   rº   r»   )rH   r   r   r  O  s     


z
Axes3D.clac             C   s(   x| j D ]}| jj |¡ qW g | _ dS )z(Disable mouse button callbacks.
        N)r(   rC   rÏ   Zmpl_disconnect)r#   Zcidr   r   r   Údisable_mouse_rotationk  s    zAxes3D.disable_mouse_rotationc             C   s(   |j | kr$|j| _|j|j | _| _d S )N)ZinaxesZbuttonr  rP   rQ   ÚsxÚsy)r#   Úeventr   r   r   r  t  s    
zAxes3D._button_pressc             C   s
   d | _ d S )N)r  )r#   r  r   r   r   r  y  s    zAxes3D._button_releasec          	   C   s<   y
|   |¡S  ttfk
r6   | 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)r9   r¥   r•   r;   Zget_major_formatterZformat_data_short)r#   rN   ÚfuncÚvalr   r   r   Úformat_zdata|  s     
zAxes3D.format_zdatac                sè   | j dkrdS | j| jkr*d | j| j¡S t|  ¡ ‡ ‡fdd„d\}}|\}}}|\}}	}
t 	|ˆ  |ˆ ¡}t 	|ˆ  |	ˆ ¡}|| }|| | || |
  }t
 ˆ ˆ|| 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  | d | d ˆ ˆf¡S )Nr   r   )r   Zline2d_seg_dist)Zedge)ÚxdÚydr   r   r$   ™  s   z%Axes3D.format_coord.<locals>.<lambda>)rw   zx=%s, y=%s, z=%s)r8   r  r  Úformatr   r   Úminrq   r   Zhypotr   Zinv_transformZformat_xdataZformat_ydatar  )r#   r  r  Úp0Úp1rµ   r¸   rº   r¶   r¹   r»   Zd0Zd1ZdtrN   r   rZ   Ú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|| d  ¡| _t	 
| j|| d  ¡| _|  ¡  d| _| jj ¡  n¦| j | jkrx|  ¡ \}}	}
}}}d|| |  }|	| | }||
 | }|| | }|  || |	| ¡ |  |
| || ¡ |  || || ¡ |  ¡  | 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  r8   rP   rQ   r  r  rA   rB   r  r   Z
norm_angler   r   r{   rJ   rC   rÏ   rÐ   r	  r`   rÔ   rÜ   rá   )r#   r  r   rZ   ÚdxÚdyÚwÚhrb   rc   rd   re   rf   rg   ZdfÚdzr   r   r   r  «  s<    
	zAxes3D._on_movec             K   s"   |dk	r|| j _| j j||f|ŽS )zO
        Set zlabel.  See doc for :meth:`set_ylabel` for description.

        N)r;   ÚlabelpadZset_label_text)r#   ZzlabelÚfontdictr&  rF   r   r   r   Ú
set_zlabelã  s     zAxes3D.set_zlabelc             C   s   | j  ¡ }| ¡ S )z
        Get the z-label text string.

        .. versionadded :: 1.1.0
            This function was added, but not tested. Please report any bugs.
        )r;   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
        )rz   )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   rz   rJ   )r#   r   r   r   r   Úset_frame_onÿ  s    

zAxes3D.set_frame_onc             K   s"   t |ƒrd}t |¡| _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–   r¿   Z_string_to_boolZ
_draw_gridrJ   )r#   r   rF   r   r   r   r    s    zAxes3D.gridr  )ÚstyleÚ	scilimitsÚ	useOffsetrr   c         	   C   s¶  |  ¡ }|  ¡ }|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 |¡ |dkrÈ| jjj |¡ |dkrà| jjj |¡ |dk	r8|dkr| jjj 	|¡ |dkr| jjj 	|¡ |dkr8| jjj 	|¡ |dk	r|dkr\| jjj 
|¡ |dkrv| jjj 
|¡ |dkr| 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 integersrk   ZsciTZplainFr  z%s is not a valid style value)rœ   rN   )rœ   rZ   )rœ   r   z0This method only works with the ScalarFormatter.)Úlowerr   r•   rK   r  Z	formatterZset_scientificrM   r;   Zset_powerlimitsZset_useOffsetr¥   )r#   r-  r.  r/  rr   r’   ÚnZsbr   r   r   Úticklabel_format  sP    







zAxes3D.ticklabel_formatc             K   sp   |dk}|dk}|dk}|r.| j  ¡ jf |Ž |rD| j ¡ jf |Ž |rZ| 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.
        )r   rœ   )rZ   rœ   )rN   rœ   )r”   r†   r‡   r!   N)rK   r°   Z
set_paramsrM   r;   rˆ   )r#   rr   r”   rF   Z_xZ_yZ_zr   r   r   Úlocator_paramsX  s    zAxes3D.locator_paramsc                sb   t ƒ j|f|Ž |dkr^t|ƒ}| dd¡ | dd¡ | dd¡ | 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.
        )rN   rœ   rÙ   NrØ   ZlabeltopZlabelbottom)r4   Útick_paramsÚdictrT   r;   Zset_tick_params)r#   rr   rF   Zzkw)rH   r   r   r4  q  s    zAxes3D.tick_paramsc             C   s    |   ¡ \}}| 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)rV   )rß   rà   )r#   rØ   rÙ   r   r   r   Úinvert_zaxis—  s    zAxes3D.invert_zaxisc             C   s   |   ¡ \}}||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(   |   ¡ \}}||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  |¡r|\}}|  ¡ \}}|dkr2|}|dkr>|}|  ¡ 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)rV   )r¿   rÀ   r8  r7  rà   )r#   r0  ÚupperZ	old_lowerZ	old_upperr   r   r   r´   º  s    	  zAxes3D.set_zboundc                s&   t ƒ j|||f|Ž}t |||¡ |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.
        )r4   Útextr   Ztext_2d_to_3d)r#   r   rZ   rN   ÚsÚzdirrF   r:  )rH   r   r   r:  Ö  s    zAxes3D.textrN   )r<  c      
         sº   |   ¡ }|r@t|d tƒs@|d }|dd… }d|krLtdƒ‚n| dd¡}t |t|ƒ¡}tƒ j	||f|ž|Ž}x|D ]}	t
j|	||d qxW t
 ||||¡\}}}|  ||||¡ |S )ao  
        Plot 2D or 3D data.

        ==========  ================================================
        Argument    Description
        ==========  ================================================
        *xs*, *ys*  x, y coordinates of vertices

        *zs*        z value(s), either one for all points or one for
                    each point.
        *zdir*      Which direction to use as z ('x', 'y' or 'z')
                    when plotting a 2D set.
        ==========  ================================================

        Other arguments are passed on to
        :func:`~matplotlib.axes.Axes.plot`
        r   r   Nr  z+plot() for multiple values for argument 'z')r  r<  )Úhas_dataÚ
isinstanceÚstrr•   rT   r   Úbroadcast_tor–   r4   Úplotr   Zline_2d_to_3dÚjuggle_axesr«   )
r#   r  r  r<  rE   rF   rª   r  r®   Úline)rH   r   r   rA  ã  s    

zAxes3D.plot)ÚnormÚvminÚvmaxÚlightsourcec                sB  |   ¡ }
|jdkrtdƒ‚t |||¡\}}}|j\}}d|	kpFd|	k}d|	kpVd|	k}|rh|rhtdƒ‚|	 dd¡}|	 dd¡}|	 dd	¡}|	 dd	¡}td
 r¦|}n| }|ràtt	t 
|| ¡dƒƒ}tt	t 
|| ¡dƒƒ}d|	krô|	 d¡}n4|	 dd¡}|dkr| j ¡ }t t |¡¡}d}|	 dd¡}|	 d|dk¡}|rl|dk	rl|dk	rl|  |||¡}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}| |¡ |dk	rð| |ˆ ˆ  ¡ qðW qÌW dd„ }tj|f|ž|	Ž}|dk	r¤|rŽ|  |||ƒ¡}| |¡ | |¡ n€|rþt dd„ |D ƒ¡}| |¡ |dk	sÜ|dk	rè| ||¡ |dk	r$| |¡ n&|r|  |||ƒ¡}n|}| |¡ |  |¡ |   ||||
¡ |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 face colors.

        **kwargs :
            Other arguments are forwarded to `.Poly3DCollection`.
        rj   z!Argument Z must be 2-dimensional.ÚrstrideÚcstrideÚrcountÚccountz.Cannot specify both stride and count argumentsrõ   é2   z_internal.classic_moder   Ú
facecolorsÚcolorNÚcmapÚshader   rø   c          	      s.   g | ]&}t  |ˆˆd  …ˆ ˆd  …f ¡‘qS )r   )r¿   Z_array_perimeter)r   Úa)ÚcsÚcs_nextÚrsÚrs_nextr   r   r    ƒ  s   z'Axes3D.plot_surface.<locals>.<listcomp>c             S   sÂ   t  t| ƒdf¡}t  t| ƒdf¡}xt| ƒD ]„\}}dt|ƒd dt|ƒ d   }}}||dd…f ||dd…f  ||dd…f< ||dd…f ||dd…f  ||dd…f< q.W t  ||¡S )zW
            Takes a list of polygons and return an array of their normals
            rk   r   rj   N)r   Úemptyr–   r€   Úcross)ÚpolygonsÚv1Úv2Zpoly_iÚpsÚi1Úi2Zi3r   r   r   Úget_normals  s    $,0z(Axes3D.plot_surface.<locals>.get_normalsc             S   s    g | ]}|d d …df   ¡ ‘qS )Nrj   )Úmean)r   r[  r   r   r   r    ¦  s    )!r=  Úndimr   r   Úbroadcast_arraysÚshaperT   r   Úintr   ÚceilÚ
_get_linesÚget_next_colorr   ÚmcolorsÚto_rgbaÚgetÚ_shade_colors_lightsourceÚlistÚrangeÚzipr¦   Úappendr   ÚPoly3DCollectionÚ_shade_colorsÚset_facecolorsZset_edgecolorsÚ	set_arrayÚset_climÚset_normÚadd_collectionr«   ) r#   r§   r¨   r©   rD  rE  rF  rG  rE   rF   rª   ÚrowsÚcolsÚ
has_strideÚ	has_countrH  rI  rJ  rK  Zcompute_stridesZfcolorsrN  rO  rP  Zrow_indsZcol_indsÚcolsetÚpolysr[  r^  ÚpolycÚavg_zr   )rR  rS  rT  rU  r   Úplot_surface  s~    9



$$







zAxes3D.plot_surfacec             C   s`   g }xV|D ]N}t  |d ¡t  |d ¡ }t  |d ¡t  |d ¡ }| t  ||¡¡ q
W |S )zÊ
        Generate normals for polygons by using the first three points.
        This normal of course might not make sense for polygons with
        more than three points not lying in a plane.
        r   r   rj   )r   r   rn  rW  )r#   rX  ÚnormalsÚvertsrY  rZ  r   r   r   Ú_generate_normals¸  s    
zAxes3D._generate_normalsc             C   s¼   t  dd„ |D ƒ¡}t  |¡ }t|| ƒdkrªtt|| ƒt|| ƒƒ}t|| ƒ|| < t |¡}|dd…df }d||ƒdd…t j	f d  | }||dd…df< nt  
|¡ ¡ }|S )zŽ
        Shade *color* using normal vectors given by *normals*.
        *color* can also be an array of the same length as *normals*.
        c             S   s8   g | ]0}t  |¡r.t |t  |¡ d d dg¡ntj‘qS )rø   g      à?)r   rü   r   rþ   Únan)r   r1  r   r   r   r    Ì  s   z(Axes3D._shade_colors.<locals>.<listcomp>r   Nrk   g      à?)r   r   Zisnanr–   r   r  r   rg  Úto_rgba_arrayZnewaxisZ
asanyarrayÚcopy)r#   rN  r  rP  ÚmaskrD  ÚalphaÚcolorsr   r   r   rp  Æ  s    


"zAxes3D._shade_colorsc             C   s    |d krt ddd}| ||¡S )Né‡   é7   )ZazdegZaltdeg)r   rP  )r#   ÚdatarO  rG  r   r   r   rj  à  s    z Axes3D._shade_colors_lightsourcec                sÖ  |   ¡ }ˆjdkrtdƒ‚t ˆ ˆˆ¡\‰ ‰‰ˆj\}}d|kpFd|k}	d|kpVd|k}
|	rh|
rhtdƒ‚| dd¡}| dd¡}| dd	¡}| dd	¡}td
 ræ|
rä|rÀtt	t 
|| ¡dƒƒnd}|ràtt	t 
|| ¡dƒƒnd}nJ|	s0|r
tt	t 
|| ¡dƒƒnd}|r,tt	t 
|| ¡dƒƒnd}t ˆ ¡t ˆ¡t ˆ¡  ‰‰‰|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|ž|Ž}|  |¡ |  ˆ ˆˆ|¡ |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`.
        rj   z!Argument Z must be 2-dimensional.rH  rI  rJ  rK  z.Cannot specify both stride and count argumentsr   rL  z_internal.classic_moder   rø   z*Either rstride or cstride must be non zeroc                s   g | ]}ˆ | ‘qS r   r   )r   r…   )r§   r   r   r    J  s    z)Axes3D.plot_wireframe.<locals>.<listcomp>c                s   g | ]}ˆ | ‘qS r   r   )r   r…   )r¨   r   r   r    K  s    c                s   g | ]}ˆ | ‘qS r   r   )r   r…   )r©   r   r   r    L  s    c                s   g | ]}ˆ | ‘qS r   r   )r   r…   )ÚtXr   r   r    N  s    c                s   g | ]}ˆ | ‘qS r   r   )r   r…   )ÚtYr   r   r    O  s    c                s   g | ]}ˆ | ‘qS r   r   )r   r…   )ÚtZr   r   r    P  s    c             S   s"   g | ]\}}}t t|||ƒƒ‘qS r   )rk  rm  )r   ÚxlÚylÚzlr   r   r   r    R  s   c             S   s"   g | ]\}}}t t|||ƒƒ‘qS r   )rk  rm  )r   rŽ  r  r  r   r   r   r    T  s   )r=  r`  r   r   ra  rb  rT   r   rc  r   rd  Z	transposerk  rl  Úsizerm  r   ÚLine3DCollectionru  r«   )r#   r§   r¨   r©   rE   rF   rª   rv  rw  rx  ry  rH  rI  rJ  rK  ZriiZciiZxlinesZylinesZzlinesZtxlinesZtylinesZtzlinesr®   Úlinecr   )r§   r¨   r©   r‹  rŒ  r  r   Úplot_wireframeå  sd    (

 """"
zAxes3D.plot_wireframe)rN  rD  rE  rF  rG  c            O   sâ  |   ¡ }|dkr| j ¡ }t t |¡¡}| dd¡}	| d|	dk¡}
t	j
||Ž\}}}d|krrt | d¡¡}nt |d ¡}|dd… }| ¡ }|j| }|j| }|| }tj|||fdd}tj|f|ž|Ž}|	r:|dd…dd…d	f jdd}| |¡ |dk	s|dk	r$| ||¡ |dk	rÀ| |¡ n†|
r²|dd…ddd…f |dd…ddd…f  }|dd…ddd…f |dd…d	dd…f  }t ||¡}|  ||¡}n|}| |¡ |  |¡ |  |j|j||¡ |S )
ap  
        ============= ================================================
        Argument      Description
        ============= ================================================
        *X*, *Y*, *Z* Data values as 1D arrays
        *color*       Color of the surface patches
        *cmap*        A colormap for the surface patches.
        *norm*        An instance of Normalize to map values to colors
        *vmin*        Minimum value to map
        *vmax*        Maximum value to map
        *shade*       Whether to shade the facecolors
        ============= ================================================

        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.

        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.
        NrO  rP  r©   r   r   rø   )rr   rj   )r=  re  rf  r   r   rg  rh  ri  rT   r
   Úget_from_args_and_kwargsr£   Zget_masked_trianglesr   rZ   Ústackr   ro  r_  rr  rs  rt  rW  rp  rq  ru  r«   )r#   rN  rD  rE  rF  rG  rE   rF   rª   rO  rP  ÚtrirN   Ú	trianglesZxtZytZztr€  r|  r}  rY  rZ  r  rz  r   r   r   Úplot_trisurf]  sD    2




,,

zAxes3D.plot_trisurfrm   c          	   C   sü  |j }|j}|d |d  d }x¸t||ƒD ]¨\}}| ¡ }|sFq.t ||| ¡}	t ||| ¡}
| ¡ d }g }g }t t	|	d ƒ| ¡}|dkr°t	|	d ƒdkr.d}nq.t	|	d ƒd |d  }xÒt
tt |¡ƒd ƒD ]¸}tt || ¡ƒ}tt |d | ¡ƒ}| |	d | |	d | |
d | |
d | g¡ t |	d | ¡t |	d | ¡ }t |	d | ¡t |
d | ¡ }| t ||¡¡ qàW |  ||¡}|  ||¡}tj|||d}| |¡ |  |¡ q.W x|D ]}| j |¡ qâW dS )z4
        Extend a contour in 3D by creating
        r   r   rj   )rM  Ú
edgecolorsN)Úlevelsr‚   rm  Z	get_pathsr   Zpaths_to_3d_segmentsZ	get_colorr   Úroundr–   rl  rc  rn  r   rW  rp  ro  Úset_sort_zposÚadd_collection3dÚremove)r#   ÚcsetÚstrider›  Zcollsr%  rN   r“  ÚpathsZtopvertsZbotvertsrN  Z	polyvertsr  ZnstepsZstepsizer…   r\  r]  rY  rZ  r‡  Zcolors2Zpolycolru   r   r   r   Ú_3d_extend_contourÀ  sJ    

$$

zAxes3D._3d_extend_contourc             C   sV   d| }|r|   ||¡ n8x6t|j|jƒD ]$\}}|d k	r>|}tj|||d q*W d S )Nú-)r<  )r£  rm  r›  r‚   r   Úline_collection_2d_to_3d)r#   r   Úextend3dr¡  r<  ÚoffsetrN   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 | |¡ qW d S )Nr¤  )r<  )rm  r›  r‚   r   Úpoly_collection_2d_to_3dr  )r#   r   r<  r§  rN   r“  r   r   r   Úadd_contourf_setý  s    zAxes3D.add_contourf_set)r¦  r¡  r<  r§  c               s\   |   ¡ }
t ||||¡\}}}tƒ j|||f|ž|	Ž}|  |||||¡ |  ||||
¡ |S )aI  
        Create a 3D contour plot.

        ==========  ================================================
        Argument    Description
        ==========  ================================================
        *X*, *Y*,   Data values as numpy.arrays
        *Z*
        *extend3d*  Whether to extend contour in 3D (default: False)
        *stride*    Stride (step size) for extending contour
        *zdir*      The direction to use: x, y or z (default)
        *offset*    If specified plot a projection of the contour
                    lines on this position in plane normal to zdir
        ==========  ================================================

        The positional and other keyword arguments are passed on to
        :func:`~matplotlib.axes.Axes.contour`

        Returns a :class:`~matplotlib.axes.Axes.contour`
        )r=  r   Úrotate_axesr4   Úcontourr¨  r«   )r#   r§   r¨   r©   r¦  r¡  r<  r§  rE   rF   rª   ÚjXÚjYÚjZr   )rH   r   r   r¬    s    zAxes3D.contourc               s²   |   ¡ }tj||Ž\}}}|j}	|j}
d|kr:| d¡}n|d }|dd… }t |	|
||¡\}}}t|||j|j	ƒ}t
ƒ j||f|ž|Ž}|  |||||¡ |  |	|
||¡ |S )a  
        Create a 3D contour plot.

        ==========  ================================================
        Argument    Description
        ==========  ================================================
        *X*, *Y*,   Data values as numpy.arrays
        *Z*
        *extend3d*  Whether to extend contour in 3D (default: False)
        *stride*    Stride (step size) for extending contour
        *zdir*      The direction to use: x, y or z (default)
        *offset*    If specified plot a projection of the contour
                    lines on this position in plane normal to zdir
        ==========  ================================================

        Other keyword arguments are passed on to
        :func:`~matplotlib.axes.Axes.tricontour`

        Returns a :class:`~matplotlib.axes.Axes.contour`

        .. versionchanged:: 1.3.0
            Added support for custom triangulations

        EXPERIMENTAL:  This method currently produces incorrect output due to a
        longstanding bug in 3D PolyCollection rendering.
        r©   r   r   N)r=  r
   r•  r   rZ   rT   r   r«  r˜  r…  r4   Ú
tricontourr¨  r«   )r#   r¦  r¡  r<  r§  rE   rF   rª   r—  r§   r¨   r©   r­  r®  r¯  r   )rH   r   r   r°  '  s    zAxes3D.tricontour)r<  r§  c               sX   |   ¡ }t ||||¡\}	}
}tƒ j|	|
|f|ž|Ž}|  |||¡ |  ||||¡ |S )a   
        Create a 3D contourf plot.

        ==========  ================================================
        Argument    Description
        ==========  ================================================
        *X*, *Y*,   Data values as numpy.arrays
        *Z*
        *zdir*      The direction to use: x, y or z (default)
        *offset*    If specified plot a projection of the filled contour
                    on this position in plane normal to zdir
        ==========  ================================================

        The positional and keyword arguments are passed on to
        :func:`~matplotlib.axes.Axes.contourf`

        Returns a :class:`~matplotlib.axes.Axes.contourf`

        .. versionchanged :: 1.1.0
            The *zdir* and *offset* kwargs were added.
        )r=  r   r«  r4   Úcontourfrª  r«   )r#   r§   r¨   r©   r<  r§  rE   rF   rª   r­  r®  r¯  r   )rH   r   r   r±  Z  s    zAxes3D.contourfc               s®   |   ¡ }tj||Ž\}}}|j}|j}d|kr:| d¡}	n|d }	|dd… }t |||	|¡\}
}}t|
||j|j	ƒ}t
ƒ j||f|ž|Ž}|  |||¡ |  |||	|¡ |S )aš  
        Create a 3D contourf plot.

        ==========  ================================================
        Argument    Description
        ==========  ================================================
        *X*, *Y*,   Data values as numpy.arrays
        *Z*
        *zdir*      The direction to use: x, y or z (default)
        *offset*    If specified plot a projection of the contour
                    lines on this position in plane normal to zdir
        ==========  ================================================

        Other keyword arguments are passed on to
        :func:`~matplotlib.axes.Axes.tricontour`

        Returns a :class:`~matplotlib.axes.Axes.contour`

        .. versionchanged :: 1.3.0
            Added support for custom triangulations

        EXPERIMENTAL:  This method currently produces incorrect output due to a
        longstanding bug in 3D PolyCollection rendering.
        r©   r   r   N)r=  r
   r•  r   rZ   rT   r   r«  r˜  r…  r4   Útricontourfrª  r«   )r#   r<  r§  rE   rF   rª   r—  r§   r¨   r©   r­  r®  r¯  r   )rH   r   r   r²  |  s    zAxes3D.tricontourfr   c                s°   t  |¡}t|ƒdkr t|ƒ}nd}t|ƒtjkrNtj|||d | 	|¡ nRt|ƒtj
krxtj|||d | 	|¡ n(t|ƒtjkr tj|||d | 	|¡ tƒ  |¡ 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  r<  N)r   r  r–   r  ÚtypeÚmcollZPolyCollectionr   r©  r  ZLineCollectionr¥  ZPatchCollectionÚpatch_collection_2d_to_3dr4   ru  )r#   ru   r  r<  ZzvalsZzsortval)rH   r   r   rž  ¬  s    


zAxes3D.add_collection3dé   c                sÔ   |   ¡ }
tjdd„ |||gD ƒŽ \}}}tj |¡}t |||||¡\}}}}}tƒ j||f|ž||dœ|	—Ž}t 	|¡ }t 
|t|ƒ¡}tj||||d | jdk r¼|jdkr¼|  d¡ |sÐ|  ||||
¡ |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  t j |t j¡¡‘qS r   )r   ÚravelÚmaÚfilledr‚  )r   Útr   r   r   r    ü  s    z"Axes3D.scatter.<locals>.<listcomp>)r;  Úc)r  r<  Ú
depthshadegš™™™™™©?r   )r=  r   ra  r¸  r·  r¿   Zdelete_masked_pointsr4   ÚscatterrÀ   r@  r–   r   rµ  r‘   r‘  r“   r«   )r#   r  r  r  r<  r;  r»  r¼  rE   rF   rª   rƒ   Zis_2d)rH   r   r   r½  Í  s    , 

zAxes3D.scatterc                sì   |   ¡ }tƒ j||f|ž|Ž}t |t|ƒ¡}g }	g }
xbt||ƒD ]T\}}t |¡}|	| 	¡ 7 }	|
|gt|ƒ 7 }
t 
|||¡ d|krB| |d ¡ qBW t|	ƒdkr¸tt|	Ž ƒ\}}n
g g  }}t |||
|¡\}}}
|  |||
|¡ |S )a  
        Add 2D bar(s).

        ==========  ================================================
        Argument    Description
        ==========  ================================================
        *left*      The x coordinates of the left sides of the bars.
        *height*    The height of the bars.
        *zs*        Z coordinate of bars, if one value is specified
                    they will all be placed at the same z.
        *zdir*      Which direction to use as z ('x', 'y' or 'z')
                    when plotting a 2D set.
        ==========  ================================================

        Keyword arguments are passed onto :func:`~matplotlib.axes.Axes.bar`.

        Returns a :class:`~mpl_toolkits.mplot3d.art3d.Patch3DCollection`
        r†  r   )r=  r4   Úbarr   r@  r–   rm  r   Zget_patch_vertsr  Zpatch_2d_to_3dZ	set_alphark  rB  r«   )r#   rÑ   Zheightr  r<  rE   rF   rª   rƒ   r€  Zverts_zsÚprN   Zvsr  r  )rH   r   r   r¾  	  s$    

z
Axes3D.barÚaveragec
             O   sò  |   ¡ }t t |¡|||||¡\}}}}}}t |¡}t || ¡}t |¡}t || ¡}t |¡}t || ¡}g }xŽt||||||ƒD ]v\}}}}}}| |||f|| ||f|| || |f||| |ff|||| f|| ||| f|| || || f||| || ff|||f|| ||f|| ||| f|||| ff||| |f|| || |f|| || || f||| || ff|||f||| |f||| || f|||| ff|| ||f|| || |f|| || || f|| ||| ffg¡ qW g }|dkr&| j 	¡ g}t
|ƒt
|ƒkrZxP|D ]}| |gd ¡ q>W n0tt |¡ƒ}t
|ƒt
|ƒk rŠ|dt
|ƒ 9 }|	r¨|  |¡}|  ||¡}n|}tj|f|
ž||dœ|—Ž}|  |¡ |  ||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
            :func:`~mpl_toolkits.mplot3d.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).

        Any additional keyword arguments are passed onto
        :func:`~mpl_toolkits.mplot3d.art3d.Poly3DCollection`

        Returns
        -------
        collection : Poly3DCollection
            A collection of three dimensional polygons representing
            the bars.
        Nrn   )ÚzsortZ	facecolor)r=  r   ra  r  r  r   rm  ÚextendÚ_get_patches_for_fillrf  r–   rk  rg  rƒ  r  rp  r   ro  ru  r«   )r#   r   rZ   rN   r!  r"  r%  rN  rÁ  rP  rE   rF   rª   rb   rc   rd   re   rf   rg   r{  ZxiZyiZziZdxiZdyiZdzirM  r»  r  Zsfacecolorsru   r   r   r   Úbar3dC	  sT    7"


(&&0



zAxes3D.bar3dÚcenterc                s<   t ƒ j|f||dœ|—Ž}| j ¡ \}}| j d| ¡ |S )N)r'  Úlocgq=
×£pí?)r4   Ú	set_titleÚtitleZget_positionZset_y)r#   r)  r'  rÆ  rF   Zretr   rZ   )rH   r   r   rÇ  ¶	  s    zAxes3D.set_titleg333333Ó?Útail)ÚlengthÚarrow_length_ratioÚpivotÚ	normalizec               sÚ  ddd„‰ |   ¡ }d}t|ƒ|k r6td|t|ƒf ƒ‚|d|… }	dd„ |	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… ž|Ž}|  
|¡ |S tdd„ |	D ƒƒst‚tdd„ |	D ƒƒdks$t‚tjd|dd}|| }|dkrP||8 }n2|dkrh||d 8 }n|dkr‚tdt|ƒ ƒ‚t |	dd… ¡}t |	d|… ¡ t¡}tjj|dd}|dk‰|ˆ }|rê|ˆ |ˆ  d¡ }n|ˆ }t|ƒdkrz|tj ||¡  dd¡}t ‡ fdd„|D ƒ¡}|dd…dd…f tj ||¡ }t|ƒddf|_| dd¡}||•}ng }tj	|f||d… ž|Ž}|  
|¡ |  |dd…df |dd…df |dd…df |¡ |S ) a  
        Plot a 3D field of arrows.

        call signatures::

            quiver(X, Y, Z, U, V, W, **kwargs)

        Arguments:

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

            *U*, *V*, *W*:
                The x, y and z components of the arrow vectors

        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.

        Keyword arguments:

            *length*: [1.0 | float]
                The length of each quiver, default to 1.0, the unit is
                the same with the axes

            *arrow_length_ratio*: [0.3 | 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.

        Any additional keyword arguments are delegated to
        :class:`~matplotlib.collections.LineCollection`

        é   c       
      S   s  t j | dd… ¡}|dkr8| d | }| d  | }nd\}}t |¡}t |¡}t |¡}t  ||d d|   || d|  || g|| d|  ||d d|   | | g| | || |gg¡}| ¡ }	|	ddddgddddgf  |	ddddgddddgf< | 	| ¡|	 	| ¡fS )zu
            To calculate the arrow head. uvw should be a unit vector.
            We normalize it here:
            Nrj   r   r   )r   r   )
r   ÚlinalgrD  ÚmathZradiansrú   rû   r   r„  rþ   )
ZuvwZanglerD  r   rZ   Zrar»  r;  ZRposZRnegr   r   r   Ú
calc_arrowí	  s    


,*6z!Axes3D.quiver.<locals>.calc_arrowrn   z-Wrong number of arguments. Expected %d got %dNc             S   s$   g | ]}t |ttfƒr|gn|‘qS r   )r>  rc  Úfloat)r   rG   r   r   r   r    
  s   z!Axes3D.quiver.<locals>.<listcomp>c             S   s    g | ]}t |tjjƒr|j‘qS r   )r>  r   r¸  ZMaskedArrayr…  )r   rG   r   r   r   r    
  s    c                s    g | ]}t jj|ˆ d  ¡ ‘qS ))r…  )r   r¸  r   Z
compressed)r   rG   )r…  r   r   r    "
  s   c             S   s   g | ]}|  ¡ ‘qS r   )r¤   )r   rG   r   r   r   r    %
  s    c             s   s   | ]}t |ƒd kV  qdS )r   N)r–   )r   Úvr   r   r   rs   '
  s    z Axes3D.quiver.<locals>.<genexpr>c             s   s   | ]}t |tjƒV  qd S )N)r>  r   Zndarray)r   rG   r   r   r   rs   /
  s    c             S   s   h | ]
}|j ’qS r   )rb  )r   rG   r   r   r   ú	<setcomp>1
  s    z Axes3D.quiver.<locals>.<setcomp>r   r   rj   )ZnumrÉ  Zmiddleg       @ZtipzInvalid pivot argument: rk   )rr   )rø   r   c                s   g | ]}ˆ |ƒ‘qS r   r   )r   Úd)rÑ  r   r   r    O
  s    rø   )rÎ  )r=  r–   r   r   ra  r   Z
logical_orÚanyr   r’  ru  ÚallÚAssertionErrorZlinspacer?  Zcolumn_stackZastyperÒ  rÏ  rD  ZreshapeZmultiplyZouterZswapaxesr   rb  r«   )r#   rÊ  rË  rÌ  rÍ  rE   rF   rª   ZargiZ
input_argsZmasksZbcastr“  Zshaft_dtZarrow_dtZXYZZUVWrD  ZshaftsZ	head_dirsZheadsr®   r   )rÑ  r…  r   Úquiver½	  sh    0







"

4zAxes3D.quiver)rM  rš  c      ,   	      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 ˆ ¡\}}	}
n‡ fd	d
„|D ƒ\}}	}
‡fdd„}|dkr®| j	 
¡ }||dƒ}||dƒ}|  ||	|
¡ 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 |¡\}}}t |¡}t |¡}t |¡}| |j¡}xH|D ]>}x4|D ]*}| ||dg¡}t|ƒ}ˆ| r®||  || ¡ x¦t|dd… |dd… ƒD ]ˆ\}}| |||g¡}| |||g¡}t|ƒ}t|ƒ} ˆ| r*ˆ|  s*||  || ¡ n&ˆ| sÊˆ|  rÊ||   || ¡ qÊW | |||d g¡}!| |||g¡}"t|!ƒ}#ˆ|# rt||#  |"| ¡ qtW qfW qW i }$xì| ¡ D ]à\}%}&|dkrÖ|&}'n”g }'xŽ|&D ]†}(|(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< |' |*¡ qàW tj|'f||% ||% dœ|—Ž}+|  |+¡ |+|$|%< q¾W |$S )aa
  
        ax.voxels([x, y, z,] /, filled, **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.

        Call signatures::

            voxels(filled, facecolors=fc, edgecolors=ec, **kwargs)
            voxels(x, y, z, filled, facecolors=fc, edgecolors=ec, **kwargs)

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

        **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
        rk   c             [   s   | ||f||fS )Nr   )Z
_Axes3D__xZ
_Axes3D__yZ
_Axes3D__zr¹  rF   r   r   r   Úvoxels¬
  s    zAxes3D.voxels.<locals>.voxelsc             [   s
   d | |fS )Nr   )r¹  rF   r   r   r   rÚ  ¯
  s    z%Argument filled must be 3-dimensional)Údtyper   Nc             3   s   | ]}t  |ˆ ¡V  qd S )N)r   r@  )r   r»  )Úcoord_shaper   r   rs   ¾
  s    z Axes3D.voxels.<locals>.<genexpr>c                sp   t  | ¡dkr&t  | ˆ jt  | ¡ ¡S t  | ¡dkr^t  | ¡d d… ˆ jkrZtd |¡ƒ‚| S td |¡ƒ‚d S )N)r   r   )rk   rl   rk   z8When multidimensional, {} must match the shape of filledzInvalid {} argument)r   r`  r@  rb  r   r  )rN  rÅ   )r¹  r   r   Ú_broadcast_color_argÀ
  s    z+Axes3D.voxels.<locals>._broadcast_color_argrM  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 matices )rÛ  r   r   )rr   N)r   r}   Úintprl  Zroll)r1  Zmatr…   r   r   r   Úpermutation_matricesã
  s    z+Axes3D.voxels.<locals>.permutation_matricesrø   rj   )rM  rš  )r–   r`  r   r   r   rb  rÞ  râ   ÚindicesrÃ  rf  r«   r   rk  r¦   rþ   Úarangern  rm  ÚitemsrV  r   ro  rž  ),r#   rM  rš  rE   rF   rÚ  Zxyzr‘  r   rZ   rN   rÝ  ZsquareZvoxel_facesrß  ZpermuteZpcZqcZrcZpindsZqindsZrindsZ
square_rotr¿  Úqr  Zi0Zr1Zr2r  Zp2r\  r]  ZpkZpk2ZikrX  ZcoordZ
faces_indsZfacesZ	face_indsZindZfaceZpolyr   )rÜ  r¹  r   rÚ  d
  sŒ    F






	



$
$

.

zAxes3D.voxels)N)NNNN)N)NN)NN)FFF)Trœ   N)NN)NTTT)NN)NNTF)NNTF)NNTF)F)F)N)NN)r   rk   )NN)T)rœ   N)rœ   )NN)N)rm   )Frm   rN   N)rN   N)r   rN   )r   rN   r¶  NT)r   rN   )NrÀ  T)NrÅ  )zÚ__name__Ú
__module__Ú__qualname__Ú__doc__rÅ   r¿   ZGrouperr3   r5   r6   r7   rL   rO   rS   r>   r]   r^   r_   rh   ri   rq   r   Zallow_rasterizationry   r~   r"   r‰   rŠ   r‹   r   rŽ   r“   r›   r¡   r«   rˆ   r`   rÃ   rÔ   rX   rÜ   rY   rá   rà   r¼   Úmaxesr   rË   r½   r×   r¾   rß   rä   rè   ré   Ú	docstringZdedent_interpdr:   rê   rì   rî   rï   rð   rñ   rò   ró   rô   r0   r+   r{   r=   r
  r  r  r  r  r  r  r   r  r(  r*  r+  r,  r  r2  r3  r4  r6  r7  r8  r´   r:  Ztext3DZtext2DrA  Zplot3Dr~  r  rp  rj  r”  r™  r£  r¨  rª  r¬  Z	contour3Dr°  r±  Z
contourf3Dr²  rž  r½  Z	scatter3Dr¾  rÄ  rÇ  rÙ  Zquiver3DrÚ  Ú__classcell__r   r   )rH   r   r   *   s  R
 


3
			D

 
O
777
	



/
$	#8

8
&



* )xb
3


	2 0!C1 
r %r   çš™™™™™©?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 )	z6
    Return a tuple X, Y, Z with a test data set.
    g      Àg      @rj   r   g      ø?g      à?rõ   iô  )r   rá  ZmeshgridZexprù   )r·   r   rZ   r§   r¨   ZZ1ZZ2r©   r   r   r   Úget_test_data1  s    &*rì  )rë  )0rç  Ú	functoolsr   r‚   r   rÐ  r—   Znumpyr   Z
matplotlibr   Zmatplotlib.axesZaxesrè  Zmatplotlib.cbookr¿   Zmatplotlib.collectionsr´  Zmatplotlib.colorsr‡  rg  Zmatplotlib.docstringré  Zmatplotlib.scaler   r&   Zmatplotlib.transformsZ
transformsr²   r   r   r   r   r	   Zmatplotlib.tri.triangulationr
   r  r   r   r   r   r   rì  Zmatplotlib.projectionsZprojectionsZprojZprojection_registryÚregisterr   r   r   r   Ú<module>   s^                         
