ó
    |ñ:iù¸  ã                   ó”  • S r SSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSK
rSSKr SSKJr  SrSS	KJr  SS
KJr  SSKJr  SSKJrJrJrJrJr  SS/rS rS r S r!S r" " S S5      r#SSSSSSSSSSSSSSSSSSS.S jr$ " S S5      r%SSSSSSSSS.S jr& " S  S!\5      r'SSSSSS"SSSSSSSSS#S$S%SS&.S' jr(g! \ a    Sr N˜f = f)(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                 óª   • [        U [        R                  5      (       a)  SR                  [	        [
        U R                  5      5      $ U R                  $ )z6Convert a pandas index or multiindex to an axis label.Ú-)Ú
isinstanceÚpdÚ
MultiIndexÚjoinÚmapr   ÚnamesÚname)Úindexs    ÚQ/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/seaborn/matrix.pyÚ_index_to_labelr      s7   € ä�%œŸ™×'Ñ'Ø�x‰xœœG U§[¡[Ó1Ó2Ð2à�z‰zÐó    c           	      óÖ   • [        U [        R                  5      (       a:  U R                   Vs/ s H"  nSR	                  [        [        U5      5      PM$     sn$ U R                  $ s  snf )z5Convert a pandas index or multiindex into ticklabels.r   )r   r   r   Úvaluesr   r   r   )r   Úis     r   Ú_index_to_ticklabelsr!   '   sK   € ä�%œŸ™×'Ñ'Ø38·<²<Ó@²<¨a�—‘œœW a›Ö)±<Ñ@Ð@à�|‰|Ðùò As   ®)A&c           
      óì   • [         R                  R                  n U" U S   5        [        [	        X5      5      $ ! [
         a.    U  Vs/ s H  n[        [	        X5      5      PM     Os  snf sns $ f = f)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)   /   sc   € ä�Z‰Z×Ñ€FðHÙˆv�a‰yÔä”C˜Ó'Ó(Ð(øÜó Há@FÓGÂ°*””S˜Ó,Ö-ÂùÔGÒGðHús   œ; »A3Á	A(Á'	A3Á2A3c                 óp  • Uc%  [         R                  " U R                  [        5      n[	        U[         R
                  5      (       aU  UR                  U R                  :w  a  [        S5      e[        R                  " UU R                  U R                  [        S9nO€[	        U[        R                  5      (       aa  UR                  R                  U R                  5      (       d7  UR                  R                  U R                  5      (       a  Sn[        U5      eU[        R                  " U 5      -  nU$ )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Ñ0ØFˆCÜ˜S“/Ð!ð
 ”"—)’)˜D“/Ñ!€Dà€Kr   c                   óB   • \ rS rSrSr SS jrS rS rS rS r	S	 r
S
rg)Ú_HeatMapperéa   z?Draw a heatmap plot of a matrix with nice labels and colormaps.Nc                 ó”  • [        U[        R                  5      (       a  UR                  nO,[        R
                  " U5      n[        R                  " U5      n[        X5      n[        R                  R                  [        R
                  " U5      U5      nSn[        U[        5      (       a  Un[        UR                  5      nO"USL a  [        UR                  5      nOUSL a  / nSn[        U[        5      (       a  Un[        UR                  5      nO"USL a  [        UR                  5      nOUSL a  / n[        U5      (       d  / U l        / U l        O\[        U[         5      (       a(  US:X  a"  SU l        [        UR                  5      U l        OU R#                  UU5      u  U l        U l        [        U5      (       d  / U l        / U l        O\[        U[         5      (       a(  US:X  a"  SU l        [        UR                  5      U l        OU R#                  UU5      u  U l        U l        [)        UR                  5      n[)        UR                  5      nUb  UOSU l        Ub  UOSU l        U R/                  XòUXEU5        Ub  USL a  SnSnOW[        U[0        5      (       a  UnO=[        R
                  " U5      nUR2                  UR2                  :w  a  Sn[5        U5      eSnXl        Xðl        Xpl        UU l        X€l        U	c  0 OU	RA                  5       U l!        X l"        Uc  0 U l#        gURA                  5       U l#        g)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ÚrobustrO   rQ   rS   rT   rU   rF   rJ   r6   rN   Ú
xtickeveryÚ
ytickeveryrK   rL   rP   r7   s                         r   Ú__init__Ú_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Ø$(°&ô	:ð ‰=˜E UšNØˆEØ‰Jä˜%¤×&Ñ&Ø&‘
äŸZšZ¨Ó.�
Ø×#Ñ# y§¡Ó6ØD�CÜ$ S›/Ð)ØˆEð Œ	Ø"ŒàŒ
Ø$ˆŒàŒØ(Ñ0™°i·n±nÓ6FˆŒØŒ	Ø&Ñ.˜ˆ�°H·M±M³Oˆ�r   c                 óì  • UR                  [        5      R                  [        R                  5      nUc5  U(       a  [        R
                  " US5      nO[        R                  " U5      nUc5  U(       a  [        R
                  " US5      nO[        R                  " U5      nX#sU l        U l	        Uc/  Uc  [        R                  U l        O|[        R                  U l        Of[        U[        5      (       a  [!        U5      U l        O@[        U["        5      (       a%  [$        R&                  R)                  U5      U l        OX@l        UGb¨  U R                  [        R*                  R-                  [        R                  /5      5      S   nU R                  [        R.                  * 5      n	U R                  [        R.                  5      n
X�R                  S5      :g  nX R                  U R                  R0                  S-
  5      :g  n[3        X5-
  XR-
  5      n[$        R&                  R5                  X]-
  X]-   5      nU" X#/5      u  nn[        R6                  " UUS5      n[$        R&                  R)                  U R                  U5      5      U l        U R                  R9                  U5        U(       a  U R                  R;                  U	5        U(       a  U R                  R=                  U
5        ggg)z@Use some heuristics to set good defaults for colorbar and range.Né   éb   r   r   é   )ÚastypeÚfloatÚfilledr-   ÚnanÚnanpercentileÚnanminÚnanmaxrW   rX   r   ÚrocketrY   Úicefirer   rG   r	   r&   r#   r$   ÚListedColormaprA   Úmasked_invalidÚinfÚNÚmaxÚ	NormalizeÚlinspaceÚset_badÚ	set_underÚset_over)rV   rN   rW   rX   rY   rZ   r[   Ú	calc_dataÚbadÚunderÚoverÚ	under_setÚover_setÚvrangeÚnormlizeÚcminÚcmaxÚccs                     r   rM   Ú"_HeatMapper._determine_cmap_paramsÀ   s  € ð
 ×$Ñ$¤UÓ+×2Ñ2´2·6±6Ó:ˆ	Ø‰<ÞÜ×'Ò'¨	°1Ó5‘ä—y’y Ó+�Ø‰<ÞÜ×'Ò'¨	°2Ó6‘ä—y’y Ó+�Ø#ÐˆŒ	�4”9ð ‰<Ø‰~ÜŸI™I�•	äŸJ™J�•	Ü˜œc×"Ñ"Ü$ TÓ*ˆD�IÜ˜œd×#Ñ#ÜŸ
™
×1Ñ1°$Ó7ˆD�IàŒIð Òð
 —)‘)œBŸE™E×0Ñ0´"·&±&°Ó:Ó;¸AÑ>ˆCð —I‘IœrŸv™v˜gÓ&ˆEØ—9‘9œRŸV™VÓ$ˆDØ§¡¨1£Ñ-ˆIØŸy™y¨¯©¯©°q©Ó9Ñ9ˆHä˜™¨©Ó6ˆFÜ—z‘z×+Ñ+¨F©O¸V¹_ÓMˆHÙ! 4 ,Ó/‰JˆD�$Ü—’˜T 4¨Ó-ˆBÜŸ
™
×1Ñ1°$·)±)¸B³-Ó@ˆDŒIØ�I‰I×Ñ˜cÔ"ÞØ—	‘	×#Ñ# EÔ*ÞØ—	‘	×"Ñ" 4Õ(ð ð- r   c                 óÐ  • UR                  5         U R                  R                  u  p4[        R                  " [        R
                  " U5      S-   [        R
                  " U5      S-   5      u  pV[        UR                  UR                  UR                  5       R                  UR                  5       U R                  R                  5       H–  u  pxpšnU	[        R                  R                  Ld  M&  [        U
5      nUS:”  a  SOSnSU R                  -   S-   R                  U5      n[        USSS9nUR!                  U R"                  5        UR$                  " XxU40 UD6  M˜     g	)
z/Add textual labels with the value in each cell.ç      à?gé&1¬Ú?z.15Úwz{:Ú}rZ   )ÚcolorÚhaÚvaN)Úupdate_scalarmappablerP   r/   r-   ÚmeshgridÚarangeÚzipÚflatÚ	get_arrayÚget_facecolorsrA   Úmaskedr   rQ   ÚformatÚdictÚupdaterS   Útext)rV   ÚaxÚmeshÚheightÚwidthÚxposÚyposÚxÚyÚmr‡   ÚvalÚlumÚ
text_colorÚ
annotationÚtext_kwargss                   r   Ú_annotate_heatmapÚ_HeatMapper._annotate_heatmapù   s  € à×"Ñ"Ô$ØŸ™×-Ñ-‰ˆÜ—[’[¤§¢¨5Ó!1°BÑ!6¼¿	º	À&Ó8IÈBÑ8NÓO‰
ˆÜ#& t§y¡y°$·)±)Ø'+§~¡~Ó'7×'<Ñ'<¸d×>QÑ>QÓ>SØ'+§¡×';Ñ';ö$=ÑˆA�!˜Cð œŸ™Ÿ™Ô$Ü(¨Ó/�Ø&)¨D£j™U°c�
Ø" T§X¡X™o°Ñ3×;Ñ;¸CÓ@�
Ü"¨¸ÀXÑN�Ø×"Ñ" 4§>¡>Ô2Ø—’˜˜jÑ8¨KÔ8ò$=r   c                 óÄ   • [        U5      nUS:X  a  / / pXA4$ US:X  a  [        R                  " U5      S-   UpXA4$ SX2pvn[        R                  " XVU5      S-   nXXg2   nXA4$ )z3Return ticks and labels at evenly spaced intervals.r   r   r„   )rD   r-   rŒ   )rV   ÚlabelsÚ	tickeveryÚnÚticksÚstartÚendÚsteps           r   rH   Ú_HeatMapper._skip_ticks	  s~   € ä�‹KˆØ˜‹>Ø �6ð ˆ}Ðð ˜!‹^ÜŸIšI a›L¨2Ñ-¨v�6ð
 ˆ}Ðð  ! !˜ˆEÜ—I’I˜e¨$Ó/°"Ñ4ˆEØ #˜NÑ+ˆFØˆ}Ðr   c                 óæ  • UR                   R                  R                  5       nUR                  5       R	                  U5      nUR
                  UR                  /U   nUR                  UR                  /U   nUR                  S/5      u  nUR                  R                  5       n[        XhS-  -  5      n	U	S:  a  / / 4$ [        U5      U	-  S-   n
U
S:X  a  SOU
n
U R                  X*5      u  p²X²4$ )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_sizerC   rD   rH   )rV   r–   r§   ÚaxisÚ	transformÚbboxÚsizeÚtickÚfontsizeÚ	max_ticksÚ
tick_everyrª   s               r   Ú_auto_ticksÚ_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ˆ
Ø×(Ñ(¨Ó<‰ˆØˆ}Ðr   c                 ó  • [        USSS9  UR                  S5      c8  UR                  SU R                  5        UR                  SU R                  5        UR
                  " U R                  4SU R                  0UD6nUR                  SU R                  R                  S	   4SU R                  R                  S   4S
9  UR                  5         U R                  (       au  UR                  R                  " XBU40 U R                  D6nUR                   R#                  S5        UR                  SS5      (       a  UR$                  R'                  S5        [)        U R*                  [,        5      (       a/  U R*                  S:X  a  U R/                  XR0                  S5      u  pgOU R*                  U R0                  pv[)        U R2                  [,        5      (       a/  U R2                  S:X  a  U R/                  XR4                  S	5      u  p‰OU R2                  U R4                  p˜UR                  XhS9  UR7                  U5      n
UR9                  U	SS9n[:        R<                  " USS9  [?        UR                  5        [A        U
5      (       a  [:        R<                  " U
SS9  [A        U5      (       a  [:        R<                  " USS9  UR                  U RB                  U RD                  S9  U RF                  (       a  U RI                  X5        gg)z&Draw the heatmap on the provided Axes.T)r–   ÚleftÚbottomÚnormNrW   rX   rY   r   r   )ÚxlimÚylimÚ
rasterizedFr=   )rE   rI   Úvertical©ÚrotationrZ   )r‰   Ú
horizontal)rK   rL   )%r
   ÚgetÚ
setdefaultrW   rX   Ú
pcolormeshrN   rY   Úsetr5   r/   Úinvert_yaxisrT   r±   ÚcolorbarrU   ÚoutlineÚset_linewidthÚsolidsÚset_rasterizedr   rE   rG   rÃ   rF   rI   rJ   Úset_xticklabelsÚset_yticklabelsÚpltÚsetpr   r   rK   rL   rO   r¤   )rV   r–   ÚcaxÚkwsr—   ÚcbrE   rF   rI   rJ   ÚxtlÚytls               r   ÚplotÚ_HeatMapper.plot&  sT  € ô 	�2˜D¨Ò.ð �7‰7�6‹?Ñ"Ø�N‰N˜6 4§9¡9Ô-Ø�N‰N˜6 4§9¡9Ô-ð �}Š}˜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×7GÑ7GÈÓ"KÑˆF�Kà"&§+¡+¨t×/?Ñ/?�Kä�d—k‘k¤3×'Ñ'¨D¯K©K¸6Ó,AØ"&×"2Ñ"2°2×7GÑ7GÈÓ"KÑˆF�Kà"&§+¡+¨t×/?Ñ/?�Kà
�‰�fˆÑ,Ø× Ñ  Ó-ˆØ× Ñ  °zÐ ÐBˆÜ�Š�˜Ò"ô 	�R—Y‘YÔä" 3×'Ñ'Ü�HŠH�S :Ò.Ü" 3×'Ñ'Ü�HŠH�S <Ò0ð 	�‰�d—k‘k¨$¯+©+ˆÑ6ð �:�:Ø×"Ñ" 2Õ,ð r   )rO   rP   rS   rT   rU   rY   r5   rQ   rN   rX   rW   rK   rF   rE   rL   rJ   rI   )TTN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r^   rM   r¤   rH   rÃ   rã   Ú__static_attributes__© r   r   r:   r:   a   s,   † ÙIð ;?ôZDòx7)òr9ò òõ :-r   r:   z.2gÚwhiter=   )rW   rX   rY   rZ   r[   rO   rQ   rS   Ú
linewidthsÚ	linecolorrT   rU   Úcbar_axÚsquarerF   rJ   r6   r–   c                óÄ   • [        XX#XEXgX‹XÏUU5      nU	US'   U
US'   Uc  [        R                  " 5       nU(       a  UR                  S5        UR	                  UUU5        U$ )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   rW   rX   rY   rZ   r[   rO   rQ   rS   rí   rî   rT   rU   rï   rð   rF   rJ   r6   r–   ÚkwargsÚplotters                        r   r   r   c  sm   € ôv ˜$ d°&À%Ø#¨8Ø% tó-€Gð
 &€Fˆ<ÑØ#€Fˆ;Ñð 
�zÜ�WŠW‹YˆÞØ
�‰�gÔØ‡L�L��W˜fÔ%Ø€Ir   c                   óV   • \ rS rSrSrS rS rS r\S 5       r	S r
\S 5       rS	 rS
rg)Ú_DendrogramPlotteriÏ  zAObject for drawing tree of similarities between data rows/columnsc                 óÒ  • XPl         U R                   S:X  a  UR                  n[        U[        R                  5      (       a  UR
                  nO,[        R                  " U5      n[        R                  " U5      nX€l        Xl	        U R                  R                  U l
        X0l        X@l        XPl         X`l        Xpl        Uc  U R                  U l        OX l        U R#                  5       U l        S[        R&                  " U R                  R                  S   5      -  S-   n	U R                  (       aÚ  [)        U R                  R*                  5      n
U R,                   Vs/ s H  oºU   PM	     n
nU R                  (       aF  / U l        X�l        / U l        X l        [7        U R                  R*                  5      U l        SU l        OsX�l        / U l        X l        / U l        SU l        [7        U R                  R*                  5      U l        O-/ / sU l        U l        / / sU l        U l        Su  U l        U l        U R$                  S   U l        U R$                  S	   U l        gs  snf )
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_indrE   rI   rF   rJ   r   rL   rK   Údependent_coordÚindependent_coord)rV   r5   r  r  r  r»   r  r  r   rª   Ú
ticklabelsr    s               r   r^   Ú_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à"Œ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Ò1C¨A Qœ-Ñ1Cˆ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                 ón   • [         R                  " U R                  U R                  U R                  S9nU$ )N©r  r  )r   r  r   r  r  )rV   r  s     r   Ú_calculate_linkage_scipyÚ+_DendrogramPlotter._calculate_linkage_scipy  s*   € Ü×#Ò# D§J¡J°t·{±{Ø+/¯;©;ñ8ˆàˆr   c                 óF  • SS K nSnU R                  S:H  =(       a    U R                  U;   nU(       d  U R                  S:X  a/  UR                  U R                  U R                  U R                  S9$ UR                  U R                  U R                  U R                  S9nU$ )Nr   )ÚcentroidÚmedianÚwardÚ	euclideanÚsingler  )Úfastclusterr  r  Úlinkage_vectorr   r  )rV   r  Úeuclidean_methodsr  r  s        r   Ú_calculate_linkage_fastclusterÚ1_DendrogramPlotter._calculate_linkage_fastcluster  s™   € Ûð ;ÐØ—K‘K ;Ñ.÷ °4·;±;Øñ4ˆ	æ˜Ÿ™ xÓ/Ø×-Ñ-¨d¯j©jØ59·[±[Ø59·[±[ð .ð Bð Bð "×)Ñ)¨$¯*©*¸T¿[¹[Ø15·±ð *ð >ˆGàˆNr   c                 óÚ   •  U R                  5       $ ! [         aN    [        R                  " U R                  5      S:¼  a  Sn[
        R                  " U5         U R                  5       $ f = f)Ni'  zYClustering large matrix with scipy. Installing `fastcluster` may give better performance.)r  ÚImportErrorr-   Úprodr/   ÚwarningsÚwarnr  )rV   Úmsgs     r   r  Ú%_DendrogramPlotter.calculated_linkage'  s^   € ð	#Ø×6Ñ6Ó8Ð8øÜó 	#Ü�wŠw�t—z‘zÓ" eÓ+ðD�ä—’˜cÔ"øà×,Ñ,Ó.Ð.ð	#ús   ‚ ’AA*Á)A*c                 ó`   • [         R                  " U R                  S[        R                  * S9$ )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-   ro   ©rV   s    r   r  Ú'_DendrogramPlotter.calculate_dendrogram4  s(   € ô ×#Ò# D§L¡L¸$Ü57·V±V°Gñ=ð 	=r   c                 ó    • U R                   S   $ )z2Indices of the matrix, reordered by the dendrogramÚleaves)r  r'  s    r   r	  Ú _DendrogramPlotter.reordered_indD  s   € ð �‰˜xÑ(Ð(r   c                 ó�  • Uc  0 OUR                  5       nUR                  SS5        UR                  SUR                  SS5      5        U R                  (       a1  U R                  S:X  a!  [        U R                  U R                  5      nO [        U R                  U R                  5      n[        U VVs/ s H  u  pE[        [        XE5      5      PM     snn40 UD6nUR                  U5        [        U R                  5      n[        [        [        U R                  5      5      nU R                  (       af  UR                  R!                  S5        UR#                  SUS-  5        UR%                  SUS	-  5        UR'                  5         UR)                  5         O*UR%                  SUS-  5        UR#                  SUS	-  5        [+        US
S
S9  UR-                  U R.                  U R0                  U R2                  U R4                  S9  UR7                  U R8                  5      n	UR;                  U R<                  SS9n
[?        UR@                  5        [        U
5      S:”  a%  [C        U
5      (       a  [D        RF                  " U
SS9  [        U	5      S:”  a%  [C        U	5      (       a  [D        RF                  " U	SS9  U $ s  snnf )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Æ   )rE   rI   rK   rL   rÌ   rÍ   rÏ   )$rR   rÑ   Úpopr  r»   r�   r
  r  r   r&   Úadd_collectionrD   r	  rq   r   r·   Úset_ticks_positionÚset_ylimÚset_xlimÚinvert_xaxisrÔ   r
   rÓ   rE   rI   rK   rL   rÚ   rF   rÛ   rJ   r   r±   r   rÜ   rÝ   )rV   r–   Útree_kwsÚcoordsrœ   r�   ÚlinesÚnumber_of_leavesÚmax_dependent_coordrá   râ   s              r   rã   Ú_DendrogramPlotter.plotI  s2  € ð "Ñ)‘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ºF±D°A¤¤S¨£Y¦¹FÒ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Ñ8Ü�HŠH�S <Ò0Üˆs‹8�a‹<Ô3°C×8Ñ8Ü�HŠH�S :Ò.ØˆùóK  Ds   Â6 K
)r   r»   r5   r  r
  r  r  r  r  r  r  r/   rK   rF   rE   rL   rJ   rI   N)rå   ræ   rç   rè   ré   r^   r  r  Úpropertyr  r  r	  rã   rê   rë   r   r   rù   rù   Ï  sG   † ÙKò=;ò~ò
ð" ñ
/ó ð
/ò=ð  ñ)ó ð)õ6r   rù   r  Úaverage)r  r»   r  r  r  r  r6  r–   c          
      ó”   • [         (       a  [        S5      e[        XUXEX6S9n	Uc  [        R                  " 5       nU	R                  X‡S9$ )aS  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–   r6  )Ú	_no_scipyÚRuntimeErrorrù   rÜ   rô   rã   )
r5   r  r»   r  r  r  r  r6  r–   r÷   s
             r   r  r  ‚  sM   € ÷T ‚yÜÐFÓGÐGä  ¸TØ(.Ø',ñ=€Gð 
�zÜ�WŠW‹Yˆà�<‰<˜2ˆ<Ð1Ð1r   c                   ó’   • \ rS rSr   SS jrS r  SS jr\SS j5       r\SS j5       r	S r
\SS	 j5       rS
 rS rS rS rSrg)ÚClusterGridi¸  Nc                 óh  • [         (       a  [        S5      e[        U[        R                  5      (       a  Xl        O[        R                  " U5      U l        U R                  U R
                  X#U5      U l        [        U R                  U5      U l	        [        R                  " US9U l        U R                  XSS9u  U l        U l        U R                  XSS9u  U l        U l         U	u  pÍ U
u  pïU R'                  U R                  UU5      nU R'                  U R                   UU5      nU R                   c  SOSnU R                  c  SOSn[(        R*                  " UUUUS	9U l        U R                  R/                  U R,                  S
   5      U l        U R                  R/                  U R,                  S   5      U l        U R0                  R5                  5         U R2                  R5                  5         SU l        SU l        U R                  b-  U R                  R/                  U R,                  S   5      U l        U R                   b-  U R                  R/                  U R,                  S   5      U l        U R                  R/                  U R,                  S   5      U l        Uc  S=U l        U l        O>U R                  R/                  U R,                  S   5      U l        U R<                  U l        X°l         SU l!        SU l"        g! [$         a    U	=pÍ GN/f = f! [$         a    U
=pï GN>f = f)z=Grid object for organizing clustered heatmap input on to axesz*ClusterGrid requires scipy to be available)Úfigsizer   ©r»   r   Nra   é   )Úwidth_ratiosÚheight_ratios)éÿÿÿÿr   )r   rI  )rI  r   )r   rI  )rI  rI  )r   r   )#r?  r@  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)rV   r5   Ú	pivot_kwsÚz_scoreÚstandard_scalerD  rN  rP  r6   Údendrogram_ratioÚcolors_ratior^  Úrow_dendrogram_ratioÚcol_dendrogram_ratioÚrow_colors_ratioÚcol_colors_ratiorG  rH  ÚnrowsÚncolss                       r   r^   ÚClusterGrid.__init__º  sÒ  € ÷ Š9ÜÐKÓLÐLä�dœBŸL™L×)Ñ)Ø�IäŸš TÓ*ˆDŒIà×&Ñ& t§y¡y°)Ø'5ó7ˆŒô ! §¡¨dÓ3ˆŒ	ä—z’z¨'Ñ2ˆŒð ×#Ñ# D¸1Ð#Ð=ñ 	/ˆŒ˜Ô.ð ×#Ñ# D¸1Ð#Ð=ñ 	/ˆŒ˜Ô.ð	KØ9IÑ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 Ã.L  ÌLÌLÌ L1Ì0L1c                 óÎ  • SnUGb]  [        U[        R                  [        R                  45      (       Ga"  [	        US5      (       d  US:X  d  [	        US5      (       d$  US:X  a  U(       a  SOSnU SU S	3n[        U5      eUS:X  a  UR                  UR                  5      nOUR                  UR                  5      nUR                  [        5      R                  S
5      n[        U[        R                  5      (       a,  [        UR                  5      nUR                  R                  nO*UR                  c  S/nOUR                  /nUR                  n[!        U5      nX$4$ )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ÚhasattrrR  Úreindexr   r+   rd   ÚobjectÚfillnar&   rÿ   r   r   r)   )rV   r5   r$   r»   r§   Ú	axis_namer"  s          r   rM  ÚClusterGrid._preprocess_colors  s.  € àˆàÒÜ˜&¤2§<¡<´·±Ð";×<Ò<ô    g×.Ñ.°4¸1³9Ü  i×0Ñ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Ñ3Ü! &§.¡.Ó1�FØ#ŸX™XŸ_™_‘Fà—{‘{Ñ*Ø"$ ™à"(§+¡+ ˜Ø#Ÿ]™]�Fä$ VÓ,ˆFàˆ~Ðr   c                 ó¨   • Ub  UR                   " S0 UD6nOUnUb  Ub  [        S5      eUb  U R                  XS5      nUb  U R                  XT5      nU$ )z,Extract variables from data or use directly.z:Cannot perform both z-scoring and standard-scaling on datarë   )Úpivotr'   rb  rc  )rV   r5   ra  rb  rc  rK  s         r   rJ  ÚClusterGrid.format_data0  sn   € ð
 Ñ Ø—Z’ZÑ, )Ñ,‰FàˆFàÑ >Ñ#=ÜØLóNð Nð ÑØ—\‘\ &Ó2ˆFØÑ%Ø×(Ñ(¨Ó@ˆFØˆr   c                 óš   • US:X  a  U nOU R                   nX"R                  5       -
  UR                  5       -  nUS:X  a  U$ UR                   $ )an  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)rK  r»   Úz_scoreds      r   rb  ÚClusterGrid.z_scoreD  sH   € ð$ �1‹9Ø‰Hà—x‘xˆHàŸ}™}›Ñ.°(·,±,³.Ñ@ˆà�1‹9ØˆOà—:‘:Ðr   c                 óÀ   • US:X  a  U nOU R                   nUR                  5       nX#-
  UR                  5       UR                  5       -
  -  nUS:X  a  U$ UR                   $ )ay  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ÿ   Úminrq   )rK  r»   ÚstandardizedÚsubtracts       r   rc  ÚClusterGrid.standard_scaleb  sg   € ð( �1‹9Ø!‰Là!Ÿ8™8ˆLà×#Ñ#Ó%ˆØ$Ñ/Ø×ÑÓ ×!1Ñ!1Ó!3Ñ3ñ5ˆð �1‹9ØÐà—>‘>Ð!r   c                 ó¬   • U/nUb0  [         R                  " U5      S:”  a  [        U5      nOSnXEU-  /-  nUR                  S[	        U5      -
  5        U$ )z8Get the proportions of the figure taken up by each axes.ra   r   )r-   ÚndimrD   ÚappendÚsum)rV   r$   rd  re  ÚratiosÚn_colorss         r   rS  ÚClusterGrid.dim_ratios„  sY   € à"Ð#ˆàÑä�wŠw�v‹ Ó"Ü˜v›;‘à�à ,Ñ.Ð/Ñ/ˆFð 	�‰�aœ#˜f›+‘oÔ&àˆr   c                 ój  ^•  [         R                  R                  U S   5        S[        U 5      snmU /n 0 n[        R                  " UT4[        5      n[        U 5       H9  u  pg[        U5       H%  u  p‰UR                  U	[        U5      5      n
X¥Xh4'   M'     M;     USS2U4   nUS:X  a  UR                  n[         R                  R                  [        U5      5      nX[4$ ! [         aE    [        U 5      [        U S   5      snm[        U4S jU SS  5       5      (       d  [	        S5      e Nûf = f)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   ó@   >#   • U  H  n[        U5      T:H  v •  M     g 7f)N)rD   )Ú.0Úcr©   s     €r   Ú	<genexpr>Ú<ClusterGrid.color_list_to_matrix_and_cmap.<locals>.<genexpr>³  s   øé € Ð7ªJ q”s˜1“v –{ªJùs   ƒNz/Multiple side color vectors must have same size)r#   r$   r%   rD   r'   Úallr-   r.   rC   Ú	enumeraterÑ   rÿ   rm   r&   )r$   Úindr»   rž   Úunique_colorsÚmatrixr    ÚinnerÚjr‡   ÚidxrY   r©   s               @r   Úcolor_list_to_matrix_and_cmapÚ)ClusterGrid.color_list_to_matrix_and_cmap–  s%  ø€ ð0
	Ü�J‰J×Ñ˜f Q™iÔ(ð ”c˜&“kˆDˆAˆqØ�XˆFð ˆÜ—’˜1˜a˜&¤#Ó&ˆÜ! &Ö)‰HˆAÜ% eÖ,‘�Ø#×.Ñ.¨u´c¸-Ó6HÓI�Ø"�q�t“ó -ñ *ð š˜3˜‘ˆØ�1‹9Ø—X‘XˆFä�z‰z×(Ñ(¬¨mÓ)<Ó=ˆØˆ|Ðøô1 ó 	Tä�v“;¤ F¨1¡I£ˆDˆAˆqÜÔ7¨F°1°2©JÓ7×7Ñ7Ü Ð!RÓSÐSñ 8ð	Tús   ƒ"C# Ã#AD2Ä1D2c                 óò  • U(       a*  [        U R                  X4SSU R                  SUUS9	U l        O6U R                  R	                  / 5        U R                  R                  / 5        U(       a)  [        U R                  X4SSU R                  UUS9U l        O6U R                  R	                  / 5        U R                  R                  / 5        [        U R                  SSS9  [        U R                  SSS9  g )NFr   T)r  r  r  r»   r–   r  r  r6  r   )r  r  r  r»   r–   r  r6  r/  )	r  rK  rW  r_  Ú
set_xticksÚ
set_yticksrX  r`  r
   )rV   Úrow_clusterÚcol_clusterr  r  Úrow_linkageÚcol_linkager6  s           r   Úplot_dendrogramsÚClusterGrid.plot_dendrogramsÊ  sÔ   € ö Ü",Ø—‘ FÀÈQØ×)Ñ)°$ÀØ!ñ#ˆDÕð ×"Ñ"×-Ñ-¨bÔ1Ø×"Ñ"×-Ñ-¨bÔ1æÜ",Ø—‘ FÀØ˜4×1Ñ1¸;Ø!ñ#ˆDÕð ×"Ñ"×-Ñ-¨bÔ1Ø×"Ñ"×-Ñ-¨bÔ1Ü�4×)Ñ)°$¸TÒBÜ�4×)Ñ)°$¸TÓBr   c           	      óZ  • UR                  5       nUR                  SS5        UR                  SS5        UR                  SS5        UR                  SS5        UR                  SS5        UR                  SS5        UR                  SS5        UR                  S	S5        UR                  S
S5        U R                  bˆ  U R                  U R                  USS9u  pEU R                  b  U R                  nOSn[        U4USU R                  USS.UD6  USLa-  [        R                  " U R                  R                  5       SS9  O[        U R                  SSS9  U R                  b­  U R                  U R                  USS9u  pEU R                  b  U R                  nOSn[        U4USU R                  SUS.UD6  USLaR  U R                  R                  R                  5         [        R                  " U R                  R!                  5       SS9  gg[        U R                  SSS9  g)zƒPlots color labels between the dendrogram and the heatmap

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

rY   NrÈ   rZ   rO   rW   rX   r[   rF   rJ   r   rE  F)rY   rT   r–   rF   rJ   éZ   rÍ   T)rÆ   rÇ   r   )rR   r0  rN  r™  rO  r   rZ  rÜ   rÝ   Úget_xticklabelsr
   rP  rQ  r[  r·   Ú
tick_rightÚget_yticklabels)rV   ÚxindÚyindrß   r•  rY   rO  rQ  s           r   Úplot_colorsÚClusterGrid.plot_colorsã  s  € ð �h‰h‹jˆØ�‰�˜ÔØ�‰�˜ÔØ�‰�˜$ÔØ�‰�˜ÔØ�‰�˜ÔØ�‰�˜ÔØ�‰�˜$ÔØ�‰�˜tÔ$Ø�‰�˜tÔ$ð �?‰?Ñ&Ø×=Ñ=Ø—‘ ¨Að >ð /‰LˆFð ×$Ñ$Ñ0Ø#'×#8Ñ#8Ñ à#(Ð ä�Fð L ¨E°d×6HÑ6HØ 0¸eñLØGJòLð   uÒ,Ü—’˜×+Ñ+×;Ñ;Ó=ÈÒKøä�D×&Ñ&¨T¸$Ò?ð �?‰?Ñ&Ø×=Ñ=Ø—‘ ¨Að >ð /‰LˆFð ×$Ñ$Ñ0Ø#'×#8Ñ#8Ñ à#(Ð ä�Fð L ¨E°d×6HÑ6HØ %Ð3CñLØGJòLð   uÒ,Ø×"Ñ"×(Ñ(×3Ñ3Ô5Ü—’˜×+Ñ+×;Ñ;Ó=ÈÓJð -ô �D×&Ñ&¨T¸$Ó?r   c                 ó  • U R                   R                  X24   U l         U R                  R                  X24   U l        UR                  SS5      n [        R
                  " U5      U   nUR                  SS5      n [        R
                  " U5      U   nUR                  SS 5      nUb  USL a  Ov[        U[        5      (       a  U R                   nOR[        R
                  " U5      nUR                  U R                   R                  :w  a  Sn	[        U	5      eXƒ   S S 2U4   nUnUR                  SU R                  S L5        [        U R                   4U R                  U R                  XR                  XVUS.UD6  U R                  R!                  5       nU(       d  S OUS	   R#                  5       n
U R                  R$                  R'                  S
5        U R                  R$                  R)                  S
5        U
b.  U R                  R!                  5       n[*        R,                  " XjS9  [/        SSS9nU R                  c  U R0                  R2                  " S0 UD6  g U R                  R5                  5         U R0                  R2                  " S0 UD6  U R                  R7                  5         U R                  R9                  U R:                  5        g ! [        [        4 a     GNƒf = f! [        [        4 a     GNnf = f)NrF   r=   rJ   rO   Fr?   rT   )r–   rï   rU   r6   rF   rJ   rO   r   r.  rÍ   ç{®Gáz”?)Úh_padÚw_padrë   )rK  Úilocr6   r0  r-   r@   rR  Ú
IndexErrorr   r0   r/   r'   rÑ   r]  r   r\  r¨  Úget_rotationr·   r2  Úset_label_positionrÜ   rÝ   r“   rL  Útight_layoutrY  Úset_axis_onÚset_positionr^  )rV   Úcolorbar_kwsr©  rª  rß   rá   râ   rO   rP   r7   Úytl_rotÚtight_paramss               r   Úplot_matrixÚClusterGrid.plot_matrix$  sz  € Ø—k‘k×&Ñ& 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 §¡¸¿¹Ø%¯I©IØ¸ñ	FàADò	Fð �o‰o×-Ñ-Ó/ˆÞ!‘$ s¨1¡v×':Ñ':Ó'<ˆØ�‰×Ñ×0Ñ0°Ô9Ø�‰×Ñ×0Ñ0°Ô9ØÑØ—/‘/×1Ñ1Ó3ˆCÜ�HŠH�SÒ+ä #¨SÑ1ˆØ�<‰<ÑØ�L‰L×%Ò%Ñ5¨Ó5ð
 �L‰L×%Ñ%Ô'Ø�L‰L×%Ò%Ñ5¨Ò5Ø�L‰L×$Ñ$Ô&Ø�L‰L×%Ñ% d§m¡mÕ4øô_ œ:Ð&ó 	Úð	ûô
 œ:Ð&ó 	Úð	ús$   ÁK Á>K2 ËK/Ë.K/Ë2LÌLc	           
      óV  • U	R                  SS5      (       a)  Sn
[        R                  " U
5        U	R                  S5        Uc  0 OUnU R	                  XEXXgUS9   U R
                  R                  n U R                  R                  nU R                  " X¼40 U	D6  U R                  " X;U40 U	D6  U $ ! [         a0    [        R                  " U R                  R                  S   5      n Nyf = f! [         a0    [        R                  " U R                  R                  S   5      n NŸf = f)Nrð   Fz%``square=True`` ignored in clustermap)r   r¡  r6  r   r   )rÐ   r   r!  r0  r¢  r`  r	  ÚAttributeErrorr-   rŒ   rK  r/   r_  r«  r»  )rV   r  r  r¸  rž  rŸ  r   r¡  r6  rß   r"  r©  rª  s                r   rã   Ú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ð 	×Ò˜Ñ+ sÒ+Ø×Ò˜¨TÑ9°SÒ9Øˆøô ó 	3Ü—9’9˜TŸ[™[×.Ñ.¨qÑ1Ó2ŠDð	3ûô ó 	3Ü—9’9˜TŸ[™[×.Ñ.¨qÑ1Ó2ŠDð	3ús$   ÁB1 Á2C. Â17C+Ã*C+Ã.7D(Ä'D()rL  r]  r[  rX  r\  rZ  rW  rÞ   r^  rQ  rP  r5   rK  r`  r_  rU  r6   rO  rN  )
NNNNNNNNNN)NN)r   )r   )rå   ræ   rç   rè   r^   rM  rJ  Ústaticmethodrb  rc  rS  r™  r¢  r«  r»  rã   rê   rë   r   r   rB  rB  ¸  s€   † àJNØFJØDHôJ#òX(ðT 48Ø#'ôð( óó ðð: ó"ó ð"òBð$ ó1ó ð1òfCò2?@òB75õrr   rB  )rû   rû   r-  g¸…ëQ¸ž?)r®  gš™™™™™é?gš™™™™™©?g
×£p=
Ç?)ra  r  r  rb  rc  rD  rU   rž  rŸ  r   r¡  rN  rP  r6   rd  re  r^  r6  c                ó|   • [         (       a  [        S5      e[        XUXÍXEXïUUS9nUR                  " SX2UX‰X«US.UD6$ )aì  
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)
ra  rD  rN  rP  rb  rc  r6   rd  re  r^  )r  r  r¸  rž  rŸ  r   r¡  r6  rë   )r?  r@  rB  rã   )r5   ra  r  r  rb  rc  rD  rU   rž  rŸ  r   r¡  rN  rP  r6   rd  re  r^  r6  rö   r÷   s                        r   r   r   z  sc   € ÷N ‚yÜÐFÓGÐGä˜$¸WØ%/Ø")Ø#Ø'3¸hñ	H€Gð �<Š<ð 5˜vØ%-Ø$/Ø$/Ø!)ñ	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  rB  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   ¦B< Â<CÃC