
    6DhA                         S SK JrJr  S SKJr  S SKJr  \R                  " S5      r	S r
       SS jr              S	S jrg)
    )
exceptionsoptional_importsN)
graph_objsnumpyc                    X4:  a  [         R                  " S5      e[        U5      S:X  a3  US   n[        R                  " U5      n[        R
                  " U5      nU$ X:X  a3  US   n[        R                  " U5      n[        R
                  " U5      nU$ Uc  X-
  [        XC-
  5      -  n[        US[        U5      S-
  -  -  5      n[        R                  " X   XS-      U[        U5      S-
  -  U-
  5      n[        R                  " U5      n[        R
                  " U5      nU$ X-
  [        XC-
  5      -  nSn[        [        U5      S-
  5       H!  nX(   Us=::  a  X(S-      :  a  O  O  O	US-  nM#     X'   n	X'S-      n
[        R                  " X   XS-      Xi-
  X-
  -  5      n[        R                  " U5      n[        R
                  " U5      nU$ )a6  
Normalize facecolor values by vmin/vmax and return rgb-color strings

This function takes a tuple color along with a colormap and a minimum
(vmin) and maximum (vmax) range of possible mean distances for the
given parametrized surface. It returns an rgb color based on the mean
distance between vmin and vmax

zmIncorrect relation between vmin and vmax. The vmin value cannot be bigger than or equal to the value of vmax.   r   g      ?)
r   PlotlyErrorlenclrsconvert_to_RGB_255	label_rgbfloatintfind_intermediate_colorrange)facecolormapscalevminvmax
face_colortlow_color_indexklow_scale_valhigh_scale_vals              P/var/www/html/env/lib/python3.13/site-packages/plotly/figure_factory/_trisurf.pymap_face2colorr      s    |$$
 	
 8}a[
,,Z8
^^J/
|b\
,,Z8
^^J/
= t{ 44A!!sc(ma.?'@"ABO55)1,-S]Q&'/9J 00<J
3J, ' t{ 44AO3u:>*8q/5Q</1$ +
 "2M"Q#67N55)1,-"~'EFJ 00<J
3J    c                    [         (       d  [        S5      e[         R                  XU45      R                  n[         R	                  U5      nX   nUc  USS2SS2S4   R                  S5      nGO[        U[        [         R                  45      (       a  [        U5      [        U5      :w  a  [        S5      e[        [        U5      5       H  n[        UU   [        5      (       a;  SUU   ;   a2  [        R                  " UU   5      n[        R                  " U5      UU'   [        UU   [         5      (       d  Mp  [        R"                  " UU   5      n[        R                  " U5      UU'   M     [         R%                  U5      nOs/ nU HV  n/ nU H'  nU" US   US   US   5      nUR'                  U5        M)     UR'                  [         R                  U5      5        MX     [         R%                  U5      n[        US   [        5      (       a  UnOl[         R)                  U5      n[         R+                  U5      nUc  / n[        [        U5      5       H%  n[-        UU   XvUU5      nUR'                  U5        M'     [         R%                  U5      nUR                  u  nnn[.        R0                  " XX-UUUS	S
9n[        US   [        5      (       + nU(       a`  USL a[  [        R2                  " Xv5      n[        R4                  " U5      n[.        R6                  " U SS USS USS S[9        SWW/USS9SSS9n U	SL a  U(       a	  USL a  UW /$ U/$ XU4 Vs/ s H  nUSL PM	     n!n[;        U!5      (       a!  [=        U!5      (       d  [        S5      e/ n
/ n/ n/ SQn"USS2U"SS24   n#[         R?                  U#SS2SS2S4   [         RA                  SU#RB                  S   S/5      /5      n$[         R?                  U#SS2SS2S4   [         RA                  SU#RB                  S   S/5      /5      n%[         R?                  U#SS2SS2S4   [         RA                  SU#RB                  S   S/5      /5      n&[         R?                  U
U$RE                  SS/5      S   /5      n
[         R?                  UU%RE                  SS/5      S   /5      n[         R?                  UU&RE                  SS/5      S   /5      n[        U
5      [        U5      s=:X  a  [        U5      :X  d  O  [F        RH                  " S5      e[.        R6                  " U
UUS[.        RJ                  RM                  USS9SS9n'U(       a
  USL a  UU'W /$ UU'/$ s  snf )z7
Refer to FigureFactory.create_trisurf() for docstring
z1FigureFactory._trisurf() requires numpy imported.N   r	   zGIf color_func is a list/array, it must be the same length as simplices.#r   r    )xyz	facecolorijr   nameTmarkersg?)sizecolor
colorscale	showscalenoneF)r%   r&   r'   modemarker	hoverinfo
showlegendz9If any (x_edge, y_edge, z_edge) is None, all must be None)r   r   r"   r   z:The lengths of x_edge, y_edge and z_edge are not the same.linesg      ?)r.   width)r%   r&   r'   r2   liner5   )'npImportErrorvstackT
atleast_2dmean
isinstancelistndarrayr   
ValueErrorr   strr   
hex_to_rgbr   tupler   asarrayappendminmaxr   r   Mesh3dmake_colorscaleconvert_colorscale_to_rgb	Scatter3ddictanyallhstacktileshapereshaper   r
   	scatter3dLine)(r%   r&   r'   	simplicesshow_colorbaredges_colorr   r   
color_func
plot_edgesx_edgey_edgez_edger(   points3Dtri_vertices
mean_distsindexfootriangledistsvertexdistmin_mean_distsmax_mean_distsr.   iijjkk	trianglesmean_dists_are_numbersr/   colorbaris_noneixs_triangles
pull_edgesx_edge_pully_edge_pullz_edge_pullr6   s(                                           r   trisurfrv   L   sL   ( 2PQQyy!#%%Hi(I &L !!Q'*//3
	Jrzz 2	3	3z?c)n,3  3z?+E*U+S11*U++//*U*;<C(,s(;Ju%*U+U33--j.?@$(NN3$7
5! , ZZ
+
 
$HE"!&)VAYq	BT" # bggen- % ZZ
+
 *Q-%%	
+
+I3z?+E"5!8NNE U#	 , 

9%IJBB!!
AbB"2I ",JqM3!??-4"7))(:
33J?
''eee%~6%	 
  U!mt&;x((;
 &,V$<=$<brTz$<G=
7||7||N  FFF !Ma12J))	Aq!G	bggdZ-=-=a-@!,DEFK ))	Aq!G	bggdZ-=-=a-@!,DEFK ))	Aq!G	bggdZ-=-=a-@!,DEFK
 YY 3 3QG <Q ?@AFYY 3 3QG <Q ?@AFYY 3 3QG <Q ?@AFK3v;5#f+5$$K
 	

   


!!&&[&DE -4"75(++5!!_ >s   Vc                 V   Uc  SSSS.n[         R                  " U5        [         R                  " USSUS9u  pF[        U UUUUUUUUU	S9
n[	        U
UUUS9n[
        R                  " UUU[
        R                  R                  [
        R                  R                  R                  " S0 UD6[
        R                  R                  R                  " S0 UD6[
        R                  R                  R                  " S0 UD6[	        US   US	   US
   S9S9S9n[
        R                  " UUS9$ )a  
Returns figure for a triangulated surface plot

:param (array) x: data values of x in a 1D array
:param (array) y: data values of y in a 1D array
:param (array) z: data values of z in a 1D array
:param (array) simplices: an array of shape (ntri, 3) where ntri is
    the number of triangles in the triangularization. Each row of the
    array contains the indicies of the verticies of each triangle
:param (str|tuple|list) colormap: either a plotly scale name, an rgb
    or hex color, a color tuple or a list of colors. An rgb color is
    of the form 'rgb(x, y, z)' where x, y, z belong to the interval
    [0, 255] and a color tuple is a tuple of the form (a, b, c) where
    a, b and c belong to [0, 1]. If colormap is a list, it must
    contain the valid color types aforementioned as its members
:param (bool) show_colorbar: determines if colorbar is visible
:param (list|array) scale: sets the scale values to be used if a non-
    linearly interpolated colormap is desired. If left as None, a
    linear interpolation between the colors will be excecuted
:param (function|list) color_func: The parameter that determines the
    coloring of the surface. Takes either a function with 3 arguments
    x, y, z or a list/array of color values the same length as
    simplices. If None, coloring will only depend on the z axis
:param (str) title: title of the plot
:param (bool) plot_edges: determines if the triangles on the trisurf
    are visible
:param (bool) showbackground: makes background in plot visible
:param (str) backgroundcolor: color of background. Takes a string of
    the form 'rgb(x,y,z)' x,y,z are between 0 and 255 inclusive
:param (str) gridcolor: color of the gridlines besides the axes. Takes
    a string of the form 'rgb(x,y,z)' x,y,z are between 0 and 255
    inclusive
:param (str) zerolinecolor: color of the axes. Takes a string of the
    form 'rgb(x,y,z)' x,y,z are between 0 and 255 inclusive
:param (str) edges_color: color of the edges, if plot_edges is True
:param (int|float) height: the height of the plot (in pixels)
:param (int|float) width: the width of the plot (in pixels)
:param (dict) aspectratio: a dictionary of the aspect ratio values for
    the x, y and z axes. 'x', 'y' and 'z' take (int|float) values

Example 1: Sphere

>>> # Necessary Imports for Trisurf
>>> import numpy as np
>>> from scipy.spatial import Delaunay

>>> from plotly.figure_factory import create_trisurf
>>> from plotly.graph_objs import graph_objs

>>> # Make data for plot
>>> u = np.linspace(0, 2*np.pi, 20)
>>> v = np.linspace(0, np.pi, 20)
>>> u,v = np.meshgrid(u,v)
>>> u = u.flatten()
>>> v = v.flatten()

>>> x = np.sin(v)*np.cos(u)
>>> y = np.sin(v)*np.sin(u)
>>> z = np.cos(v)

>>> points2D = np.vstack([u,v]).T
>>> tri = Delaunay(points2D)
>>> simplices = tri.simplices

>>> # Create a figure
>>> fig1 = create_trisurf(x=x, y=y, z=z, colormap="Rainbow",
...                       simplices=simplices)

Example 2: Torus

>>> # Necessary Imports for Trisurf
>>> import numpy as np
>>> from scipy.spatial import Delaunay

>>> from plotly.figure_factory import create_trisurf
>>> from plotly.graph_objs import graph_objs

>>> # Make data for plot
>>> u = np.linspace(0, 2*np.pi, 20)
>>> v = np.linspace(0, 2*np.pi, 20)
>>> u,v = np.meshgrid(u,v)
>>> u = u.flatten()
>>> v = v.flatten()

>>> x = (3 + (np.cos(v)))*np.cos(u)
>>> y = (3 + (np.cos(v)))*np.sin(u)
>>> z = np.sin(v)

>>> points2D = np.vstack([u,v]).T
>>> tri = Delaunay(points2D)
>>> simplices = tri.simplices

>>> # Create a figure
>>> fig1 = create_trisurf(x=x, y=y, z=z, colormap="Viridis",
...                       simplices=simplices)

Example 3: Mobius Band

>>> # Necessary Imports for Trisurf
>>> import numpy as np
>>> from scipy.spatial import Delaunay

>>> from plotly.figure_factory import create_trisurf
>>> from plotly.graph_objs import graph_objs

>>> # Make data for plot
>>> u = np.linspace(0, 2*np.pi, 24)
>>> v = np.linspace(-1, 1, 8)
>>> u,v = np.meshgrid(u,v)
>>> u = u.flatten()
>>> v = v.flatten()

>>> tp = 1 + 0.5*v*np.cos(u/2.)
>>> x = tp*np.cos(u)
>>> y = tp*np.sin(u)
>>> z = 0.5*v*np.sin(u/2.)

>>> points2D = np.vstack([u,v]).T
>>> tri = Delaunay(points2D)
>>> simplices = tri.simplices

>>> # Create a figure
>>> fig1 = create_trisurf(x=x, y=y, z=z, colormap=[(0.2, 0.4, 0.6), (1, 1, 1)],
...                       simplices=simplices)

Example 4: Using a Custom Colormap Function with Light Cone

>>> # Necessary Imports for Trisurf
>>> import numpy as np
>>> from scipy.spatial import Delaunay

>>> from plotly.figure_factory import create_trisurf
>>> from plotly.graph_objs import graph_objs

>>> # Make data for plot
>>> u=np.linspace(-np.pi, np.pi, 30)
>>> v=np.linspace(-np.pi, np.pi, 30)
>>> u,v=np.meshgrid(u,v)
>>> u=u.flatten()
>>> v=v.flatten()

>>> x = u
>>> y = u*np.cos(v)
>>> z = u*np.sin(v)

>>> points2D = np.vstack([u,v]).T
>>> tri = Delaunay(points2D)
>>> simplices = tri.simplices

>>> # Define distance function
>>> def dist_origin(x, y, z):
...     return np.sqrt((1.0 * x)**2 + (1.0 * y)**2 + (1.0 * z)**2)

>>> # Create a figure
>>> fig1 = create_trisurf(x=x, y=y, z=z,
...                       colormap=['#FFFFFF', '#E4FFFE',
...                                 '#A4F6F9', '#FF99FE',
...                                 '#BA52ED'],
...                       scale=[0, 0.6, 0.71, 0.89, 1],
...                       simplices=simplices,
...                       color_func=dist_origin)

Example 5: Enter color_func as a list of colors

>>> # Necessary Imports for Trisurf
>>> import numpy as np
>>> from scipy.spatial import Delaunay
>>> import random

>>> from plotly.figure_factory import create_trisurf
>>> from plotly.graph_objs import graph_objs

>>> # Make data for plot
>>> u=np.linspace(-np.pi, np.pi, 30)
>>> v=np.linspace(-np.pi, np.pi, 30)
>>> u,v=np.meshgrid(u,v)
>>> u=u.flatten()
>>> v=v.flatten()

>>> x = u
>>> y = u*np.cos(v)
>>> z = u*np.sin(v)

>>> points2D = np.vstack([u,v]).T
>>> tri = Delaunay(points2D)
>>> simplices = tri.simplices


>>> colors = []
>>> color_choices = ['rgb(0, 0, 0)', '#6c4774', '#d6c7dd']

>>> for index in range(len(simplices)):
...     colors.append(random.choice(color_choices))

>>> fig = create_trisurf(
...     x, y, z, simplices,
...     color_func=colors,
...     show_colorbar=True,
...     edges_color='rgb(2, 85, 180)',
...     title=' Modern Art'
... )
r   )r%   r&   r'   rE   T)	colortypereturn_default_colorsr   )rX   rZ   r   r   rY   r[   )showbackgroundbackgroundcolor	gridcolorzerolinecolorr%   r&   r'   )xaxisyaxiszaxisaspectratio)titler7   heightscene)datalayout )r   validate_colorsconvert_colors_to_same_typerv   rN   r   Layoutr   Scener   XAxisYAxisZAxisFigure)r%   r&   r'   rW   r   rX   r   rZ   r   r[   rz   r{   r|   r}   rY   r   r7   r   data1axisr   s                        r   create_trisurfr      sB   | AA. 	"66G4uOH 			#E %'#	D %%##))//7$7##))//7$7##))//7$7c"k#&6+c:J	 & 
	F %77r    )NNFNNNN)NTNNzTrisurf PlotTTzrgb(230, 230, 230)rgb(255, 255, 255)r   zrgb(50, 50, 50)   r   N)plotlyr   r   plotly.colorscolorsr   plotly.graph_objsr   
get_moduler9   r   rv   r   r   r    r   <module>r      su    /  (  )AX f"\ 

("&!
%H8r    