
    ~i(                         d dl mZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZ  ej        d          Zd Z	 	 	 	 	 	 	 dd
Zd Zd Z G d de          ZdS )    N)
exceptionsoptional_imports)utils)
graph_objs)ValidatorCachenumpyc                    |t          |t                    rtt          j        | |           t	          t          |                     D ]B}t          | |                   t          ||                   k    rt          j        d          C|r:t          |          t          | d                   k    rt          j        d          |r4t          |          t          |           k    rt          j        d          dS dS )a(  
    Annotated-heatmap-specific validations

    Check that if a text matrix is supplied, it has the same
    dimensions as the z matrix.

    See FigureFactory.create_annotated_heatmap() for params

    :raises: (PlotlyError) If z and text matrices do not  have the same
        dimensions.
    Nz*z and text should have the same dimensionsr   zMoops, the x list that you provided does not match the width of your z matrix zNoops, the y list that you provided does not match the length of your z matrix )
isinstancelistr   validate_equal_lengthrangelenr   PlotlyError)zxyannotation_textlsts        \/home/jrussi/.local/lib/python3.11/site-packages/plotly/figure_factory/_annotated_heatmap.pyvalidate_annotated_heatmapr      s    "z/4'H'H"#A777Q== 	 	C1S6{{c/#"67777 ,@   8
 	 q66S1YY(*   	 q66SVV(+       PlasmaFc                 $   ||ng }t          | |||           t          j        dd          }	|	                    |          }t	          | ||||||fi |                                }
|s|rHt          dd| |||||d|}t          |
t          dddd	          t          ddd
                    }nEt          dd| |||d|}t          |
t          dddd          t          dd
d                    }|g}t          j        ||          S )a  
    **deprecated**, use instead
    :func:`plotly.express.imshow`.

    Function that creates annotated heatmaps

    This function adds annotations to each cell of the heatmap.

    :param (list[list]|ndarray) z: z matrix to create heatmap.
    :param (list) x: x axis labels.
    :param (list) y: y axis labels.
    :param (list[list]|ndarray) annotation_text: Text strings for
        annotations. Should have the same dimensions as the z matrix. If no
        text is added, the values of the z matrix are annotated. Default =
        z matrix values.
    :param (list|str) colorscale: heatmap colorscale.
    :param (list) font_colors: List of two color strings: [min_text_color,
        max_text_color] where min_text_color is applied to annotations for
        heatmap values < (max_value - min_value)/2. If font_colors is not
        defined, the colors are defined logically as black or white
        depending on the heatmap's colorscale.
    :param (bool) showscale: Display colorscale. Default = False
    :param (bool) reversescale: Reverse colorscale. Default = False
    :param kwargs: kwargs passed through plotly.graph_objs.Heatmap.
        These kwargs describe other attributes about the annotated Heatmap
        trace such as the colorscale. For more information on valid kwargs
        call help(plotly.graph_objs.Heatmap)

    Example 1: Simple annotated heatmap with default configuration

    >>> import plotly.figure_factory as ff

    >>> z = [[0.300000, 0.00000, 0.65, 0.300000],
    ...      [1, 0.100005, 0.45, 0.4300],
    ...      [0.300000, 0.00000, 0.65, 0.300000],
    ...      [1, 0.100005, 0.45, 0.00000]]

    >>> fig = ff.create_annotated_heatmap(z)
    >>> fig.show()
    Nheatmap
colorscale)typer   r   r   r   	showscalereversescale    topzrgb(0, 0, 0))ticksdtickside	gridcolorz  )r"   r#   
ticksuffix)annotationsxaxisyaxis)r   r   r   r   r   F)r"   r$   r%   showticklabels)r"   r&   r*   )datalayout )	r   r   get_validatorvalidate_coerce_AnnotatedHeatmapmake_annotationsdictr   Figure)r   r   r   r   r   font_colorsr   r   kwargscolorscale_validatorr'   tracer,   r+   s                 r   create_annotated_heatmapr8   0   s   j "-!8++bKq!Q888 *7	<PP%55jAAJ#	1a*k< KQ   	 
A 
 	
!%	
 	
 	
 	
 #RquOOORqT:::
 
 
  
!%
 
 
 
 #uu   RDGGG
 
 
 7D$v6666r   c                    |                                  } |                     d          r2d |                      d                              d          D             S |                     d          rt          j        |           S |S )Nrgbc                 ,    g | ]}t          |          S r-   )int).0vs     r   
<listcomp>z%to_rgb_color_list.<locals>.<listcomp>   s    EEE1AEEEr   zrgba(),#)strip
startswithsplitclrs
hex_to_rgb)	color_strdefaults     r   to_rgb_color_listrI      s    !!IE"" EE	 9 9 ? ? D DEEEE			c	"	" y)))r   c                 P    | d         dz  | d         dz  z   | d         dz  z   dk    S )Nr   gA`"?r    gbX9?   gv/?   r-   )background_colors    r   should_use_black_textrN      sB    e#
1

%	&
1

%	& 		 r   c                   $    e Zd ZdZd Zd Zd ZdS )r0   zH
    Refer to TraceFactory.create_annotated_heatmap() for docstring
    c                    || _         |r|| _        n't          t          |d                             | _        |r|| _        n!t          t          |                    | _        ||| _        n| j         | _        || _        || _        || _        t          rht          | j         t          j                  rIt                              | j                   | _        t                              | j                   | _        nFt!          d | j         D                       | _        t#          d | j         D                       | _        |                    dd           |d         | _        |                    dd           |d         | _        | j        | j        z   dz  | _        |                    dd           |d         | _        d S d S )Nr   c                     g | ]	}|D ]}|
S r-   r-   r=   rowr>   s      r   r?   z._AnnotatedHeatmap.__init__.<locals>.<listcomp>   %    >>>3#>>QQ>>>>r   c                     g | ]	}|D ]}|
S r-   r-   rR   s      r   r?   z._AnnotatedHeatmap.__init__.<locals>.<listcomp>   rT   r   zminzmaxrK   zmid)r   r   r   r   r   r   r   r   r4   npr
   ndarrayaminrV   amaxrW   minmaxgetrX   )	selfr   r   r   r   r   r4   r   r5   s	            r   __init__z_AnnotatedHeatmap.__init__   s     	&DFF3qt99%%DF 	#DFF3q66]]DF&#2D  #'6D $(& 	@*TVRZ00 	@DIDII>>$&>>>??DI>>$&>>>??DI::fd##/vDI::fd##/vDIY*a/	::fd##/vDIII 0/r   c                     g d}dg}d}d}| j         r| j         d         }| j         d         }n| j        |v r| j        r|}|}n| j        |v r|}|}n| j        |v r| j        r|}|}n| j        |v r|}|}nt          | j        t                    rzt          | j        d         d         g d          }t          | j        d         d         g d          }| j        r||}}t          |          r|}n|}t          |          r|}n|}n|}|}||fS )	a  
        Get font color for annotations.

        The annotated heatmap can feature two text colors: min_text_color and
        max_text_color. The min_text_color is applied to annotations for
        heatmap values < (max_value - min_value)/2. The user can define these
        two colors. Otherwise the colors are defined logically as black or
        white depending on the heatmap's colorscale.

        :rtype (string, string) min_text_color, max_text_color: text
            color for annotations for heatmap values <
            (max_value - min_value)/2 and text color for annotations for
            heatmap values >= (max_value - min_value)/2
        )GreysGreensBluesYIGnBuYIOrRdRdBuPicnicJetHot	BlackbodyEarthElectricViridisCividisRedsz#FFFFFFz#000000r   r    )   rs   rs   )r4   r   r   r
   r   rI   rN   )	r`   colorscalescolorscales_reversewhiteblackmin_text_colormax_text_colormin_colmax_cols	            r   get_text_colorz _AnnotatedHeatmap.get_text_color   s{    
 
 
"  &h "	#!-a0N!-b1NN_++0A+"N"NN_++"N"NN_ 3338I3"N"NN_ 333"N"NN.. 	#'(:1(=OOG'(;A(>PPG   4#*G$W-- '!&!&$W-- '!&!&"N"N~--r   c                    t                               |           \  }}g }t          | j                  D ]\  }}t          |          D ]\  }}|| j        k     r|n|}|                    t          j                            t          | j
        |         |                   | j        |         | j        |         ddt          |          d                     |S )z
        Get annotations for each cell of the heatmap with graph_objs.Annotation

        :rtype (list[dict]) annotations: list of annotations for each cell of
            the heatmap
        x1y1)colorF)textr   r   xrefyreffont	showarrow)r0   r|   	enumerater   rX   appendr   r,   
Annotationstrr   r   r   r2   )	r`   rx   ry   r'   nrS   mval
font_colors	            r   r1   z"_AnnotatedHeatmap.make_annotations  s     *;)I)I$)O)O&'' 	 	FAs#C..  3/2TY^^N
""%00 !5a!8!;<<&)&)!!!
333"' 1  
 
 
 
 r   N)__name__
__module____qualname____doc__ra   r|   r1   r-   r   r   r0   r0      sP         #' #' #'JH. H. H.T    r   r0   )NNNr   NFF)plotly.colorscolorsrE   plotlyr   r   plotly.figure_factoryr   plotly.graph_objsr   plotly.validator_cacher   
get_modulerY   r   r8   rI   rN   objectr0   r-   r   r   <module>r      s         / / / / / / / / ' ' ' ' ' ' ( ( ( ( ( ( 1 1 1 1 1 1 ! ))" " "N 
c7 c7 c7 c7L    K K K K K K K K K Kr   