§
    à©ºj$  ã                  óÆ   — U d Z ddlmZ ddlmZ ddlmZ erddlZdZ	dZ
ded	<   d
„ Zdaded<   d8d„Zd9d:d„Zd;d<d„Zd=d „Zd>d?d#„Zd$„ Zd@d&„ZdAd*„ZdBdCd0„ZdDd2„Zd3d4œdEd7„ZdS )FzHMatplotlib import helpers, figure utilities, and shared plot primitives.é    )Úannotations)ÚPath)ÚTYPE_CHECKINGNzLmatplotlib is required for plotting. Install with: pip install hotcoco[plot])ÚClsÚLocÚBothÚDupeÚBkgÚMissztuple[str, ...]ÚTIDE_ERROR_ORDERc                 ót   — 	 dd l } dd lm} ddl m} | ||fS # t          $ r t	          t
          ¦  «        d ‚w xY w)Nr   )Úfont_manager)Ú
matplotlibÚmatplotlib.pyplotÚpyplotr   ÚImportErrorÚ
_MPL_ERROR)r   Úpltr   s      úa/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/hotcoco/plot/core.pyÚ_import_mplr      so   € ð0ØÐÐÐØ'Ð'Ð'Ð'Ð'Ð'Ø+Ð+Ð+Ð+Ð+Ð+à˜3 Ð,Ð,øÝð 0ð 0ð 0Ý�*Ñ%Ô%¨4Ð/ð0øøøs   ‚ — 7zlist[str] | NoneÚ_FONT_FAMILYÚreturnú	list[str]c                 óÎ  ‡— t           �t           S t          ¦   «         \  } } }t          t          ¦  «        j        j        dz  }|                     d¦  «        D ]:}	 |j                             t          |¦  «        ¦  «         Œ+# t          $ r Y Œ7w xY wg d¢}	 d„ |j        j
        D ¦   «         Šn# t          $ r t          ¦   «         ŠY nw xY wˆfd„|D ¦   «         }|pdga t           S )NÚ_fontsz*.ttf)zIBM Plex SanszHelvetica NeueúDejaVu Sansc                ó   — h | ]	}|j         ’Œ
S © )Úname)Ú.0Úfs     r   ú	<setcomp>z'_resolve_font_family.<locals>.<setcomp>:   s   € ÐFÐFÐF �Q”VÐFÐFÐFó    c                ó   •— g | ]}|‰v ¯|‘Œ	S r   r   )r    r   Ú	availables     €r   ú
<listcomp>z(_resolve_font_family.<locals>.<listcomp>=   s#   ø€ Ð@Ð@Ð@˜¨d°iÐ.?Ð.?�Ð.?Ð.?Ð.?r#   r   )r   r   r   Ú__file__ÚparentÚglobÚfontManagerÚaddfontÚstrÚ	ExceptionÚttflistÚset)Ú_r   Ú	fonts_dirÚttfÚ	preferredÚresolvedr%   s         @r   Ú_resolve_font_familyr5   '   s  ø€ åÐÝÐå$™œÑ€A€qˆ,Ý•X‘”Ô%Ô,¨xÑ7€IØ�~Š~˜gÑ&Ô&ð ð ˆð	ØÔ$×,Ò,­S°©X¬XÑ6Ô6Ð6Ð6øÝð 	ð 	ð 	ØˆDð	øøøð CÐBÐB€IðØFÐF \Ô%=Ô%EÐFÑFÔFˆ	ˆ	øÝð ð ð Ý‘E”Eˆ	ˆ	ˆ	ðøøøà@Ð@Ð@Ð@ Ð@Ñ@Ô@€HàÐ. ˜€LÝÐs$   Á'BÂ
BÂBÂB/ Â/C
Ã	C
ÚxçìQ¸…ëÁ?Úaxisr,   ÚfracÚfloatÚNonec                ó^  — d„ |D ¦   «         }|sdS t          dt          |¦  «        ¦  «        t          dt          |¦  «        ¦  «        }}||z
  }|dk    rdS ||z  }|dk    r&|                      ||dk     r|ndz
  ||z   ¦  «         dS |                      ||dk     r|ndz
  ||z   ¦  «         dS )u¨  Leave room past the longest bar for its `bar_label` text.

    `bar_label(padding=...)` places the text outside the bar end but does not
    widen the axes, so the label on the longest bar runs into the margin and
    clips. The needed room depends on the rendered width of the digits, which
    changes with the body face â€” this keeps the figures font-independent rather
    than tuned to whichever face is vendored.
    c                ó"   — g | ]}|®||k    ¯
|‘ŒS ©Nr   )r    Úvs     r   r&   z,_headroom_for_bar_labels.<locals>.<listcomp>Q   s!   € Ð<Ð<Ð<�A 1 =°Q¸!²V°Vˆa°V°V°Vr#   Ng        r   r6   )ÚminÚmaxÚset_xlimÚset_ylim)	ÚaxÚvaluesr8   r9   ÚfiniteÚloÚhiÚspanÚpads	            r   Ú_headroom_for_bar_labelsrK   H   sÔ   € ð =Ð<˜Ð<Ñ<Ô<€FØð ØˆÝ�•c˜&‘k”kÑ"Ô"¥C¨­S°©[¬[Ñ$9Ô$9ˆ€BØ�‰7€DØˆq‚y€yØˆØ
�‰+€CØˆs‚{€{Ø
�Š�B  a¢ ˜#˜#¨QÑ/°°c±Ñ:Ô:Ð:Ð:Ð:à
�Š�B  a¢ ˜#˜#¨QÑ/°°c±Ñ:Ô:Ð:Ð:Ð:r#   ÚconstrainedÚfigsizeútuple[float, float]Úlayoutú
str | Nonec                óx   — t          ¦   «         \  }}}|�	|j        |fS |                     | |¬¦  «        \  }}||fS )N)rM   rO   )r   ÚfigureÚsubplots)rM   rD   rO   r0   r   Úfigs         r   Ú_new_figurerU   _   sD   € Ý‘”�I€A€sˆAØ	€~ØŒy˜"ˆ}ÐØ�lŠl 7°6ˆlÑ:Ô:�G€CˆØ�ˆ7€Nr#   ÚtitleÚsubtitlec                óæ  — ddl }| j        }d}d}|                     ¦   «         }|dz  |z  }|dz  |z  }	d}
d}d|z
  |
z
  }||	z
  |z
  }|                     ¦   «         }|�+t	          |d	¦  «        r|                     ddd
|g¬¦  «         n|                     |dz
  ¬¦  «         |                     ||dd¬¦  «         |                     d||dd|d|j	         
                    dd¦  «        ¬¦  «         dS )zUPosition a suptitle + subtitle above the axes, reserving space so they never overlap.r   Né   é	   éH   g{®Gázt?gü©ñÒMb€?g\�Âõ(\ï?r/   é   )Úrectg{®Gáz”?)Útopi¼  )ÚfontsizeÚ
fontweightÚyg      à?Úcenterr^   i�  zaxes.labelcolorz#666)ÚhaÚvar_   r`   Úcolor)r   rR   Úget_figheightÚget_layout_engineÚhasattrr/   Úsubplots_adjustÚsuptitleÚtextÚrcParamsÚget)rD   rV   rW   Ú_mplrT   Ú
title_sizeÚsub_sizeÚhÚ
title_fracÚsub_fracÚ	inter_gapÚ
bottom_padÚ
subtitle_yÚaxes_topÚengines                  r   Ú_place_title_and_subtitlery   g   sC  € àÐÐÐà
Œ)€CØ€JØ€HØ×ÒÑÔ€Að ˜b‘ 1Ñ$€JØ˜"‰}˜qÑ €HØ€IØ€Jà˜
Ñ" YÑ.€JØ˜HÑ$ zÑ1€Hð ×"Ò"Ñ$Ô$€FØÐ�g f¨eÑ4Ô4ÐØ�
Š
˜˜A˜q (Ð+ˆ
Ñ,Ô,Ð,Ð,à×Ò ¨4¡ÐÑ0Ô0Ð0à‡L‚L� ¸¸t€LÑDÔDÐDØ‡H‚HØØØØØØØØŒm×ÒÐ 1°6Ñ:Ô:ð ñ 	ô 	ð 	ð 	ð 	r#   ra   Ú
value_axisc                óÜ  — |dk    rL| j                              d¦  «         | j                             d¦  «         |                      dd¬¦  «         ng|dk    rL| j                             d¦  «         | j                              d¦  «         |                      dd¬¦  «         n|                      d¦  «         |r0|rt	          | ||¦  «         dS |                      |ddd	¬
¦  «         dS dS )zJSet grid direction, title, and subtitle. Colors come from active rcParams.ra   TFr6   r   )r8   Úlengthé   iô  é
   )r_   r`   rJ   N)ÚyaxisÚgridÚxaxisÚtick_paramsry   Ú	set_title)rD   rV   rW   rz   s       r   Ú_configure_axesr„   �   sÿ   € à�SÒÐØ
Œ�Š�dÑÔÐØ
Œ�Š�eÑÔÐØ
�Š˜C¨ˆÑ*Ô*Ð*Ð*Ø	�sÒ	Ð	Ø
Œ�Š�dÑÔÐØ
Œ�Š�eÑÔÐØ
�Š˜C¨ˆÑ*Ô*Ð*Ð*à
�Š�‰Œˆàð EØð 	EÝ% b¨%°Ñ:Ô:Ð:Ð:Ð:à�LŠL˜¨¸ÀˆLÑDÔDÐDÐDÐDð	Eð Er#   c                ó~   — |�8|                       t          |¦  «        dd|                      ¦   «         ¬¦  «         | |fS )NéÈ   Útight)ÚdpiÚbbox_inchesÚ	facecolor)Úsavefigr,   Úget_facecolor)rT   rD   Ú	save_paths      r   Ú_save_and_returnrŽ   £   s=   € ØÐØ�Š•C˜	‘N”N¨¸ÈC×L]ÒL]ÑL_ÔL_ˆÑ`Ô`Ð`Ø�ˆ7€Nr#   ú'np.ndarray'c                óR   — ddl }|                      ¦   «         }|j        ||dk     <   |S )zDReturn a copy of arr with COCO sentinel values (-1) replaced by NaN.r   N)ÚnumpyÚcopyÚnan)ÚarrÚnpÚouts      r   Ú_mask_invalid_precr—   ©   s/   € àÐÐÐà
�(Š(‰*Œ*€CØ”6€CˆˆaŠ�LØ€Jr#   ÚcurvesÚdictú,'tuple[np.ndarray, list[float], np.ndarray]'c                ó  — ddl } |j        | d         t          ¬¦  «        }t          d„ |                      ¦   «         D ¦   «         d„ ¬¦  «        }d„ |D ¦   «         }t           |j        d	„ |D ¦   «         t          ¬¦  «        ¦  «        }|||fS )
uñ  Unpack ``report()["curves"]`` into ``(rec_thrs, iou_thrs, precision)``.

    ``precision`` has shape ``(T, R)``, one aggregate curve per IoU threshold in
    ascending threshold order â€” the curve keys are ``"pr@0.50"`` â€¦ ``"pr@0.95"``,
    and dict order is not threshold order.

    This is the boundary where Rust's ``-1.0`` sentinel ("not computed for this
    configuration") becomes NumPy's own missing value, NaN. Every renderer of
    these curves crosses that boundary here, once.
    r   NÚrec_thrs)Údtypec              3  ó’   K  — | ]B\  }}|                      d ¦  «        ¯t          |t          d ¦  «        d…         ¦  «        |fV — ŒCdS )zpr@N)Ú
startswithr:   Úlen)r    ÚkeyrE   s      r   ú	<genexpr>z!_report_curves.<locals>.<genexpr>Á   sW   è è € ÐgÐg±°°VÐQT×Q_ÒQ_Ð`eÑQfÔQfÐg�%�•C˜‘J”J�L�LÔ!Ñ
"Ô
" FÐ	+ÐgÐgÐgÐgÐgÐgr#   c                ó   — | d         S )Nr   r   )Úitems    r   ú<lambda>z _report_curves.<locals>.<lambda>Â   s
   € ˜˜aœ€ r#   )r¡   c                ó   — g | ]\  }}|‘ŒS r   r   )r    Úthrr0   s      r   r&   z"_report_curves.<locals>.<listcomp>Ä   s   € Ð*Ð*Ð*™˜˜Q�Ð*Ð*Ð*r#   c                ó   — g | ]\  }}|‘ŒS r   r   )r    r0   rE   s      r   r&   z"_report_curves.<locals>.<listcomp>Å   s   € Ð.OÐ.OÐ.O¹)¸!¸V¨vÐ.OÐ.OÐ.Or#   )r‘   Úasarrayr:   ÚsortedÚitemsr—   )r˜   r•   rœ   ÚorderedÚiou_thrsÚ	precisions         r   Ú_report_curvesr¯   ²   s®   € ð ÐÐÐàˆrŒz˜& Ô,µEÐ:Ñ:Ô:€HÝØgÐg¸v¿|º|¹~¼~ÐgÑgÔgØ Ð ðñ ô €Gð +Ð* 'Ð*Ñ*Ô*€HÝ" : 2¤:Ð.OÐ.OÀwÐ.OÑ.OÔ.OÕW\Ð#]Ñ#]Ô#]Ñ^Ô^€IØ�X˜yÐ(Ð(r#   Ún_catsÚintÚtop_nú
int | Noneú'list[int] | None'c                óP  — ddl }|€|dk    rd}|�||k    rdS | d|…d|…f         } |j        |¦  «        }|                     d¬¦  «        |z
  |                     d¬¦  «        |z
  z   } |j        |¦  «        ddd…         d|…         }t	          d„ |D ¦   «         ¦  «        |gz   S )	a¹  Pick which confusion-matrix rows/columns to keep, by off-diagonal mass.

    *matrix* is the full ``(K + 1, K + 1)`` matrix, BG last. Returns the kept
    category indices in ascending order with the BG index appended, or ``None``
    when everything fits and the caller should not subset at all.

    ``top_n=None`` means "decide for me": above 30 categories a full matrix is
    unreadable, so it falls back to the 25 worst offenders.
    r   Né   é   r\   )r8   éÿÿÿÿc              3  ó4   K  — | ]}t          |¦  «        V — Œd S r>   )r±   )r    Úis     r   r¢   z&_top_confusion_keep.<locals>.<genexpr>Þ   s(   è è € Ð.Ð.˜Q•#�a‘&”&Ð.Ð.Ð.Ð.Ð.Ð.r#   )r‘   ÚdiagÚsumÚargsortrª   )Úmatrixr°   r²   r•   Ú	cat_blockr»   Úconfusion_massÚtop_indicess           r   Ú_top_confusion_keeprÂ   É   sÕ   € ð ÐÐÐà€}˜ "š˜ØˆØ€}˜ š˜Øˆtà�w˜�w   Ð'Ô(€IØˆ2Œ7�9ÑÔ€DØ—m’m¨�mÑ+Ô+¨dÑ2°y·}²}È!°}Ñ7LÔ7LÈtÑ7SÑT€NØ�"”*˜^Ñ,Ô,¨T¨T¨r¨TÔ2°6°E°6Ô:€KÝÐ.Ð. +Ð.Ñ.Ô.Ñ.Ô.°&°Ñ9Ð9r#   ú'tuple[int, float] | None'c                óì   — ddl }d|z  | z   |j        || z   d¦  «        z  } |j         |j        |¦  «        ¦  «        rdS t	           |j        |¦  «        ¦  «        }|t          ||         ¦  «        fS )z¼Return ``(index, f1)`` at the peak F1 of a PR curve, or ``None``.

    NaN precision entries (the -1 sentinel, already masked) are skipped; the
    index is into the arrays as passed.
    r   Né   g:Œ0âŽyE>)r‘   ÚmaximumÚallÚisnanr±   Ú	nanargmaxr:   )Ú
recall_ptsÚprecr•   Úf1Úbests        r   Ú_f1_peakrÎ   á   s‡   € ð ÐÐÐà	
ˆT‰�JÑ	  ¤¨D°:Ñ,=¸tÑ!DÔ!DÑ	D€BØ€r„vˆhˆbŒh�r‰lŒlÑÔð ØˆtÝˆ|ˆrŒ|˜BÑÔÑ Ô €DØ•�r˜$”x‘”Ð Ð r#   T)ÚfillrÏ   Úboolc               óX  — |                      ¦   «         }|r|                      ||d|¬¦  «         t          ||¦  «        }|€dS |\  }}||         dk    rU|                      ||         ||         d|dd¬¦  «         |                      d|d	›�||         ||         fd
dd¬¦  «         dS dS )a4  Mark the F1 peak of a PR curve, optionally filling the area under it.

    ``fill=False`` for a multi-curve plot. The fill runs from the curve down to
    zero, so under the topmost curve of a sweep it tints every other curve's
    area as well and washes the whole plot rather than delimiting anything.
    g333333Ã?)Úalphare   Nr   Úoé   )re   Ú
markersizeÚzorderzF1=z.2fzoffset points)rÔ   rÔ   é   )Ú
textcoordsÚxytextr_   )Ú	get_colorÚfill_betweenrÎ   ÚplotÚannotate)	rD   rÊ   rË   ÚlinerÏ   re   ÚpeakrÍ   Úf1_vals	            r   Ú_annotate_f1_peakrá   ð   sß   € ð �NŠNÑÔ€EØð CØ
�Š˜
 D°¸EˆÑBÔBÐBÝ�J Ñ%Ô%€DØ€|ØˆØ�L€Dˆ&ØˆD„z�A‚~€~Ø
�Š�
˜4Ô  $ t¤*¨c¸È1ÐUVˆÑWÔWÐWØ
�ŠØ�&ÐÐÐ ¨DÔ!1°4¸´:Ð >È?ÐciÐtuð 	ñ 	
ô 	
ð 	
ð 	
ð 	
ð €~r#   )r   r   )r6   r7   )r8   r,   r9   r:   r   r;   )NrL   )rM   rN   rO   rP   )rV   r,   rW   r,   r   r;   )NNra   )rV   rP   rW   rP   rz   rP   )r   r�   )r˜   r™   r   rš   r>   )r°   r±   r²   r³   r   r´   )r   rÃ   )rÏ   rÐ   )Ú__doc__Ú
__future__r   Úpathlibr   Útypingr   r‘   r•   r   r   Ú__annotations__r   r   r5   rK   rU   ry   r„   rŽ   r—   r¯   rÂ   rÎ   rá   r   r#   r   ú<module>rç      s£  ðØ NÐ NÐ Nà "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  àð ð ÐÐÐà[€
ð
 %RÐ Ð QÐ QÐ QÑ Qð0ð 0ð 0ð "&€Ð %Ð %Ð %Ñ %ðð ð ð ðB;ð ;ð ;ð ;ð ;ð.ð ð ð ð ð%ð %ð %ð %ðPEð Eð Eð Eð Eð(ð ð ðð ð ð ð)ð )ð )ð )ð.:ð :ð :ð :ð :ð0!ð !ð !ð !ð CGð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
r#   