Ë
    ªehù¸  ã                   óŒ  — d 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
ZddlZ	 ddlmZ dZdd	lmZ dd
lmZ ddlmZ ddlmZmZmZmZmZ ddgZd„ Zd„ Z d„ Z!d„ Z" G d„ d«      Z#dddddddddddddddddddœd„Z$ G d„ d«      Z%dddddddddœd„Z& G d „ d!e«      Z'dddddd"ddddddddd#d$d%dd&œd'„Z(y# e$ r dZY Œ”w xY w)(z(Functions to visualize matrices of data.é    N)ÚLineCollection)Úgridspec)Ú	hierarchyFTé   )Úcm)ÚGrid)Úget_colormap)ÚdespineÚaxis_ticklabels_overlapÚrelative_luminanceÚto_utf8Ú_draw_figureÚheatmapÚ
clustermapc                 ó    — t        | t        j                  «      r)dj                  t	        t
        | j                  «      «      S | j                  S )z6Convert a pandas index or multiindex to an axis label.ú-)Ú
isinstanceÚpdÚ
MultiIndexÚjoinÚmapr   ÚnamesÚname)Úindexs    úL/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/seaborn/matrix.pyÚ_index_to_labelr      s4   € ä�%œŸ™Ô'Ø�x‰xœœG U§[¡[Ó1Ó2Ð2à�z‰zÐó    c           	      óÆ   — t        | t        j                  «      r7| j                  D �cg c]!  }dj	                  t        t        |«      «      ‘Œ# c}S | j                  S c c}w )z5Convert a pandas index or multiindex into ticklabels.r   )r   r   r   Úvaluesr   r   r   )r   Úis     r   Ú_index_to_ticklabelsr!   '   sD   € ä�%œŸ™Ô'Ø38·<±<Ö@¨a�—‘œœW a›Õ)Ò@Ð@à�|‰|Ðùò As   ©&Ac           
      óè   — t         j                  j                  }	  || d   «       t        t	        || «      «      S # t
        $ r, | D �cg c]  }t        t	        ||«      «      ‘Œ nc c}w c}cY S w xY w)zAConvert either a list of colors or nested lists of colors to RGB.r   )ÚmplÚcolorsÚto_rgbÚlistr   Ú
ValueError)r$   r%   Ú
color_lists      r   Ú_convert_colorsr)   /   sf   € ä�Z‰Z×Ñ€FðHÙˆv�a‰yÔä”C˜ Ó'Ó(Ð(øÜò Hà@FÖG°*””S˜ Ó,Õ-ÑGùÔGÒGðHús   œ< ¼A1Á	A&Á%	A1Á0A1c                 óD  — |€$t        j                  | j                  t        «      }t	        |t         j
                  «      rV|j                  | j                  k7  rt        d«      ‚t        j                  || j                  | j                  t        ¬«      }nqt	        |t        j                  «      rW|j                  j                  | j                  «      s2|j                  j                  | j                  «      rd}t        |«      ‚|t        j                  | «      z  }|S )zãEnsure that data and mask are compatible and add missing values.

    Values will be plotted for cells where ``mask`` is ``False``.

    ``data`` is expected to be a DataFrame; ``mask`` can be an array or
    a DataFrame.

    z&Mask must have the same shape as data.)r   ÚcolumnsÚdtypez2Mask must have the same index and columns as data.)ÚnpÚzerosÚshapeÚboolr   Úndarrayr'   r   Ú	DataFramer   r+   ÚequalsÚisnull)ÚdataÚmaskÚerrs      r   Ú_matrix_maskr8   <   sÌ   € ð €|Ü�x‰x˜Ÿ
™
¤DÓ)ˆä�$œŸ
™
Ô#à�:‰:˜Ÿ™Ò#ÜÐEÓFÐFä�|‰|˜DØ"&§*¡*Ø$(§L¡LÜ"&ô(‰ô
 
�Dœ"Ÿ,™,Ô	'à�z‰z× Ñ  §¡Ô,Ø�|‰|×"Ñ" 4§<¡<Ô0ØFˆCÜ˜S“/Ð!ð
 ”"—)‘)˜D“/Ñ!€Dà€Kr   c                   ó8   — e Zd ZdZ	 d	d„Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)
Ú_HeatMapperz?Draw a heatmap plot of a matrix with nice labels and colormaps.Nc                 ó2  — t        |t        j                  «      r|j                  }n*t	        j
                  |«      }t        j                  |«      }t        ||«      }t        j                  j                  t	        j
                  |«      |«      }d}t        |t        «      r|}t        |j                  «      }n |du rt        |j                  «      }n|du rg }d}t        |t        «      r|}t        |j                  «      }n |du rt        |j                  «      }n|du rg }t        |«      sg | _        g | _        nVt        |t         «      r'|dk(  r"d| _        t        |j                  «      | _        n| j#                  ||«      \  | _        | _        t        |«      sg | _        g | _        nVt        |t         «      r'|dk(  r"d| _        t        |j                  «      | _        n| j#                  ||«      \  | _        | _        t)        |j                  «      }t)        |j                  «      }|�|nd| _        |�|nd| _        | j/                  ||||||«       |�|du rd}d}nPt        |t0        «      r|}n;t	        j
                  |«      }|j2                  |j2                  k7  rd}t5        |«      ‚d}|| _        || _        || _        || _        || _        |	€i n|	jA                  «       | _!        |
| _"        |€i | _#        y|jA                  «       | _#        y)zInitialize the plotting object.r   TFÚautoNÚ ú(`data` and `annot` must have same shape.)$r   r   r2   r   r-   Úasarrayr8   ÚmaÚmasked_whereÚintr!   r+   r   ÚlenÚxticksÚxticklabelsÚstrÚ_skip_ticksÚyticksÚyticklabelsr   ÚxlabelÚylabelÚ_determine_cmap_paramsr0   r/   r'   r5   Ú	plot_dataÚannotÚ
annot_dataÚfmtÚcopyÚ	annot_kwsÚcbarÚcbar_kws)Úselfr5   ÚvminÚvmaxÚcmapÚcenterÚrobustrN   rP   rR   rS   rT   rE   rI   r6   rM   Ú
xtickeveryÚ
ytickeveryrJ   rK   rO   r7   s                         r   Ú__init__z_HeatMapper.__init__d   s¼  € ô �dœBŸL™LÔ)ØŸ™‰IäŸ
™
 4Ó(ˆIÜ—<‘< 	Ó*ˆDô ˜D $Ó'ˆä—E‘E×&Ñ&¤r§z¡z°$Ó'7¸ÓCˆ	ð ˆ
Ü�k¤3Ô'Ø$ˆJÜ.¨t¯|©|Ó<‰KØ˜DÑ Ü.¨t¯|©|Ó<‰KØ˜EÑ!ØˆKàˆ
Ü�k¤3Ô'Ø$ˆJÜ.¨t¯z©zÓ:‰KØ˜DÑ Ü.¨t¯z©zÓ:‰KØ˜EÑ!ØˆKä�;ÔØˆDŒKØ!ˆDÕÜ˜¤SÔ)¨k¸VÒ.CØ ˆDŒKÜ3°D·L±LÓAˆDÕà,0×,<Ñ,<¸[Ø=Gó-IÑ)ˆDŒK˜Ô)ô �;ÔØˆDŒKØ!ˆDÕÜ˜¤SÔ)¨k¸VÒ.CØ ˆDŒKÜ3°D·J±JÓ?ˆDÕà,0×,<Ñ,<¸[Ø=Gó-IÑ)ˆDŒK˜Ô)ô ! §¡Ó.ˆÜ  §¡Ó,ˆØ &Ð 2‘f¸ˆŒØ &Ð 2‘f¸ˆŒð 	×#Ñ# I¨t°TØ$(¨&°&ô	:ð ˆ=˜E U™NØˆEØ‰Jä˜%¤Ô&Ø&‘
äŸZ™Z¨Ó.�
Ø×#Ñ# y§¡Ò6ØD�CÜ$ S›/Ð)ØˆEð ˆŒ	Ø"ˆŒàˆŒ
Ø$ˆŒàˆŒØ(Ð0™°i·n±nÓ6FˆŒØˆŒ	Ø&Ð.˜ˆ�°H·M±M³Oˆ�r   c                 ó®  — |j                  t        «      j                  t        j                  «      }|€.|rt        j
                  |d«      }nt        j                  |«      }|€.|rt        j
                  |d«      }nt        j                  |«      }||c| _        | _	        |€.|€t        j                  | _        nst        j                  | _        n]t        |t        «      rt!        |«      | _        n<t        |t"        «      r%t$        j&                  j)                  |«      | _        n|| _        |��¤| j                  t        j*                  j-                  t        j                  g«      «      d   }| j                  t        j.                   «      }	| j                  t        j.                  «      }
|	| j                  d«      k7  }|
| j                  | j                  j0                  dz
  «      k7  }t3        ||z
  ||z
  «      }t$        j&                  j5                  ||z
  ||z   «      } |||g«      \  }}t        j6                  ||d«      }t$        j&                  j)                  | j                  |«      «      | _        | j                  j9                  |«       |r| j                  j;                  |	«       |r| j                  j=                  |
«       yyy)z@Use some heuristics to set good defaults for colorbar and range.Né   éb   r   r   é   )ÚastypeÚfloatÚfilledr-   ÚnanÚnanpercentileÚnanminÚnanmaxrV   rW   r   ÚrocketrX   Úicefirer   rF   r	   r&   r#   r$   ÚListedColormapr@   Úmasked_invalidÚinfÚNÚmaxÚ	NormalizeÚlinspaceÚset_badÚ	set_underÚset_over)rU   rM   rV   rW   rX   rY   rZ   Ú	calc_dataÚbadÚunderÚoverÚ	under_setÚover_setÚvrangeÚnormlizeÚcminÚcmaxÚccs                     r   rL   z"_HeatMapper._determine_cmap_paramsÀ   s'  € ð
 ×$Ñ$¤UÓ+×2Ñ2´2·6±6Ó:ˆ	Øˆ<ÙÜ×'Ñ'¨	°1Ó5‘ä—y‘y Ó+�Øˆ<ÙÜ×'Ñ'¨	°2Ó6‘ä—y‘y Ó+�Ø# TÐˆŒ	�4”9ð ˆ<Øˆ~ÜŸI™I�•	äŸJ™J�•	Ü˜œcÔ"Ü$ TÓ*ˆD�IÜ˜œdÔ#ÜŸ
™
×1Ñ1°$Ó7ˆD�IàˆDŒIð Ñð
 —)‘)œBŸE™E×0Ñ0´"·&±&°Ó:Ó;¸AÑ>ˆCð —I‘IœrŸv™v˜gÓ&ˆEØ—9‘9œRŸV™VÓ$ˆDØ §¡¨1£Ñ-ˆIØ˜tŸy™y¨¯©¯©°q©Ó9Ñ9ˆHä˜ ™¨°©Ó6ˆFÜ—z‘z×+Ñ+¨F°V©O¸VÀf¹_ÓMˆHÙ! 4¨ ,Ó/‰JˆD�$Ü—‘˜T 4¨Ó-ˆBÜŸ
™
×1Ñ1°$·)±)¸B³-Ó@ˆDŒIØ�I‰I×Ñ˜cÔ"ÙØ—	‘	×#Ñ# EÔ*ÙØ—	‘	×"Ñ" 4Õ(ð ð- r   c                 óÐ  — |j                  «        | j                  j                  \  }}t        j                  t        j
                  |«      dz   t        j
                  |«      dz   «      \  }}t        |j                  |j                  |j                  «       j                  |j                  «       | j                  j                  «      D ]˜  \  }}}	}
}|	t        j                  j                  usŒ&t        |
«      }|dkD  rdnd}d| j                  z   dz   j                  |«      }t        |dd¬«      }|j!                  | j"                  «        |j$                  |||fi |¤Ž Œš y	)
z/Add textual labels with the value in each cell.ç      à?gé&1¬Ú?z.15Úwz{:ú}rY   )ÚcolorÚhaÚvaN)Úupdate_scalarmappablerO   r/   r-   ÚmeshgridÚarangeÚzipÚflatÚ	get_arrayÚget_facecolorsr@   Úmaskedr   rP   ÚformatÚdictÚupdaterR   Útext)rU   ÚaxÚmeshÚheightÚwidthÚxposÚyposÚxÚyÚmr„   ÚvalÚlumÚ
text_colorÚ
annotationÚtext_kwargss                   r   Ú_annotate_heatmapz_HeatMapper._annotate_heatmapù   s!  € à×"Ñ"Ô$ØŸ™×-Ñ-‰ˆ�Ü—[‘[¤§¡¨5Ó!1°BÑ!6¼¿	¹	À&Ó8IÈBÑ8NÓO‰
ˆˆdÜ#& t§y¡y°$·)±)Ø'+§~¡~Ó'7×'<Ñ'<¸d×>QÑ>QÓ>SØ'+§¡×';Ñ';ó$=ò 		9ÑˆAˆq�!�U˜Cð œŸ™Ÿ™Ò$Ü(¨Ó/�Ø&)¨D¢j™U°c�
Ø" T§X¡X™o°Ñ3×;Ñ;¸CÓ@�
Ü"¨¸ÀXÔN�Ø×"Ñ" 4§>¡>Ô2Ø�—‘˜˜1˜jÑ8¨KÓ8ñ		9r   c                 óÐ   — t        |«      }|dk(  rg g }}||fS |dk(  rt        j                  |«      dz   |}}||fS d||}}}t        j                  |||«      dz   }||||…   }||fS )z3Return ticks and labels at evenly spaced intervals.r   r   r�   )rC   r-   r‰   )rU   ÚlabelsÚ	tickeveryÚnÚticksÚstartÚendÚsteps           r   rG   z_HeatMapper._skip_ticks	  s’   € ä�‹KˆØ˜Š>Ø �6ˆEð �fˆ}Ðð ˜!Š^ÜŸI™I a›L¨2Ñ-¨v�6ˆEð
 �fˆ}Ðð  ! ! Y˜�3ˆEÜ—I‘I˜e S¨$Ó/°"Ñ4ˆEØ˜E # d˜NÑ+ˆFØ�fˆ}Ðr   c                 óê  — |j                   j                  j                  «       }|j                  «       j	                  |«      }|j
                  |j                  g|   }|j                  |j                  g|   }|j                  dg«      \  }|j                  j                  «       }t        ||dz  z  «      }	|	dk  rg g fS t        |«      |	z  dz   }
|
dk(  rdn|
}
| j                  ||
«      \  }}||fS )z5Determine ticks and ticklabels that minimize overlap.r   éH   r   )ÚfigureÚdpi_scale_transÚinvertedÚget_window_extentÚtransformedr–   r•   ÚxaxisÚyaxisÚ	set_ticksÚlabel1Úget_sizerB   rC   rG   )rU   r“   r£   ÚaxisÚ	transformÚbboxÚsizeÚtickÚfontsizeÚ	max_ticksÚ
tick_everyr¦   s               r   Ú_auto_ticksz_HeatMapper._auto_ticks  sè   € à—I‘I×-Ñ-×6Ñ6Ó8ˆ	Ø×#Ñ#Ó%×1Ñ1°)Ó<ˆØ—
‘
˜DŸK™KÐ(¨Ñ.ˆØ—‘˜"Ÿ(™(Ð# DÑ)ˆØ—‘ ˜sÓ#‰ˆØ—;‘;×'Ñ'Ó)ˆÜ˜ ¨B¡Ñ/Ó0ˆ	Ø�qŠ=Ø�r�6ˆMÜ˜“[ IÑ-°Ñ1ˆ
Ø$¨š/‘Q¨zˆ
Ø×(Ñ(¨°Ó<‰ˆˆvØ�fˆ}Ðr   c                 ó
  — t        |dd¬«       |j                  d«      €8|j                  d| j                  «       |j                  d| j                  «        |j
                  | j                  fd| j                  i|¤Ž}|j                  d| j                  j                  d	   fd| j                  j                  d   f¬
«       |j                  «        | j                  rq |j                  j                  |||fi | j                  ¤Ž}|j                   j#                  d«       |j                  dd«      r|j$                  j'                  d«       t)        | j*                  t,        «      r0| j*                  dk(  r!| j/                  || j0                  d«      \  }}n| j*                  | j0                  }}t)        | j2                  t,        «      r0| j2                  dk(  r!| j/                  || j4                  d	«      \  }}	n| j2                  | j4                  }	}|j                  ||¬«       |j7                  |«      }
|j9                  |	d¬«      }t;        j<                  |d¬«       t?        |j                  «       tA        |
«      rt;        j<                  |
d¬«       tA        |«      rt;        j<                  |d¬«       |j                  | jB                  | jD                  ¬«       | jF                  r| jI                  ||«       yy)z&Draw the heatmap on the provided Axes.T)r“   ÚleftÚbottomÚnormNrV   rW   rX   r   r   )ÚxlimÚylimÚ
rasterizedFr<   )rD   rH   Úvertical©ÚrotationrY   )r†   Ú
horizontal)rJ   rK   )%r
   ÚgetÚ
setdefaultrV   rW   Ú
pcolormeshrM   rX   Úsetr5   r/   Úinvert_yaxisrS   r¬   ÚcolorbarrT   ÚoutlineÚset_linewidthÚsolidsÚset_rasterizedr   rD   rF   r¾   rE   rH   rI   Úset_xticklabelsÚset_yticklabelsÚpltÚsetpr   r   rJ   rK   rN   r¡   )rU   r“   ÚcaxÚkwsr”   ÚcbrD   rE   rH   rI   ÚxtlÚytls               r   Úplotz_HeatMapper.plot&  sW  € ô 	�2˜D¨Õ.ð �7‰7�6‹?Ð"Ø�N‰N˜6 4§9¡9Ô-Ø�N‰N˜6 4§9¡9Ô-ð ˆr�}‰}˜TŸ^™^ÑC°$·)±)ÐC¸sÑCˆð 	�‰�Q˜Ÿ	™	Ÿ™¨Ñ*Ð+°1°d·i±i·o±oÀaÑ6HÐ2IˆÔJð 	�‰Ôð �9Š9Ø#�—‘×#Ñ# D¨#¨rÑC°T·]±]ÑCˆBØ�J‰J×$Ñ$ QÔ'ð �w‰w�| UÔ+Ø—	‘	×(Ñ(¨Ô.ô �d—k‘k¤3Ô'¨D¯K©K¸6Ò,AØ"&×"2Ñ"2°2°t×7GÑ7GÈÓ"KÑˆF‘Kà"&§+¡+¨t×/?Ñ/?�KˆFä�d—k‘k¤3Ô'¨D¯K©K¸6Ò,AØ"&×"2Ñ"2°2°t×7GÑ7GÈÓ"KÑˆF‘Kà"&§+¡+¨t×/?Ñ/?�KˆFà
�‰�f VˆÔ,Ø× Ñ  Ó-ˆØ× Ñ  °zÐ ÓBˆÜ�‰�˜Õ"ô 	�R—Y‘YÔä" 3Ô'Ü�H‰H�S :Õ.Ü" 3Ô'Ü�H‰H�S <Õ0ð 	�‰�d—k‘k¨$¯+©+ˆÔ6ð �:Š:Ø×"Ñ" 2 tÕ,ð r   )TTN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r]   rL   r¡   rG   r¾   rÝ   © r   r   r:   r:   a   s,   „ ÙIð ;?óZDòx7)òr9ò òó :-r   r:   z.2gÚwhiter<   )rV   rW   rX   rY   rZ   rN   rP   rR   Ú
linewidthsÚ	linecolorrS   rT   Úcbar_axÚsquarerE   rI   r6   r“   c                óÂ   — t        | |||||||||||||«      }|	|d<   |
|d<   |€t        j                  «       }|r|j                  d«       |j	                  |||«       |S )aî  Plot rectangular data as a color-encoded matrix.

    This is an Axes-level function and will draw the heatmap into the
    currently-active Axes if none is provided to the ``ax`` argument.  Part of
    this Axes space will be taken and used to plot a colormap, unless ``cbar``
    is False or a separate Axes is provided to ``cbar_ax``.

    Parameters
    ----------
    data : rectangular dataset
        2D dataset that can be coerced into an ndarray. If a Pandas DataFrame
        is provided, the index/column information will be used to label the
        columns and rows.
    vmin, vmax : floats, optional
        Values to anchor the colormap, otherwise they are inferred from the
        data and other keyword arguments.
    cmap : matplotlib colormap name or object, or list of colors, optional
        The mapping from data values to color space. If not provided, the
        default will depend on whether ``center`` is set.
    center : float, optional
        The value at which to center the colormap when plotting divergent data.
        Using this parameter will change the default ``cmap`` if none is
        specified.
    robust : bool, optional
        If True and ``vmin`` or ``vmax`` are absent, the colormap range is
        computed with robust quantiles instead of the extreme values.
    annot : bool or rectangular dataset, optional
        If True, write the data value in each cell. If an array-like with the
        same shape as ``data``, then use this to annotate the heatmap instead
        of the data. Note that DataFrames will match on position, not index.
    fmt : str, optional
        String formatting code to use when adding annotations.
    annot_kws : dict of key, value mappings, optional
        Keyword arguments for :meth:`matplotlib.axes.Axes.text` when ``annot``
        is True.
    linewidths : float, optional
        Width of the lines that will divide each cell.
    linecolor : color, optional
        Color of the lines that will divide each cell.
    cbar : bool, optional
        Whether to draw a colorbar.
    cbar_kws : dict of key, value mappings, optional
        Keyword arguments for :meth:`matplotlib.figure.Figure.colorbar`.
    cbar_ax : matplotlib Axes, optional
        Axes in which to draw the colorbar, otherwise take space from the
        main Axes.
    square : bool, optional
        If True, set the Axes aspect to "equal" so each cell will be
        square-shaped.
    xticklabels, yticklabels : "auto", bool, list-like, or int, optional
        If True, plot the column names of the dataframe. If False, don't plot
        the column names. If list-like, plot these alternate labels as the
        xticklabels. If an integer, use the column names but plot only every
        n label. If "auto", try to densely plot non-overlapping labels.
    mask : bool array or DataFrame, optional
        If passed, data will not be shown in cells where ``mask`` is True.
        Cells with missing values are automatically masked.
    ax : matplotlib Axes, optional
        Axes in which to draw the plot, otherwise use the currently-active
        Axes.
    kwargs : other keyword arguments
        All other keyword arguments are passed to
        :meth:`matplotlib.axes.Axes.pcolormesh`.

    Returns
    -------
    ax : matplotlib Axes
        Axes object with the heatmap.

    See Also
    --------
    clustermap : Plot a matrix using hierarchical clustering to arrange the
                 rows and columns.

    Examples
    --------

    .. include:: ../docstrings/heatmap.rst

    rä   Ú	edgecolorÚequal)r:   rÖ   ÚgcaÚ
set_aspectrÝ   )r5   rV   rW   rX   rY   rZ   rN   rP   rR   rä   rå   rS   rT   ræ   rç   rE   rI   r6   r“   ÚkwargsÚplotters                        r   r   r   c  sy   € ôv ˜$  d¨D°&¸&À%ÈØ# T¨8°[Ø% tó-€Gð
 &€Fˆ<ÑØ#€Fˆ;Ñð 
€zÜ�W‰W‹YˆÙØ
�‰�gÔØ‡L�L��W˜fÔ%Ø€Ir   c                   óN   — e Zd ZdZd„ Zd„ Zd„ Zed„ «       Zd„ Z	ed„ «       Z
d„ Zy	)
Ú_DendrogramPlotterzAObject for drawing tree of similarities between data rows/columnsc                 óÀ  — || _         | j                   dk(  r|j                  }t        |t        j                  «      r|j
                  }n*t        j                  |«      }t        j                  |«      }|| _        || _	        | j                  j                  | _
        || _        || _        || _         || _        || _        |€| j                  | _        n|| _        | j#                  «       | _        dt        j&                  | j                  j                  d   «      z  dz   }	| j                  r×t)        | j                  j*                  «      }
| j,                  D �cg c]  }|
|   ‘Œ	 }
}| j                  rHg | _        |	| _        g | _        |
| _        t7        | j                  j*                  «      | _        d| _        nu|	| _        g | _        |
| _        g | _        d| _        t7        | j                  j*                  «      | _        n-g g c| _        | _        g g c| _        | _        d\  | _        | _        | j$                  d   | _        | j$                  d	   | _        yc c}w )
z¯Plot a dendrogram of the relationships between the columns of data

        Parameters
        ----------
        data : pandas.DataFrame
            Rectangular data
        r   Né
   r   é   r=   )r=   r=   ÚdcoordÚicoord) r¶   ÚTr   r   r2   r   r-   r?   Úarrayr5   r/   ÚmetricÚmethodÚlabelÚrotateÚcalculated_linkageÚlinkageÚcalculate_dendrogramÚ
dendrogramr‰   r!   r   Úreordered_indrD   rH   rE   rI   r   rK   rJ   Údependent_coordÚindependent_coord)rU   r5   rý   rø   rù   r¶   rú   rû   r÷   r¦   Ú
ticklabelsr    s               r   r]   z_DendrogramPlotter.__init__Ò  sé  € ð ˆŒ	Ø�9‰9˜Š>Ø—6‘6ˆDä�dœBŸL™LÔ)Ø—K‘K‰Eä—J‘J˜tÓ$ˆEÜ—<‘< Ó&ˆDàˆŒ
ØˆŒ	à—Y‘Y—_‘_ˆŒ
ØˆŒØˆŒØˆŒ	ØˆŒ
ØˆŒàˆ?Ø×2Ñ2ˆD�Là"ˆDŒLØ×3Ñ3Ó5ˆŒð ”R—Y‘Y˜tŸy™yŸ™¨qÑ1Ó2Ñ2°QÑ6ˆà�:Š:Ü-¨d¯i©i¯o©oÓ>ˆJØ15×1CÑ1CÖD¨A˜* Q›-ÐDˆJÐDØ�{Š{Ø �”Ø#�”Ø#%�Ô à#-�Ô Ü-¨d¯i©i¯o©oÓ>�”Ø �•à#�”Ø �”Ø#-�Ô Ø#%�Ô Ø �”Ü-¨d¯i©i¯o©oÓ>�•à')¨2Ð$ˆDŒK˜œØ13°RÐ.ˆDÔ˜dÔ.Ø'-Ñ$ˆDŒK˜œà#Ÿ™¨xÑ8ˆÔØ!%§¡°Ñ!:ˆÕùò- Es   ÅIc                 ór   — t        j                  | j                  | j                  | j                  ¬«      }|S )N©rù   rø   )r   rý   r÷   rù   rø   )rU   rý   s     r   Ú_calculate_linkage_scipyz+_DendrogramPlotter._calculate_linkage_scipy  s*   € Ü×#Ñ# D§J¡J°t·{±{Ø+/¯;©;ô8ˆàˆr   c                 ó:  — dd l }d}| j                  dk(  xr | j                  |v }|s| j                  dk(  r2|j                  | j                  | j                  | j                  ¬«      S |j                  | j                  | j                  | j                  ¬«      }|S )Nr   )ÚcentroidÚmedianÚwardÚ	euclideanÚsingler  )Úfastclusterrø   rù   Úlinkage_vectorr÷   rý   )rU   r  Úeuclidean_methodsr  rý   s        r   Ú_calculate_linkage_fastclusterz1_DendrogramPlotter._calculate_linkage_fastcluster  s™   € Ûð ;ÐØ—K‘K ;Ñ.ò °4·;±;Øð4ˆ	á˜Ÿ™ xÒ/Ø×-Ñ-¨d¯j©jØ59·[±[Ø59·[±[ð .ó Bð Bð "×)Ñ)¨$¯*©*¸T¿[¹[Ø15·±ð *ó >ˆGàˆNr   c                 óÒ   — 	 | j                  «       S # t        $ rK t        j                  | j                  «      dk\  rd}t        j                  |«       Y | j                  «       S w xY w)Ni'  zYClustering large matrix with scipy. Installing `fastcluster` may give better performance.)r  ÚImportErrorr-   Úprodr/   ÚwarningsÚwarnr  )rU   Úmsgs     r   rü   z%_DendrogramPlotter.calculated_linkage'  s^   € ð	#Ø×6Ñ6Ó8Ð8øÜò 	#Ü�w‰w�t—z‘zÓ" eÒ+ðD�ä—‘˜cÔ"øà×,Ñ,Ó.Ð.ð	#ús   ‚ ’AA&Á%A&c                 ód   — t        j                  | j                  dt        j                   ¬«      S )aÌ  Calculates a dendrogram based on the linkage matrix

        Made a separate function, not a property because don't want to
        recalculate the dendrogram every time it is accessed.

        Returns
        -------
        dendrogram : dict
            Dendrogram dictionary as returned by scipy.cluster.hierarchy
            .dendrogram. The important key-value pairing is
            "reordered_ind" which indicates the re-ordering of the matrix
        T)Úno_plotÚcolor_threshold)r   rÿ   rý   r-   rm   ©rU   s    r   rþ   z'_DendrogramPlotter.calculate_dendrogram4  s(   € ô ×#Ñ# D§L¡L¸$Ü57·V±V°Gô=ð 	=r   c                 ó    — | j                   d   S )z2Indices of the matrix, reordered by the dendrogramÚleaves)rÿ   r  s    r   r   z _DendrogramPlotter.reordered_indD  s   € ð �‰˜xÑ(Ð(r   c                 óx  — |€i n|j                  «       }|j                  dd«       |j                  d|j                  dd«      «       | j                  r0| j                  dk(  r!t        | j                  | j                  «      }n t        | j                  | j                  «      }t        |D ��cg c]  \  }}t        t        ||«      «      ‘Œ c}}fi |¤Ž}|j                  |«       t        | j                  «      }t        t        t        | j                  «      «      }| j                  rf|j                  j!                  d«       |j#                  d|dz  «       |j%                  d|d	z  «       |j'                  «        |j)                  «        n*|j%                  d|dz  «       |j#                  d|d	z  «       t+        |d
d
¬«       |j-                  | j.                  | j0                  | j2                  | j4                  ¬«       |j7                  | j8                  «      }	|j;                  | j<                  d¬«      }
t?        |j@                  «       t        |
«      dkD  r"tC        |
«      rtE        jF                  |
d¬«       t        |	«      dkD  r"tC        |	«      rtE        jF                  |	d¬«       | S c c}}w )zÏPlots a dendrogram of the similarities between data on the axes

        Parameters
        ----------
        ax : matplotlib.axes.Axes
            Axes object upon which the dendrogram is plotted

        rä   r�   r$   r„   )çš™™™™™É?r  r  r   Úrightrò   gÍÌÌÌÌÌð?T©r“   rÁ   rÀ   )rD   rH   rJ   rK   rÆ   rÇ   rÉ   )$rQ   rË   Úpoprû   r¶   rŠ   r  r  r   r&   Úadd_collectionrC   r   ro   r   r²   Úset_ticks_positionÚset_ylimÚset_xlimÚinvert_xaxisrÎ   r
   rÍ   rD   rH   rJ   rK   rÔ   rE   rÕ   rI   r   r¬   r   rÖ   r×   )rU   r“   Útree_kwsÚcoordsr™   rš   ÚlinesÚnumber_of_leavesÚmax_dependent_coordrÛ   rÜ   s              r   rÝ   z_DendrogramPlotter.plotI  s,  € ð "Ð)‘2¨x¯}©}«ˆØ×Ñ˜L¨"Ô-Ø×Ñ˜H h§l¡l°7¸LÓ&IÔJà�;Š;˜4Ÿ9™9¨š>Ü˜×-Ñ-¨t×/EÑ/EÓF‰Fä˜×/Ñ/°×1EÑ1EÓFˆFÜ¸F×C±D°A°q¤¤S¨¨A£Y¥ÓCñ +Ø!)ñ+ˆð 	×Ñ˜%Ô Ü˜t×1Ñ1Ó2ÐÜ!¤#¤c¨4×+?Ñ+?Ó"@ÓAÐà�;Š;Ø�H‰H×'Ñ'¨Ô0ð �K‰K˜Ð+¨bÑ0Ô1Ø�K‰K˜Ð.°Ñ5Ô6à�O‰OÔØ�O‰OÕð �K‰K˜Ð+¨bÑ0Ô1Ø�K‰K˜Ð.°Ñ5Ô6ä�2˜d¨Õ.à
�‰�d—k‘k¨$¯+©+Ø—k‘k¨$¯+©+ð 	ô 	7à× Ñ  ×!1Ñ!1Ó2ˆØ× Ñ  ×!1Ñ!1¸JÐ ÓGˆô 	�R—Y‘YÔäˆs‹8�aŠ<Ô3°CÔ8Ü�H‰H�S <Õ0Üˆs‹8�aŠ<Ô3°CÔ8Ü�H‰H�S :Õ.ØˆùóK  Ds   Â/J6
N)rÞ   rß   rà   rá   r]   r  r  Úpropertyrü   rþ   r   rÝ   râ   r   r   rð   rð   Ï  sG   „ ÙKò=;ò~ò
ð" ñ
/ó ð
/ò=ð  ñ)ó ð)ó6r   rð   r  Úaverage)rý   r¶   rú   rø   rù   rû   r'  r“   c          	      óš   — t         rt        d«      ‚t        | ||||||¬«      }	|€t        j                  «       }|	j                  ||¬«      S )aÓ  Draw a tree diagram of relationships within a matrix

    Parameters
    ----------
    data : pandas.DataFrame
        Rectangular data
    linkage : numpy.array, optional
        Linkage matrix
    axis : int, optional
        Which axis to use to calculate linkage. 0 is rows, 1 is columns.
    label : bool, optional
        If True, label the dendrogram at leaves with column or row names
    metric : str, optional
        Distance metric. Anything valid for scipy.spatial.distance.pdist
    method : str, optional
        Linkage method to use. Anything valid for
        scipy.cluster.hierarchy.linkage
    rotate : bool, optional
        When plotting the matrix, whether to rotate it 90 degrees
        counter-clockwise, so the leaves face right
    tree_kws : dict, optional
        Keyword arguments for the ``matplotlib.collections.LineCollection``
        that is used for plotting the lines of the dendrogram tree.
    ax : matplotlib axis, optional
        Axis to plot on, otherwise uses current axis

    Returns
    -------
    dendrogramplotter : _DendrogramPlotter
        A Dendrogram plotter object.

    Notes
    -----
    Access the reordered dendrogram indices with
    dendrogramplotter.reordered_ind

    z)dendrogram requires scipy to be installed)rý   r¶   rø   rù   rú   rû   )r“   r'  )Ú	_no_scipyÚRuntimeErrorrð   rÖ   rë   rÝ   )
r5   rý   r¶   rú   rø   rù   rû   r'  r“   rî   s
             r   rÿ   rÿ   ‚  sS   € õT ÜÐFÓGÐGä  ¨w¸TØ(.°vØ',°Vô=€Gð 
€zÜ�W‰W‹Yˆà�<‰<˜2¨ˆ<Ó1Ð1r   c                   ó€   — e Zd Z	 	 	 dd„Zd„ Z	 	 dd„Zedd„«       Zedd„«       Zd„ Z	edd„«       Z
d	„ Zd
„ Zd„ Zd„ Zy)ÚClusterGridNc                 ój  — t         rt        d«      ‚t        |t        j                  «      r|| _        nt        j                  |«      | _        | j                  | j
                  |||«      | _        t        | j                  |«      | _	        t        j                  |¬«      | _        | j                  ||d¬«      \  | _        | _        | j                  ||d¬«      \  | _        | _        	 |	\  }}	 |
\  }}| j'                  | j                  ||«      }| j'                  | j                   ||«      }| j                   €dnd}| j                  €dnd}t)        j*                  ||||¬	«      | _        | j                  j/                  | j,                  d
   «      | _        | j                  j/                  | j,                  d   «      | _        | j0                  j5                  «        | j2                  j5                  «        d| _        d| _        | j                  �-| j                  j/                  | j,                  d   «      | _        | j                   �-| j                  j/                  | j,                  d   «      | _        | j                  j/                  | j,                  d   «      | _        |€dx| _        | _        n>| j                  j/                  | j,                  d   «      | _        | j<                  | _        || _         d| _!        d| _"        y# t$        $ r |	x}}Y �Œ.w xY w# t$        $ r |
x}}Y �Œ<w xY w)z=Grid object for organizing clustered heatmap input on to axesz*ClusterGrid requires scipy to be available)Úfigsizer   ©r¶   r   Nr_   é   )Úwidth_ratiosÚheight_ratios)éÿÿÿÿr   )r   r9  )r9  r   )r   r9  )r9  r9  )r   r   )#r/  r0  r   r   r2   r5   Úformat_dataÚdata2dr8   r6   rÖ   r¬   Ú_figureÚ_preprocess_colorsÚ
row_colorsÚrow_color_labelsÚ
col_colorsÚcol_color_labelsÚ	TypeErrorÚ
dim_ratiosr   ÚGridSpecÚgsÚadd_subplotÚax_row_dendrogramÚax_col_dendrogramÚset_axis_offÚax_row_colorsÚax_col_colorsÚ
ax_heatmapÚax_cbarrØ   Úcbar_posÚdendrogram_rowÚdendrogram_col)rU   r5   Ú	pivot_kwsÚz_scoreÚstandard_scaler4  r>  r@  r6   Údendrogram_ratioÚcolors_ratiorN  Úrow_dendrogram_ratioÚcol_dendrogram_ratioÚrow_colors_ratioÚcol_colors_ratior7  r8  ÚnrowsÚncolss                       r   r]   zClusterGrid.__init__º  sÝ  € õ ÜÐKÓLÐLä�dœBŸL™LÔ)ØˆD�IäŸ™ TÓ*ˆDŒIà×&Ñ& t§y¡y°)¸WØ'5ó7ˆŒô ! §¡¨dÓ3ˆŒ	ä—z‘z¨'Ô2ˆŒð ×#Ñ# D¨*¸1Ð#Ó=ñ 	/ˆŒ˜Ô.ð ×#Ñ# D¨*¸1Ð#Ó=ñ 	/ˆŒ˜Ô.ð	KØ9IÑ6Ð Ð"6ð	?Ø1=Ñ.ÐÐ.ð —‘ t§¡Ø';Ø'7ó9ˆð Ÿ™¨¯©Ø(<Ø(8ó:ˆð —_‘_Ð,‘°!ˆØ—_‘_Ð,‘°!ˆä×#Ñ# E¨5Ø1=Ø2?ôAˆŒð "&§¡×!9Ñ!9¸$¿'¹'À%¹.Ó!IˆÔØ!%§¡×!9Ñ!9¸$¿'¹'À%¹.Ó!IˆÔØ×Ñ×+Ñ+Ô-Ø×Ñ×+Ñ+Ô-à!ˆÔØ!ˆÔà�?‰?Ð&Ø!%§¡×!9Ñ!9Ø—‘˜‘ó" ˆDÔà�?‰?Ð&Ø!%§¡×!9Ñ!9Ø—‘˜‘ó" ˆDÔð Ÿ,™,×2Ñ2°4·7±7¸6±?ÓCˆŒØÐØ&*Ð*ˆDŒL˜4�8ð  Ÿ<™<×3Ñ3°D·G±G¸D±MÓBˆDŒLØ—|‘|ˆDŒHØ ˆŒà"ˆÔØ"ˆÕøôa ò 	KØ:JÐJÐ Ó#7ð	Kûô
 ò 	?Ø2>Ð>ÐÓ/ð	?ús$   Ã*L Ã0L! ÌLÌLÌ!L2Ì1L2c                 ó”  — d}|��@t        |t        j                  t        j                  f«      �r
t	        |d«      s|dk(  st	        |d«      s|dk(  r|rdnd}|› d|› d	�}t        |«      ‚|dk(  r|j                  |j                  «      }n|j                  |j                  «      }|j                  t        «      j                  d
«      }t        |t        j                  «      r,t        |j                  «      }|j                  j                  }n)|j                  €dg}n|j                  g}|j                  }t!        |«      }||fS )zAPreprocess {row/col}_colors to extract labels and convert colors.Nr   r   r+   r   ÚcolÚrowz<_colors indices can't be matched with data indices. Provide z?_colors as a non-indexed datatype, e.g. by using `.to_numpy()``rã   r=   )r   r   r2   ÚSeriesÚhasattrrB  Úreindexr   r+   rb   ÚobjectÚfillnar&   rö   r   r   r)   )rU   r5   r$   r¶   r£   Ú	axis_namer  s          r   r=  zClusterGrid._preprocess_colors  s$  € àˆàÑÜ˜&¤2§<¡<´·±Ð";Õ<ô    gÔ.°4¸1²9Ü  iÔ0°T¸Q²Yá)-¡°5�IØ'˜[ð )/Ø/8¨kð :DðD�Cô $ C›.Ð(ð ˜1’9Ø#Ÿ^™^¨D¯J©JÓ7‘Fà#Ÿ^™^¨D¯L©LÓ9�Fð  Ÿ™¤vÓ.×5Ñ5°gÓ>�ô ˜f¤b§l¡lÔ3Ü! &§.¡.Ó1�FØ#ŸX™XŸ_™_‘Fà—{‘{Ð*Ø"$ ™à"(§+¡+ ˜Ø#Ÿ]™]�Fä$ VÓ,ˆFà�vˆ~Ðr   c                 ó¢   — |� |j                   di |¤Ž}n|}|�|�t        d«      ‚|�| j                  ||«      }|�| j                  ||«      }|S )z,Extract variables from data or use directly.z:Cannot perform both z-scoring and standard-scaling on datarâ   )Úpivotr'   rR  rS  )rU   r5   rQ  rR  rS  r;  s         r   r:  zClusterGrid.format_data0  st   € ð
 Ð Ø�T—Z‘ZÑ, )Ñ,‰FàˆFàÐ >Ð#=ÜØLóNð Nð ÐØ—\‘\ &¨'Ó2ˆFØÐ%Ø×(Ñ(¨°Ó@ˆFØˆr   c                 ó˜   — |dk(  r| }n| j                   }||j                  «       z
  |j                  «       z  }|dk(  r|S |j                   S )aÖ  Standarize the mean and variance of the data axis

        Parameters
        ----------
        data2d : pandas.DataFrame
            Data to normalize
        axis : int
            Which axis to normalize across. If 0, normalize across rows, if 1,
            normalize across columns.

        Returns
        -------
        normalized : pandas.DataFrame
            Noramlized data with a mean of 0 and variance of 1 across the
            specified axis.
        r   )rö   ÚmeanÚstd)r;  r¶   Úz_scoreds      r   rR  zClusterGrid.z_scoreD  sJ   € ð$ �1Š9Ø‰Hà—x‘xˆHà˜xŸ}™}›Ñ.°(·,±,³.Ñ@ˆà�1Š9ØˆOà—:‘:Ðr   c                 ó¾   — |dk(  r| }n| j                   }|j                  «       }||z
  |j                  «       |j                  «       z
  z  }|dk(  r|S |j                   S )aá  Divide the data by the difference between the max and min

        Parameters
        ----------
        data2d : pandas.DataFrame
            Data to normalize
        axis : int
            Which axis to normalize across. If 0, normalize across rows, if 1,
            normalize across columns.

        Returns
        -------
        standardized : pandas.DataFrame
            Noramlized data with a mean of 0 and variance of 1 across the
            specified axis.

        r   )rö   Úminro   )r;  r¶   ÚstandardizedÚsubtracts       r   rS  zClusterGrid.standard_scaleb  si   € ð( �1Š9Ø!‰Là!Ÿ8™8ˆLà×#Ñ#Ó%ˆØ$ xÑ/Ø×ÑÓ ×!1Ñ!1Ó!3Ñ3ñ5ˆð �1Š9ØÐà—>‘>Ð!r   c                 ó¨   — |g}|�/t        j                  |«      dkD  rt        |«      }nd}|||z  gz  }|j                  dt	        |«      z
  «       |S )z8Get the proportions of the figure taken up by each axes.r_   r   )r-   ÚndimrC   ÚappendÚsum)rU   r$   rT  rU  ÚratiosÚn_colorss         r   rC  zClusterGrid.dim_ratios„  s[   € à"Ð#ˆàÐä�w‰w�v‹ Ò"Ü˜v›;‘à�à�x ,Ñ.Ð/Ñ/ˆFð 	�‰�aœ#˜f›+‘oÔ&àˆr   c                 óZ  ‡— 	 t         j                  j                  | d   «       dt        | «      c}Š| g} i }t        j                  |‰ft        «      }t        | «      D ]:  \  }}t        |«      D ]'  \  }}	|j                  |	t        |«      «      }
|
|||f<   Œ) Œ< |dd…|f   }|dk(  r|j                  }t         j                  j                  t        |«      «      }||fS # t        $ r? t        | «      t        | d   «      c}Št        ˆfd„| dd D «       «      st	        d«      ‚Y Œów xY w)aã  Turns a list of colors into a numpy matrix and matplotlib colormap

        These arguments can now be plotted using heatmap(matrix, cmap)
        and the provided colors will be plotted.

        Parameters
        ----------
        colors : list of matplotlib colors
            Colors to label the rows or columns of a dataframe.
        ind : list of ints
            Ordering of the rows or columns, to reorder the original colors
            by the clustered dendrogram order
        axis : int
            Which axis this is labeling

        Returns
        -------
        matrix : numpy.array
            A numpy array of integer values, where each indexes into the cmap
        cmap : matplotlib.colors.ListedColormap

        r   r   c              3   ó:   •K  — | ]  }t        |«      ‰k(  –— Œ y ­w)N)rC   )Ú.0Úcr¥   s     €r   ú	<genexpr>z<ClusterGrid.color_list_to_matrix_and_cmap.<locals>.<genexpr>³  s   øè ø€ Ò7 q”s˜1“v •{Ñ7ùs   ƒNz/Multiple side color vectors must have same size)r#   r$   r%   rC   r'   Úallr-   r.   rB   Ú	enumeraterË   rö   rk   r&   )r$   Úindr¶   r›   Úunique_colorsÚmatrixr    ÚinnerÚjr„   ÚidxrX   r¥   s               @r   Úcolor_list_to_matrix_and_cmapz)ClusterGrid.color_list_to_matrix_and_cmap–  s6  ø€ ð0
	Ü�J‰J×Ñ˜f Q™iÔ(ð ”c˜&“kˆDˆAˆqØ�XˆFð ˆÜ—‘˜1˜a˜&¤#Ó&ˆÜ! &Ó)ò 	#‰HˆAˆuÜ% eÓ,ò #‘��5Ø#×.Ñ.¨u´c¸-Ó6HÓI�Ø"��q˜!�t’ñ#ð	#ð š˜3˜‘ˆØ�1Š9Ø—X‘XˆFä�z‰z×(Ñ(¬¨mÓ)<Ó=ˆØ�tˆ|Ðøô1 ò 	Tä�v“;¤ F¨1¡I£ˆDˆAˆqÜÓ7¨F°1°2¨JÔ7Ô7Ü Ð!RÓSÐSñ 8ð	Tús   ƒ"C" Ã"AD*Ä)D*c                 óú  — |r.t        | j                  ||dd| j                  d||¬«	      | _        n6| j                  j	                  g «       | j                  j                  g «       |r-t        | j                  ||dd| j                  ||¬«      | _        n6| j                  j	                  g «       | j                  j                  g «       t        | j                  dd¬«       t        | j                  dd¬«       y )NFr   T)rø   rù   rú   r¶   r“   rû   rý   r'  r   )rø   rù   rú   r¶   r“   rý   r'  r   )	rÿ   r;  rG  rO  Ú
set_xticksÚ
set_yticksrH  rP  r
   )rU   Úrow_clusterÚcol_clusterrø   rù   Úrow_linkageÚcol_linkager'  s           r   Úplot_dendrogramszClusterGrid.plot_dendrogramsÊ  sØ   € ñ Ü",Ø—‘ F°6ÀÈQØ×)Ñ)°$ÀØ!ô#ˆDÕð ×"Ñ"×-Ñ-¨bÔ1Ø×"Ñ"×-Ñ-¨bÔ1áÜ",Ø—‘ F°6ÀØ˜4×1Ñ1¸;Ø!ô#ˆDÕð ×"Ñ"×-Ñ-¨bÔ1Ø×"Ñ"×-Ñ-¨bÔ1Ü�4×)Ñ)°$¸TÕBÜ�4×)Ñ)°$¸TÖBr   c           	      ór  — |j                  «       }|j                  dd«       |j                  dd«       |j                  dd«       |j                  dd«       |j                  dd«       |j                  dd«       |j                  dd«       |j                  d	d«       |j                  d
d«       | j                  �Œ| j                  | j                  |d¬«      \  }}| j                  �| j                  }nd}t        |f|d| j                  |ddœ|¤Ž |durHt        j                  | j                  j                  «       d¬«       nt        | j                  dd¬«       | j                  �±| j                  | j                  |d¬«      \  }}| j                  �| j                  }nd}t        |f|d| j                  d|dœ|¤Ž |durT| j                  j                  j                  «        t        j                  | j                  j!                  «       d¬«       yyt        | j                  dd¬«       y)z«Plots color labels between the dendrogram and the heatmap

        Parameters
        ----------
        heatmap_kws : dict
            Keyword arguments heatmap

        rX   NrÂ   rY   rN   rV   rW   rZ   rE   rI   r   r5  F)rX   rS   r“   rE   rI   éZ   rÇ   T)rÀ   rÁ   r   )rQ   r!  r>  r‚  r?  r   rJ  rÖ   r×   Úget_xticklabelsr
   r@  rA  rK  r²   Ú
tick_rightÚget_yticklabels)rU   ÚxindÚyindrÙ   r~  rX   r?  rA  s           r   Úplot_colorszClusterGrid.plot_colorsã  s  € ð �h‰h‹jˆØ�‰�˜ÔØ�‰�˜ÔØ�‰�˜$ÔØ�‰�˜ÔØ�‰�˜ÔØ�‰�˜ÔØ�‰�˜$ÔØ�‰�˜tÔ$Ø�‰�˜tÔ$ð �?‰?Ð&Ø×=Ñ=Ø—‘ ¨Að >ó /‰LˆF�Dð ×$Ñ$Ð0Ø#'×#8Ñ#8Ñ à#(Ð ä�Fð L ¨E°d×6HÑ6HØ 0¸eñLØGJòLð   uÑ,Ü—‘˜×+Ñ+×;Ñ;Ó=ÈÖKä�D×&Ñ&¨T¸$Õ?ð �?‰?Ð&Ø×=Ñ=Ø—‘ ¨Að >ó /‰LˆF�Dð ×$Ñ$Ð0Ø#'×#8Ñ#8Ñ à#(Ð ä�Fð L ¨E°d×6HÑ6HØ %Ð3CñLØGJòLð   uÑ,Ø×"Ñ"×(Ñ(×3Ñ3Ô5Ü—‘˜×+Ñ+×;Ñ;Ó=ÈÖJð -ô �D×&Ñ&¨T¸$Ö?r   c                 ó   — | j                   j                  ||f   | _         | j                  j                  ||f   | _        |j                  dd«      }	 t	        j
                  |«      |   }|j                  dd«      }	 t	        j
                  |«      |   }|j                  dd «      }|�|du rnpt        |t        «      r| j                   }nQt	        j
                  |«      }|j                  | j                   j                  k7  rd}	t        |	«      ‚||   d d …|f   }|}|j                  d| j                  d u«       t        | j                   f| j                  | j                  || j                  |||dœ|¤Ž | j                  j!                  «       }|sd n|d	   j#                  «       }
| j                  j$                  j'                  d
«       | j                  j$                  j)                  d
«       |
�1| j                  j!                  «       }t+        j,                  ||
¬«       t/        dd¬«      }| j                  € | j0                  j2                  di |¤Ž y | j                  j5                  «         | j0                  j2                  di |¤Ž | j                  j7                  «        | j                  j9                  | j:                  «       y # t        t        f$ r Y �Œzw xY w# t        t        f$ r Y �Œew xY w)NrE   r<   rI   rN   Fr>   rS   )r“   ræ   rT   r6   rE   rI   rN   r   r  rÇ   ç{®Gáz”?)Úh_padÚw_padrâ   )r;  Úilocr6   r!  r-   r?   rB  Ú
IndexErrorr   r0   r/   r'   rË   rM  r   rL  r�  Úget_rotationr²   r#  Úset_label_positionrÖ   r×   r�   r<  Útight_layoutrI  Úset_axis_onÚset_positionrN  )rU   Úcolorbar_kwsr�  r‘  rÙ   rÛ   rÜ   rN   rO   r7   Úytl_rotÚtight_paramss               r   Úplot_matrixzClusterGrid.plot_matrix$  s‡  € Ø—k‘k×&Ñ& t¨T zÑ2ˆŒØ—I‘I—N‘N 4¨ :Ñ.ˆŒ	ð �g‰g�m VÓ,ˆð	Ü—*‘*˜S“/ $Ñ'ˆCð �g‰g�m VÓ,ˆð	Ü—*‘*˜S“/ $Ñ'ˆCð
 —‘˜ Ó&ˆØˆ=˜E U™NØä˜%¤Ô&Ø!Ÿ[™[‘
äŸZ™Z¨Ó.�
Ø×#Ñ# t§{¡{×'8Ñ'8Ò8ØD�CÜ$ S›/Ð)Ø'¨Ñ-ªa°¨gÑ6�
ØˆEð 	�‰�v˜tŸ|™|°4Ð7Ô8Ü�—‘ð 	F §¡¸¿¹Ø%¨D¯I©IØ¨S¸ñ	FàADò	Fð �o‰o×-Ñ-Ó/ˆÙ!‘$ s¨1¡v×':Ñ':Ó'<ˆØ�‰×Ñ×0Ñ0°Ô9Ø�‰×Ñ×0Ñ0°Ô9ØÐØ—/‘/×1Ñ1Ó3ˆCÜ�H‰H�S 7Õ+ä #¨SÔ1ˆØ�<‰<ÐØ%ˆD�L‰L×%Ñ%Ñ5¨Ó5ð
 �L‰L×%Ñ%Ô'Ø%ˆD�L‰L×%Ñ%Ñ5¨Ò5Ø�L‰L×$Ñ$Ô&Ø�L‰L×%Ñ% d§m¡mÕ4øô_ œ:Ð&ò 	Úð	ûô
 œ:Ð&ò 	Úð	ús$   ÁK Á?K* ËK'Ë&K'Ë*K=Ë<K=c	           	      óP  — |	j                  dd«      r(d}
t        j                  |
«       |	j                  d«       |€i n|}| j	                  |||||||¬«       	 | j
                  j                  }	 | j                  j                  } | j                  ||fi |	¤Ž  | j                  |||fi |	¤Ž | S # t        $ r/ t        j                  | j                  j                  d   «      }Y Œyw xY w# t        $ r/ t        j                  | j                  j                  d   «      }Y Œ�w xY w)Nrç   Fz%``square=True`` ignored in clustermap)rˆ  r‰  r'  r   r   )rÊ   r  r  r!  rŠ  rP  r   ÚAttributeErrorr-   r‰   r;  r/   rO  r’  r¡  )rU   rø   rù   rž  r†  r‡  rˆ  r‰  r'  rÙ   r  r�  r‘  s                r   rÝ   zClusterGrid.plot]  s  € ð
 �7‰7�8˜UÔ#Ø9ˆCÜ�M‰M˜#ÔØ�G‰G�HÔà)Ð1‘r°|ˆà×Ñ˜k¨;¸ÀØ*5À;Ø'/ð 	ô 	1ð	3Ø×&Ñ&×4Ñ4ˆDð	3Ø×&Ñ&×4Ñ4ˆDð 	ˆ×Ñ˜˜tÑ+ sÒ+Øˆ×Ñ˜ t¨TÑ9°SÒ9Øˆøô ò 	3Ü—9‘9˜TŸ[™[×.Ñ.¨qÑ1Ó2ŠDð	3ûô ò 	3Ü—9‘9˜TŸ[™[×.Ñ.¨qÑ1Ó2ŠDð	3ús$   ÁB2 Á1C- Â25C*Ã)C*Ã-5D%Ä$D%)
NNNNNNNNNN)NN)r   )r   )rÞ   rß   rà   r]   r=  r:  ÚstaticmethodrR  rS  rC  r‚  rŠ  r’  r¡  rÝ   râ   r   r   r2  r2  ¸  s€   „ àJNØFJØDHóJ#òX(ðT 48Ø#'óð( òó ðð: ò"ó ð"òBð$ ò1ó ð1òfCò2?@òB75órr   r2  )rò   rò   r  g¸…ëQ¸ž?)r”  gš™™™™™é?gš™™™™™©?g
×£p=
Ç?)rQ  rù   rø   rR  rS  r4  rT   r†  r‡  rˆ  r‰  r>  r@  r6   rT  rU  rN  r'  c                ó†   — t         rt        d«      ‚t        | ||||||||||¬«      } |j                  d|||||	|
||dœ|¤ŽS )a0  
    Plot a matrix dataset as a hierarchically-clustered heatmap.

    This function requires scipy to be available.

    Parameters
    ----------
    data : 2D array-like
        Rectangular data for clustering. Cannot contain NAs.
    pivot_kws : dict, optional
        If `data` is a tidy dataframe, can provide keyword arguments for
        pivot to create a rectangular dataframe.
    method : str, optional
        Linkage method to use for calculating clusters. See
        :func:`scipy.cluster.hierarchy.linkage` documentation for more
        information.
    metric : str, optional
        Distance metric to use for the data. See
        :func:`scipy.spatial.distance.pdist` documentation for more options.
        To use different metrics (or methods) for rows and columns, you may
        construct each linkage matrix yourself and provide them as
        `{row,col}_linkage`.
    z_score : int or None, optional
        Either 0 (rows) or 1 (columns). Whether or not to calculate z-scores
        for the rows or the columns. Z scores are: z = (x - mean)/std, so
        values in each row (column) will get the mean of the row (column)
        subtracted, then divided by the standard deviation of the row (column).
        This ensures that each row (column) has mean of 0 and variance of 1.
    standard_scale : int or None, optional
        Either 0 (rows) or 1 (columns). Whether or not to standardize that
        dimension, meaning for each row or column, subtract the minimum and
        divide each by its maximum.
    figsize : tuple of (width, height), optional
        Overall size of the figure.
    cbar_kws : dict, optional
        Keyword arguments to pass to `cbar_kws` in :func:`heatmap`, e.g. to
        add a label to the colorbar.
    {row,col}_cluster : bool, optional
        If ``True``, cluster the {rows, columns}.
    {row,col}_linkage : :class:`numpy.ndarray`, optional
        Precomputed linkage matrix for the rows or columns. See
        :func:`scipy.cluster.hierarchy.linkage` for specific formats.
    {row,col}_colors : list-like or pandas DataFrame/Series, optional
        List of colors to label for either the rows or columns. Useful to evaluate
        whether samples within a group are clustered together. Can use nested lists or
        DataFrame for multiple color levels of labeling. If given as a
        :class:`pandas.DataFrame` or :class:`pandas.Series`, labels for the colors are
        extracted from the DataFrames column names or from the name of the Series.
        DataFrame/Series colors are also matched to the data by their index, ensuring
        colors are drawn in the correct order.
    mask : bool array or DataFrame, optional
        If passed, data will not be shown in cells where `mask` is True.
        Cells with missing values are automatically masked. Only used for
        visualizing, not for calculating.
    {dendrogram,colors}_ratio : float, or pair of floats, optional
        Proportion of the figure size devoted to the two marginal elements. If
        a pair is given, they correspond to (row, col) ratios.
    cbar_pos : tuple of (left, bottom, width, height), optional
        Position of the colorbar axes in the figure. Setting to ``None`` will
        disable the colorbar.
    tree_kws : dict, optional
        Parameters for the :class:`matplotlib.collections.LineCollection`
        that is used to plot the lines of the dendrogram tree.
    kwargs : other keyword arguments
        All other keyword arguments are passed to :func:`heatmap`.

    Returns
    -------
    :class:`ClusterGrid`
        A :class:`ClusterGrid` instance.

    See Also
    --------
    heatmap : Plot rectangular data as a color-encoded matrix.

    Notes
    -----
    The returned object has a ``savefig`` method that should be used if you
    want to save the figure object without clipping the dendrograms.

    To access the reordered row indices, use:
    ``clustergrid.dendrogram_row.reordered_ind``

    Column indices, use:
    ``clustergrid.dendrogram_col.reordered_ind``

    Examples
    --------

    .. include:: ../docstrings/clustermap.rst

    z)clustermap requires scipy to be available)
rQ  r4  r>  r@  rR  rS  r6   rT  rU  rN  )rø   rù   rž  r†  r‡  rˆ  r‰  r'  râ   )r/  r0  r2  rÝ   )r5   rQ  rù   rø   rR  rS  r4  rT   r†  r‡  rˆ  r‰  r>  r@  r6   rT  rU  rN  r'  rí   rî   s                        r   r   r   z  sr   € õN ÜÐFÓGÐGä˜$¨)¸WØ%/¸JØ")¸.Ø#Ð6FØ'3¸hô	H€Gð ˆ7�<‰<ð 5˜v¨fØ%-Ø$/¸[Ø$/¸[Ø!)ñ	5ð .4ñ	5ð 5r   ))rá   r  Ú
matplotlibr#   Úmatplotlib.collectionsr   Úmatplotlib.pyplotÚpyplotrÖ   r   Únumpyr-   Úpandasr   Úscipy.clusterr   r/  r  r=   r   Úaxisgridr   Ú_compatr	   Úutilsr
   r   r   r   r   Ú__all__r   r!   r)   r8   r:   r   rð   rÿ   r2  r   râ   r   r   ú<module>r±     s!  ðÙ .Û ã Ý 1Ý Ý Û Û ðÝ'Ø€Iõ Ý Ý !÷õ ð �lÐ
#€òòò
Hò"÷J-ñ -ðH 
�D˜t¨D¸Ø
�E TØ˜GØ	˜ dØ˜f°&Ø	�$ôi÷Xpñ pðj �q ¨[Ø˜U¨T°dô32ôl�$ô ðH ˜9¨[Ø ¨xØ˜t°Ø $Ø ¨4Ø dØ ¨4õt5øð[# ò Ø‚Iðús   ¦B9 Â9CÃC