
    Le@$                     *   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 ddlmZ ddlmZ  G d de          Z G d dee          Z G d dee          Z G d de          Z G d de          ZdS )    N)cm)Line3DCollection)Version   )	Dimension)abbreviated_exception)dim   )
map_colors   )	PointPlot)ColorbarPlot)PathPlot)mpl_versionc                       e Zd ZdZ ej        ddd          Z ej        ddd          Z ej        d	d
d          Z ej	        dd          Z
 ej        dd          Z ej        g dd          Z ej        ddgd          Z ej	        dd          Z ej        dddgd          Z ej        dddgd          Z ej        dddgd          Z fdZddZ xZS )Plot3DzI
    Plot3D provides a common baseclass for mplot3d based
    plots.
    i)iL   z(
        Azimuth angle in the x,y plane.)defaultboundsdoc   )r   r   z'
        Elevation angle in the z-axis.
   )      z*
        Distance from the plotted object.Fz
        Disable all axes.r   r   whitez&
        Background color of the axis.)xyzz5
        Whether to plot the 'x', 'y' and 'z' labels.3dz/
        The projection of the matplotlib axis.r   objectsr   Tz.
        Whether to draw a grid in the figure.fixedNz0
        Whether and where to display the xaxis.z0
        Whether and where to display the yaxis.c                    | j         d         }| j         d                             d           |                    | j                   |                    | j        | j                   	 | j        |_        n# t          $ r | j        |_
        Y nw xY w| j        >|j        j                            d           |j        j                            d           | j        >|j        j                            d           |j        j                            d           | j        >|j        j                            d           |j        j                            d           | j        r|                                 t.          t1          d          k    r|                    | j                   n|                    | j                    t9                      j        |fi |S )	z
        Extends the ElementPlot _finalize_axis method to set appropriate
        labels, and axes options for 3D Plots.
        axisfigF)elevazimNg         z1.5.9)handlesset_frameongrid	show_grid	view_init	elevationazimuthdistance_dist	Exceptiondistxaxisw_xaxislineset_lwlabelset_textyaxisw_yaxiszaxisw_zaxisdisable_axesset_axis_offr   r   set_axis_bgcolorbgcolorset_facecolorsuper_finalize_axis)selfkeykwargsr%   	__class__s       >lib/python3.11/site-packages/holoviews/plotting/mpl/chart3d.pyrE   zPlot3D._finalize_axis;   s   
 |F#U''...		$.!!!DN>>>	&DJJ 	& 	& 	& DIII	&
 :L$$R(((L''+++:L$$R(((L''+++:L$$R(((L''+++ 	 ''****!!$,////t|,,,%uww%c44V444s   +A8 8BBc                 <   || j         j        }| j                            dd           }| j        d         }| j        d         }t	          |t
                    r|j        }|At          | d          r|                    | j	                  }n@|                    d          }n*t	          |t                    s|                    |          }|j        }|                    |d|          }|| j        d<   |j        | j        d	<   |                     |||           d S )
Nartistr&   r%   color_indexr
   gffffff?)shrinkaxcbarcax)hmaplastr*   get
isinstancedim_expr	dimensionhasattrget_dimensionrM   r   pprint_labelcolorbarrO   _adjust_cbar)	rF   elementr	   redrawrL   r&   rO   r9   rP   s	            rJ   _draw_colorbarzPlot3D._draw_colorbar]   s   ?inG!!(D11l5!\&!c8$$ 	 -C;t]++ /++D,<==++A..C++ 	-'',,C ||F32|66#V"gU$s+++++    )NNT)__name__
__module____qualname____doc__paramIntegerr0   r/   r1   Booleanr?   StringrB   ListlabelledObjectSelector
projectionr-   r5   r;   r=   rE   r_   __classcell__)rI   s   @rJ   r   r      s        
 emC B+ , , ,G b @* + + +I u}R >- . . .H !5= 5   L el7 1) * * *G uz/// 88 9 9 9H &%dTF I2 3 3 3J d 11 2 2 2I !E *14 ?34 4 4E !E *14 ?34 4 4E !E *14 ?34 4 4E 5  5  5  5  5D, , , , , , , ,r`   r   c                       e Zd ZdZ ej        deefdd          Z ej        deefdd          Z	 e
d          Zd	 Zd
 ZdS )Scatter3DPlotz
    Subclass of PointPlot allowing plotting of Points
    on a 3D axis, also allows mapping color and size
    onto a particular Dimension of the data.
    NTzA
      Index of the dimension from which the color will the drawn)r   class_
allow_Noner   zB
      Index of the dimension from which the sizes will the drawn.scattersinglec                 V   fdt          d          D             \  }}}|                     ||           t                      5  |                     ||          }d d d            n# 1 swxY w Y   |                    d          dk    r|                    d           |||f|i fS )Nc              3   B   K   | ]}                     |          V  d S Ndimension_values).0ir]   s     rJ   	<genexpr>z)Scatter3DPlot.get_data.<locals>.<genexpr>   s1      DDag..q11DDDDDDr`   r   
edgecolorsnone)range_compute_stylesr   _apply_transformsrT   pop)rF   r]   rangesstylexsyszss    `     rJ   get_datazScatter3DPlot.get_data   s   DDDD588DDD
BWfe444"$$ 	C 	C**7FEBBE	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C99\""f,,IIl###B|UB&&s   A**A.1A.c                    | j         d         }|                     |||          \  |_        }}|                    | j                  }|rLd|v rH|d         |d         f}	t          j        |d                   }
t          |d         |	|
d          |_        |                    | j	                  r|
                    |d                    d S d S )	NrL   cmapvminvmaxcF)hexs)r*   r   
_offsets3drY   rM   r   get_cmapr   _facecolor3d
size_index	set_sizes)rF   rG   r%   r]   r   r   rL   _cdimclimr   s              rJ   update_handleszScatter3DPlot.update_handles   s    h'&*mmGVU&K&K#5!$$T%566 	PFeOO=%-/D;uV}--D",U3Zt"O"O"OF  11 	)U3Z(((((	) 	)r`   )ra   rb   rc   rd   re   ClassSelectorstrintrM   r   dict_plot_methodsr   r    r`   rJ   ro   ro   v   s          &%%dC:15 <DE E EK %$T3*04 ;EF F FJ D	***M' ' '	) 	) 	) 	) 	)r`   ro   c                   ,    e Zd ZdZg dZd Zd Zd ZdS )
Path3DPlotz-
    Allows plotting paths on a 3D axis.
    )alphacolor	linestyle	linewidthvisibler   c                    |                     d|j                  }| j        rd |D             }t                      5  |                     |||          }d d d            n# 1 swxY w Y   d|v r|                    d          |d<   t          |                    d          t          j	                  r|                    d          |d<   d|v r/|                    dd           |                    dd           f|d	<   |f|i fS )
Narray)datatype
dimensionsc                 ,    g | ]}|d d d d df         S )Nr   )rz   ps     rJ   
<listcomp>z'Path3DPlot.get_data.<locals>.<listcomp>   s*    ///AQqqq$$B$wZ///r`   r   r   colorsr   r   r   )
splitkdimsinvert_axesr   r   r   rU   rT   npndarray)rF   r]   r   r   pathss        rJ   r   zPath3DPlot.get_data   sS   w7=II 	0/////E"$$ 	C 	C**7FEBBE	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C%<<"YYs^^E'Neii(("*55 	1#ii00E(OU??!IIfd33UYYvt5L5LLE&Mx""s   A""A&)A&c                 L    t          |i |}|                    |           d|iS )NrL   )r   add_collection)rF   rO   	plot_argsplot_kwargsline_segmentss        rJ   init_artistszPath3DPlot.init_artists   s3    ()C{CC
-(((-((r`   c                 8    t          j        | |||||           d S rw   )r   r   )rF   rG   r%   r]   r   r   s         rJ   r   zPath3DPlot.update_handles   s#    c4&%HHHHHr`   N)ra   rb   rc   rd   
style_optsr   r   r   r   r`   rJ   r   r      s^          QPPJ# # #) ) )
I I I I Ir`   r   c                   t    e Zd ZdZ ej        dd          Z ej        dg dd          Zg d	Z	d
 Z
d ZdS )SurfacePlotz
    Plots surfaces wireframes and contours in 3D space.
    Provides options to switch the display type via the
    plot_type parameter has support for a number of
    styling options including strides and colors.
    F/
        Whether to add a colorbar to the plot.r   surface)r   	wireframecontourz
        Specifies the type of visualization for the Surface object.
        Valid values are 'surface', 'wireframe' and 'contour'.r!   )antialiasedr   r   shader   
facecolorsrstridecstridenorm	edgecolorrcountccountc                     | j         dk    r |j        |i |}n1| j         dk    r |j        |i |}n| j         dk    r |j        |i |}d|iS )Nr   r   r   rL   )	plot_typeplot_wireframeplot_surface	contour3D)rF   rO   	plot_datar   rL   s        rJ   r   zSurfacePlot.init_artists   s{    >[((&R&	A[AAFF^y(($R_i?;??FF^y((!R\9<<<F&!!r`   c                                         dd          }t          j                            |t          j        t          j        |                              }fdj        D             }| j        r|d d d         }|j        }||gz   }| j	        dk    r'd|v r#| 
                    ||j        d	                    ||i fS )
Nr
   F)flat)maskc                 L    g | ] }j                             |d d           !S )T)orderedexpanded)	interfacecoordsrz   dr]   s     rJ   r   z(SurfacePlot.get_data.<locals>.<listcomp>   sJ     * * * #**7At48 + : : * * *r`   r   r   r   r   )ry   r   mar   logical_notisfiniter   r   Tr   _norm_kwargsvdims)rF   r]   r   r   zdatadatar   
cmesh_datas    `      rJ   r   zSurfacePlot.get_data   s    (((77u{{5r~bk%6H6H'I'I{JJ* * * *"=* * *  	DDbD\F6Dtf_
>[((Vu__gvugmA6FGGG5"$$r`   N)ra   rb   rc   rd   re   rg   r[   rk   r   r   r   r   r   r`   rJ   r   r      s          u}U 12 3 3 3H %$Y.9 .9 .9?BC C CI; ; ;J" " "% % % % %r`   r   c                   \    e Zd ZdZ ej        dd          Zg dZ ed          Z	d Z
d	S )
TriSurfacePlotz_
    Plots a trisurface given a TriSurface element, containing
    X, Y and Z coordinates.
    Fr   r   )r   r   r   r   r   r   plot_trisurfrs   c                                                      }|                     |||d                    fd|D             \  }}}|||f|i fS )Nr
   c              3   B   K   | ]}                     |          V  d S rw   rx   r   s     rJ   r|   z*TriSurfacePlot.get_data.<locals>.<genexpr>   s1      ==17++A..======r`   )r   r   )rF   r]   r   r   dimsr   r   r   s    `      rJ   r   zTriSurfacePlot.get_data   sd    !!##'65$q':::=======1a1ay%##r`   N)ra   rb   rc   rd   re   rg   r[   r   r   r   r   r   r`   rJ   r   r      ss         
 u}U 12 3 3 3H  J D///M$ $ $ $ $r`   r   )numpyr   re   
matplotlibr   mpl_toolkits.mplot3d.art3dr   packaging.versionr   corer   core.optionsr   util.transformr	   rV   utilr   chartr   r]   r   pathr   r   r   ro   r   r   r   r   r`   rJ   <module>r      s              7 7 7 7 7 7 % % % % % %       1 1 1 1 1 1 - - - - - -             ! ! ! ! ! !            a, a, a, a, a,\ a, a, a,J#) #) #) #) #)FI #) #) #)LI I I I I I I I@+% +% +% +% +%& +% +% +%^$ $ $ $ $V $ $ $ $ $r`   