
    
3j>                       S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	r	SSK
rSSKrSSKJrJrJrJrJr  SSKJr  SSKJrJrJr  SS	KJrJrJr  SS
KJrJ r   SSK!J"r"J#r#J$r$J%r%J&r&J'r'  \RP                  " \)5      r*\RV                  " SS9S 5       r,S r-S r.\	R^                  " 5       4S jr0\Rb                  \Rd                  " S/SS/S/S/S/S/S/S/S/S/S/S/S.5       " S  S!\5      5       5       r3 " S" S#5      r4 " S$ S%5      r5 " S& S'\3\55      r6\Rb                  Ro                  \6Rp                  R                   S(9  g))z)
Classes for including text in a figure.
    )SequenceN)Real   )_apiartistcbook
_docstringcolors)Artist)FontPropertiesfontManagerget_font)FancyArrowPatchFancyBboxPatch	Rectangle)TextPath
TextToPath)Affine2DBboxBboxBaseBboxTransformToIdentityTransform	Transform   )maxsizec                 4    [        5       R                  U 5      $ )zG
Return an Affine2D object that rotates by the given angle in radians.
)r   rotate)thetas    I/home/wildlama/miniconda3/lib/python3.13/site-packages/matplotlib/text.py_rotater       s    
 :U##    c                     U S:X  a  X4$ [         R                  " U 5      n[         R                  " U5      [         R                  " U5      pTXA-  XR-  -
  XQ-  XB-  -   4$ )z2
Rotate point (x, y) by rotation angle in degrees
r   )mathradianscossin)anglexy	angle_radr%   r&   s         r   _rotate_pointr+   $   sV     zvU#Ixx	"DHHY$7Gcgsw011r!   c                 F    [        U 5      nU" XR                  5       X45      $ )zECall ``renderer.get_text_width_height_descent``, caching the results.)_get_text_metrics_functioncopy)renderertextfontpropismathdpiget_text_metricss         r   _get_text_metrics_with_cacher5   /   s$    
 2(; D--/6??r!   c                    ^ UR                  U S5      =nc9  [        R                  " U 5      m[        R                  " S5      U4S j5       nX!U '   U$ )a  
Helper function to provide a two-layered cache for font metrics


To get the rendered size of a size of string we need to know:
  - what renderer we are using
  - the current dpi of the renderer
  - the string
  - the font properties
  - is it math text or not

We do this as a two-layer cache with the outer layer being tied to a
renderer instance and the inner layer handling everything else.

The outer layer is implemented as `.WeakKeyDictionary` keyed on the
renderer.  As long as someone else is holding a hard ref to the renderer
we will keep the cache alive, but it will be automatically dropped when
the renderer is garbage collected.

The inner layer is provided by an lru_cache with a large maximum size (such
that we expect very few cache misses in actual use cases).  As the
dpi is mutable on the renderer, we need to explicitly include it as part of
the cache key on the inner layer even though we do not directly use it (it is
used in the method call on the renderer).

This function takes a renderer and returns a function that can be used to
get the font metrics.

Parameters
----------
input_renderer : maplotlib.backend_bases.RendererBase
    The renderer to set the cache up for.

_cache : dict, optional
    We are using the mutable default value to attach the cache to the function.

    In principle you could pass a different dict-like to this function to inject
    a different cache, but please don't.  This is an internal function not meant to
    be reused outside of the narrow context we need it for.

    There is a possible race condition here between threads, we may need to drop the
    mutable default and switch to a threadlocal variable in the future.

Ni   c                 R   > T" 5       =nc  [        S5      eUR                  XU5      $ )Nz~Trying to get text metrics for a renderer that no longer exists.  This should never happen and is evidence of a bug elsewhere.)RuntimeErrorget_text_width_height_descent)r0   r1   r2   r3   local_rendererrenderer_refs        r   _text_metrics1_get_text_metrics_function.<locals>._text_metricsr   s;    
 #/.09"S 
 "??PVWWr!   )getweakrefref	functools	lru_cache)input_renderer_cacher<   r;   s      @r   r-   r-   >   s_    Z  ND99B {{>2 
		T	"		X 
#		X "/~ r!   cfontfont_propertiesfamilynamesizestretchstylevariantweighthavama)colorfontproperties
fontfamilyfontnamefontsizefontstretch	fontstylefontvariant
fontweighthorizontalalignmentverticalalignmentmultialignmentc                     ^  \ rS rSrSrSr\" 5       rS r S\SSSSSSSSSSSSSS	.U 4S
 jjjr	              S]S jr
U 4S jrU 4S jrS rS rS rS rS rS rS rS rS rS rU 4S jrS rS rS rS rS rU 4S jrS^U 4S jjrU 4S  jrS! r S" r!S# r"S$ r#S% r$S& r%\&RN                  S' 5       r(S( r)S) r*S* r+S+ r,S, r-S- r.S. r/S/ r0S0 r1S1 r2S2 r3S3 r4S4 r5S5 r6S6 r7S_S7 jr8S^U 4S8 jjr9S9 r:S: r;S; r<S< r=S= r>S> r?S? r@S@ rASA rBSB rCSC rDSD rESE rFSF rGSG rHSH rISI rJSJ rKSK rLSL rMSM rNSN rOSO rPSP rQ\RR                  " SQ5      SR 5       rTSS rUST rVSU rWSV rXSW rYSX rZSY r[SZ r\S[r]U =r^$ )`Text   zAHandle storing and drawing of text in window or data coordinates.   c                 X    SU R                    SU R                   SU R                  < S3$ )NzText(, ))_x_y_textselfs    r   __repr__Text.__repr__   s)    twwir$''"TZZN!<<r!   NbaselineleftF)rR   r\   r[   r]   rS   rotationlinespacingrotation_modeusetexwraptransform_rotates_text
parse_mathantialiasedc                   > [         TU ]  5         XsU l        U l        SU l        SU l        U R                  S5        U R                  UUUUUUUUUU	UU
UUS9  U R                  U5        g)a  
Create a `.Text` instance at *x*, *y* with string *text*.

The text is aligned relative to the anchor point (*x*, *y*) according
to ``horizontalalignment`` (default: 'left') and ``verticalalignment``
(default: 'baseline'). See also
:doc:`/gallery/text_labels_and_annotations/text_alignment`.

While Text accepts the 'label' keyword argument, by default it is not
added to the handles of a legend.

Valid keyword arguments are:

%(Text:kwdoc)s
 N)r0   rR   rS   rq   rt   rr   r\   r[   r]   rn   rs   ro   rp   ru   )	super__init__re   rf   rg   	_featuresset_language_reset_visual_defaultsupdate)ri   r(   r)   r0   rR   r\   r[   r]   rS   rn   ro   rp   rq   rr   rs   rt   ru   kwargs	__class__s                     r   ry   Text.__init__   s    @ 	
$##)!/ 3)#9#'# 	$ 	
  	Fr!   c                 X   U R                  U5        U R                  [        R                  " US5      5        U R	                  U5        U R                  U5        U R                  [        R                  " US5      5        U R                  U5        U R                  U5        U R                  U5        Xl
        U R                  U
5        Xl        S U l        S U l        Uc  SnU R                  U5        U R!                  U5        U R#                  [        R                  " US5      5        g )Nz
text.colorztext.parse_mathnormalztext.antialiased)set_text	set_colormpl
_val_or_rcset_fontproperties
set_usetexset_parse_mathset_wrapset_verticalalignmentset_horizontalalignment_multialignmentset_rotation_transform_rotates_text_bbox_patch	_rendererset_linespacingset_rotation_modeset_antialiased)ri   r0   rR   rS   rq   rt   rr   r\   r[   r]   rn   rs   ro   rp   ru   s                  r   r|   Text._reset_visual_defaults   s    " 	ds~~e\:;/CNN:7HIJd""#45$$%89-(#'=$"K[)}-S^^K9KLMr!   c                 j  > / n[         R                  " U[        5      n[        5       nUR	                  SU5      nXCLa   UR                  U R                  U5      5        UR	                  SU5      nUR                  [        TU ]%  U5      5        XSLa   UR                  U R                  U5      5        U$ )NrS   bbox)r   normalize_kwargsr_   objectpopappendr   extendrx   r}   set_bbox)ri   r~   retsentinelrS   r   r   s         r   r}   Text.update   s    ''58$4h?)JJt..~>?zz&(+

57>&)*JJt}}T*+
r!   c                 .   > [         TU ]  5       nS US'   U$ )Nr   )rx   __getstate__)ri   dr   s     r   r   Text.__getstate__	  s    G "+r!   c                    U R                  U5      (       d"  U R                  5       (       a  U R                  c  S0 4$ [        R	                  U 5      nUR
                  UR                  s=:*  =(       a    UR                  :*  Os  =(       a3    UR                  UR                  s=:*  =(       a    UR                  :*  Os  n0 nU R                  (       a,  U R                  R                  U5      u  pVU=(       d    UnXdS'   X44$ )z[
Return whether the mouse event occurred inside the axis-aligned
bounding-box of the text.
F
bbox_patch)_different_canvasget_visibler   r_   get_window_extentx0r(   x1y0r)   y1r   contains)ri   
mouseeventr   insidecattrpatch_insidepatch_cattrs          r   r   Text.contains  s    
 "":..d6F6F6H6H>>)"9 %%d+''Z\\44TWW4 9gg888 	 (,(8(8(A(A*(M%L+|F"-,}r!   c                 f    U R                  5       u  pU R                  5       R                  X45      $ )zG
Get the (possibly unit converted) transformed x, y in display coords.
)get_unitless_positionget_transform	transformri   r(   r)   s      r   _get_xy_displayText._get_xy_display&  s0     ))+!!#--qf55r!   c                 L    U R                   b  U R                   $ U R                  $ N)r   _horizontalalignmentrh   s    r   _get_multialignmentText._get_multialignment-  s&    +''',,,r!   c                    U R                   (       d  gU R                   n[        U R                  5      nU[        R                  ;  a  [        5       [        R                  U'   [        R                  U   n[        U5       HF  nXT;  d  M
  U R                  U5        U R                  5       nUR                  UR                  -
  XE'   MH     U R                  U5        U R                  5       n[        R                  " S/U Vs/ s H  oU   PM	     sn-   5      nWUR                  -
  n[        R                  " Xx-
  5      R                  5       $ s  snf )z
Calculate the index closest to the coordinate x in display space.

The position of text[index] is assumed to be the sum of the widths
of all preceding characters text[:index].

This works only on single line texts.
r   )rg   str_fontpropertiesr_   _charsize_cachedictsetr   r   r   r   npcumsumabsargmin)	ri   r(   r0   rS   charsize_cachecharbb
size_accumstd_xs	            r   _char_index_atText._char_index_at3  s
    zzzzT112!5!55376D  0--n=ID)d#++-')uuruu}$	  	d##%YYs%FAQ&7%FFG
BEE	z)*2244 &Gs   E
c                     U R                  5       (       aL  U R                  5       R                  U R                  /U R	                  5       /5      R                  S5      S-  $ U R                  $ )z7Return the text angle in degrees in the range [0, 360).r   h  )get_transform_rotates_textr   transform_angles	_rotationr   itemrh   s    r   get_rotationText.get_rotationS  sd    **,,%%'88 4#=#=#?"@BBF$q'CP P >>!r!   c                     U R                   $ )zF
Return whether rotations of the transform affect the text direction.
)r   rh   s    r   r   Text.get_transform_rotates_text[  s     +++r!   c                 T    Uc  SnO[         R                  " SUS9  Xl        SU l        g)aF  
Set text rotation mode.

Parameters
----------
m : {None, 'default', 'anchor', 'xtick', 'ytick'}
    If ``"default"``, the text will be first rotated, then aligned according
    to their horizontal and vertical alignments.  If ``"anchor"``, then
    alignment occurs before rotation. "xtick" and "ytick" adjust the
    horizontal/vertical alignment so that the text is visually pointing
    towards its anchor point. This is primarily used for rotated tick
    labels and positions them nicely towards their ticks. Passing
    ``None`` will set the rotation mode to ``"default"``.
Ndefault)anchorr   xtickytick)rp   T)r   check_in_list_rotation_modestale)ri   ms     r   r   Text.set_rotation_modea  s-     9AFVWX
r!   c                     U R                   $ )zReturn the text rotation mode.)r   rh   s    r   get_rotation_modeText.get_rotation_modew  s    """r!   c                     Xl         SU l        g)z
Set whether to use antialiased rendering.

Parameters
----------
antialiased : bool

Notes
-----
Antialiasing will be determined by :rc:`text.antialiased`
and the parameter *antialiased* will have no effect if the text contains
math expressions.
TN)_antialiasedr   )ri   ru   s     r   r   Text.set_antialiased{  s     (
r!   c                     U R                   $ )z-Return whether antialiased rendering is used.)r   rh   s    r   get_antialiasedText.get_antialiased         r!   c                   > [         TU ]  U5        UR                  U l        UR                  U l        UR                  U l        UR
                  U l        UR                  R                  5       U l        UR                  U l        UR                  U l	        UR                  U l
        UR                  U l        UR                  U l        UR                  U l        SU l        g )NT)rx   update_from_colorr   _verticalalignmentr   r   r.   _usetexr   r   _picker_linespacingr   r   )ri   otherr   s     r   r   Text.update_from  s    E"ll$44"'":":$)$>$>!$4499;}}','D'D$}}!..!..
r!   c                    Su  p#U R                  5       R                  S5      n/ n/ n/ nS=n=pU R                  SS9R                  nU R	                  5       (       d  [        US5      (       a  UR                  U R                  5      u  pn
Uc  [        [        R                  " U R                  5      5      nSS/nU Hr  u  pnnUR                  U5      nUc  M  U R                  R                  5       nUR                  S	5      S
   nSU-  U-  U-  S-  nUU   U-  n
UU   U-  nUU   * U-  n	  O   SX4;   a9  [        USU R                  U R	                  5       (       a  SOSUS9u  nnn	UU	-
  nSn
[        U5      S:X  a  Sn
U GH  nU R                  U5      u  nnU(       a3  [        UUU R                  UU R                  SS9R                  S9u  nnnOS=n=nnUU-
  nU R	                  5       (       d  U R                   S:X  a%  [#        UU5      U
S-  -   n[#        UU	5      U
S-  -   nO)U R                   X-   -  nUUU-   -
  nUUS-  -  nUUS-  -  nUU-
  n UU-  nUR%                  UUU45        UR%                  U5        UR%                  U5        UU-  nGM     Wn!U VVVs/ s H	  u  nnnUPM     n"nnn[#        U"5      n#Sn$U#n%Sn&US   U!-
  n'U R'                  5       n(U(S:X  a#  [)        Xg5       V)V*s/ s H
  u  n)n*U)U*4PM     n+n)n*OkU(S:X  a3  [)        XgU"5       V)V*Vs/ s H  u  n)n*nU)U#S-  -   US-  -
  U*4PM     n+n*n)nO2U(S:X  a,  [)        XgU"5       V)V*Vs/ s H  u  n)n*nU)U#-   U-
  U*4PM     n+n*n)nU$U'4U$U&4U%U&4U%U'4/n,U%U$-
  U&U'-
  4n-U R+                  5       n.[,        R.                  " [0        U.5      n/U, V)V*s/ s H  u  n)n*U/" U)U*5      PM     n0n)n*[)        U06 u  pg[3        U5      [#        U5      n%n$[3        U5      [#        U5      n&n'U%U$-
  n1U&U'-
  n2U R4                  n3U R6                  n4U R9                  5       n5U5S:w  a|  U5S:X  a  U R;                  U.5      n3OU5S:X  a  U R=                  U.5      n4U3S:X  a  U$OU3S:X  a  U%OU$U%-   S-  n6U4S:X  a  U'O+U4S:X  a  U&O#U4S:X  a  U'U&-   S-  OU4S:X  a  U'U!-   O
U'U2-   W S-  -
  n7OeU,S   u  n8n9U,S   u  n:n;U3S:X  a  U8OU3S:X  a  U:OU8U:-   S-  n6U4S:X  a  U9O(U4S:X  a  U;O U4S:X  a  U9U;-   S-  OU4S:X  a  U;W -
  OU;W S-  -
  n7U/" U6U75      u  n6n7U$U6-  n$U'U7-  n'[>        R@                  " U$U'U1U25      n<[B        RD                  " U/W+5       V)V*s/ s H  u  n)n*U)U6-
  U*U7-
  4PM     n=n)n*U0S   u  n)n*U)U6-
  U*U7-
  4n>U<[G        [)        XEU=5      5      U>U-44$ s  snnnf s  sn*n)f s  snn*n)f s  snn*n)f s  sn*n)f s  sn*n)f )a#  
Return

- the rotated, axis-aligned text bbox;
- a list of ``(line, (width, ascent, descent), xy)`` tuples for each line;
- a ``(xy, (width, height))` pair of the lower-left corner and size of the
  rotated, *text-aligned* text box (i.e. describing how to draw the
  text-surrounding box).
)        r   
NTroot_get_font_height_metrics)zOS/2sTypoLineGapsTypoAscendersTypoDescender)hhealineGapascentdescenthead
unitsPerEmr   H   lpTeXF)r2   r3   r   r      rm   centerrightr   r   r   bottomtoprl   )$_get_wrapped_textsplit
get_figurer3   
get_usetexhasattrr   r   r   r   _find_fonts_by_propsget_sfnt_tableget_size_in_pointsr5   len_preprocess_mathr   maxr   r   zipr   rA   partialr+   minr   r   r   _ha_for_angle_va_for_angler   from_bounds	itertoolsstarmaplist)?ri   r/   thisxthisylineswadsxsys
min_ascentmin_descentline_gapr3   rF   possible
table_namelinegap_key
ascent_keydescent_keytablerV   units_per_emscale_hline
clean_liner2   wr   aline_heightleadingrl   r  wswidthxminxmaxymaxyminmalignr(   r)   offset_layoutcorners_horiz
size_horizr'   r   corners_rotated	width_rot
height_rothalignvalignrp   offsetxoffsetyxmin1ymin1xmax1ymax1bbox_rotxys	xy_corners?                                                                  r   _get_layoutText._get_layout  s     &&(..t4
 .22
2[oo4o(,,  x!;<< 5=4U4U((5*1
! @ @AUAU VWO< IQDJZ //
;E} #33FFHH#'#6#6v#>|#LL,x7#=BE$[1E9H!&z!2U!:J#(#5"5"=K IQ J,, <$ 4 4 $ 1 1uu!Aq+ [JH u:?HD!%!6!6t!<J6j$*>*>!tD'A'E'EG1a AAA  D$5$5$A :&A5;'(Q,6 #//:3KL%Q/Wq[ Wq[  5yHQJEKKAq	"IIeIIeQJEC H   $$tGAq!at$B"v ))+V03B<1aVM<Mx,/O=,;Aq  %!)ma!e3Q7,;  =Mw,/O=,;Aq  %i!mQ/,;  = d|dD\D$<PTk4$;/
!!#""=%84ABMDAq6!Q<MB o&Wc"gdWc"gd4K	D[
 **((..0H$'++E2')++E2 &(')!  (*%%+x%7!"(J"6wz!HqL0  )+LE5(+LE56)7*!#   8+5'-'9!#$*j$8 1$   &gw7GW##D$	:F %,,V]CEC41a GQ[)C 	 Eq!1[!g+.	c%s34y*6MMMm % === CrEs$   )V-:V4%V:WW'Wc                 b   Ub  UR                  5       nUR                  SS5      nUR                  SS5      nUc  SnUc  SnX@R                  5       -  nOUc  Sn[        U[        5      (       a  SU;  a  USU-  -  n[        SU[        5       S	.UD6U l        OSU l        U R                  5         g)
aV  
Draw a box behind/around the text.

This can be used to set a background and/or a frame around the text.
It's realized through a `.FancyBboxPatch` behind the text (see also
`.Text.get_bbox_patch`). The bbox patch is None by default and only
created when needed.

Parameters
----------
rectprops : dict with properties for `.FancyBboxPatch` or None
     The default boxstyle is 'square'. The mutation
     scale of the `.patches.FancyBboxPatch` is set to the fontsize.

     Pass ``None`` to remove the bbox patch completely.

Examples
--------
::

    t.set_bbox(dict(facecolor='red', alpha=0.5))
Nboxstylepadsquare   g333333?z
,pad=%0.2f)r   r   r   r   )rY  r   )	r.   r   get_size
isinstancer   r   r   r   _update_clip_properties)ri   	rectpropspropsrY  rZ  s        r   r   Text.set_bbox[  s    0  NN$EyyT2H))E4(C#;C}}&;C(C((U(-BL3..-  K!->-@ KDI KD  $D$$&r!   c                     U R                   $ )zv
Return the bbox Patch, or None if the `.patches.FancyBboxPatch`
is not made.

For more details see `.Text.set_bbox`.
)r   rh   s    r   get_bbox_patchText.get_bbox_patch  s     r!   c                    U R                   (       Ga2  [        U R                  U R                  5      5      n[        U R	                  U R
                  5      5      nU R                  5       R                  X#45      u  p#U R                  U5      u    nu  u  pVu  pxU R                   R                  SSXx5        U R                   R                  [        5       R                  U R                  5       5      R                  X%-   X6-   5      5        UR                  U R!                  5       5      n	U R                   R#                  U	5        gg)z
Update the location and the size of the bbox.

This method should be used when the position and size of the bbox needs
to be updated before actually drawing the bbox.
r   N)r   floatconvert_xunitsre   convert_yunitsrf   r   r   rV  
set_boundsset_transformr   
rotate_degr   	translatepoints_to_pixelsr^  set_mutation_scale)
ri   r/   posxposyr6  x_boxy_boxw_boxh_boxfontsize_in_pixels
             r   update_bbox_position_sizeText.update_bbox_position_size  s     ,,TWW56D,,TWW56D++-77EJD595E5Eh5O2Aq2>E>E''B=**
D--/04<68 !) 9 9$--/ J//0AB r!   c                     U R                   (       aE  [        U R                  U R                  U R                  S9nU R                   R                  U5        g g )N)clip_box	clip_pathclip_on)r   r   clipbox	_clippath_cliponr}   )ri   	clippropss     r   r`  Text._update_clip_properties  sD    dll'+~~%)\\3I ##I.	 r!   c                 D   > [         TU ]  U5        U R                  5         g r   )rx   set_clip_boxr`  )ri   r~  r   s     r   r  Text.set_clip_box  s    W%$$&r!   c                 D   > [         TU ]  X5        U R                  5         g r   )rx   set_clip_pathr`  )ri   pathr   r   s      r   r  Text.set_clip_path  s    d.$$&r!   c                 D   > [         TU ]  U5        U R                  5         g r   )rx   set_clip_onr`  )ri   br   s     r   r  Text.set_clip_on  s    A$$&r!   c                     U R                   $ )z'Return whether the text can be wrapped._wraprh   s    r   get_wrapText.get_wrap      zzr!   c                     Xl         g)a  
Set whether the text can be wrapped.

Wrapping makes sure the text is confined to the (sub)figure box. It
does not take into account any other artists.

Parameters
----------
wrap : bool

Notes
-----
Wrapping does not work together with
``savefig(..., bbox_inches='tight')`` (which is also used internally
by ``%matplotlib inline`` in IPython/Jupyter). The 'tight' setting
rescales the canvas to accommodate all content and happens before
wrapping.
Nr  )ri   rr   s     r   r   Text.set_wrap  s	    & 
r!   c                    U R                  5       R                  U R                  5       5      u  pU R                  5       R	                  5       nU R                  5       nU R                  S5        U R                  5       nU R                  XQX#5      nU R                  SU-   S-  XU5      nUS:X  a  UnU$ US:X  a  UnU$ S[        Xg5      -  nU$ )zS
Return the maximum line width for wrapping text based on the current
orientation.
r      r   rm   r  r  )
r   r   get_positionr  r   get_horizontalalignmentr   r   _get_dist_to_boxr  )	ri   r   r   
figure_box	alignmentr'   rm   r  
line_widths	            r   _get_wrap_line_widthText._get_wrap_line_width  s    
 ##%//0A0A0CD__&88:
 002	x(!!#$$U?%%5[C5 J  '!J  S--Jr!   c                    US:  a}  US-
  nX4R                   -
  [        R                  " [        R                  " U5      5      -  nUR                  U-
  [        R                  " [        R                  " SU-
  5      5      -  nGOzUS:  a{  US-
  nX$R
                  -
  [        R                  " [        R                  " U5      5      -  nX4R                   -
  [        R                  " [        R                  " SU-
  5      5      -  nOUS:  a|  US-
  nUR                  U-
  [        R                  " [        R                  " U5      5      -  nX$R
                  -
  [        R                  " [        R                  " SU-
  5      5      -  nOwUR                  U-
  [        R                  " [        R                  " U5      5      -  nUR                  U-
  [        R                  " [        R                  " SU-
  5      5      -  n[        Xg5      $ )zZ
Return the distance from the given points to the boundaries of a
rotated box, in pixels.
i  Z   r  )r   r#   r%   r$   r   r   r   r  )ri   rn   r   r   r  quadh1h2s           r   r  Text._get_dist_to_box  sn   
 c>c>D}}$d1C(DDB--"$b4i1H(IIB^c>D}}$d1C(DDB}}$b4i1H(IIB]b=D--"$d1C(DDB}}$b4i1H(IIB--"$h1G(HHB--"$b8m1L(MMB2{r!   c           
          [        U R                  XR                  5       [        R                  " U5      U R                  SS9R                  5      u  p#n[        R                  " U5      $ )z5
Return the width of a given text string, in pixels.
Tr   )	r5   r   get_fontpropertiesr   is_math_textr  r3   r#   ceil)ri   r0   r:  r7  r   s        r   _get_rendered_text_widthText._get_rendered_text_width
  sV    
 /NND"9"9";t$OOO&**,a yy|r!   c           
      T   U R                  5       (       d  U R                  5       $ U R                  5       (       a  U R                  5       $ U R                  5       n/ nU R                  5       R	                  S5      nU GH  nUR	                  S5      n[        U5      S:  d  M&  [        U5      S:X  a"  UR                  UR                  S5      5        MB  [        S[        U5      S-   5       H  nSR                  USU 5      nU R                  U5      nX:  a/  UR                  SR                  USUS-
   5      5        XVS-
  S n  O:U[        U5      :X  d  Mm  UR                  SR                  USU 5      5        / n  O   [        U5      S:  a  M  GM     SR                  U5      $ )z
Return a copy of the text string with new lines added so that the text
is wrapped relative to the parent figure (if `get_wrap` is True).
r    r   r   r  N)r  get_textr  r  r  r  r   r   rangejoinr  )	ri   r  wrapped_linesunwrapped_linesunwrapped_line	sub_wordsir8  current_widths	            r   r  Text._get_wrapped_text  s   
 }}==?" ??==?" ..0
 --///5 .N&,,S1Ii.1$y>Q&!((q)9:q#i.1"45A88IbqM2D$($A$A$$GM %1%,,SXXiQ6G-HI$-!ef$5	 c)n,%,,SXXim-DE$&	! 6 i.1$$	 .8 yy''r!   c                    Ub  Xl         U R                  5       (       d  g U R                  5       S:X  a  g UR                  SU R	                  5       5        U R                  U5      u  p#nU R                  5       nU R                  U R                  pv[        R                  R                  U5      (       a  [        R                  n[        R                  R                  U5      (       a  [        R                  n[        U R                  U5      5      n[        U R                  U5      5      n	UR!                  X45      u  p[        R"                  " U5      (       d  [        R"                  " U	5      (       a  g [        R$                  " U5      (       a  [        R$                  " U	5      (       d  [&        R)                  S5        g UR+                  5       u  pU R,                  (       a,  U R/                  U5        U R,                  R1                  U5        UR3                  5       nUR5                  [6        R8                  " U R;                  5       5      SS9  UR=                  U R?                  5       5        URA                  U RB                  5        URE                  U RF                  5        URI                  U RK                  5       5        U RM                  U5        U RO                  5       nU H  u  pu  pg[Q        U5      S:X  a  U OS nXh-   nXy-   nURS                  5       (       a  X-
  nU RU                  U5      u  nnU RW                  5       (       a  SSK,J-n  U" U RW                  5       U5      nOUnU R]                  5       (       a   UR_                  XUUU R`                  UUS	9  M  URc                  XUUU R`                  UUUS
9  M     URe                  5         URg                  S5        SU l4        g )Nrw   r0   z%posx and posy should be finite valuesT)isRGBAr   r   )PathEffectRenderer)mtext)r2   r  F)5r   r   r  
open_groupget_gidrV  r   re   rf   r   rQ   	is_maskednanrh  ri  rj  r   isnanisfinite_logwarningget_canvas_width_heightr   rx  drawnew_gcset_foregroundmcolorsto_rgba	get_color	set_alpha	get_alphaset_url_urlr   r   set_snapget_snap_set_gc_clipr   r  flipyr  get_path_effectsmatplotlib.patheffectsr  r  draw_texr   	draw_textrestoreclose_groupr   )ri   r/   r   infor6  transr(   r)   rq  rr  canvaswcanvashgcr'   r8  wadr  r9  r2   r  textrenderers                        r   r  	Text.drawH  s    %N!!==?b FDLLN3((2A""$ ww155??1A55??1AT((+,T((+,__d\2
88D>>RXXd^^{{4  D(9(9LL@A#;;= **84!!(+__
'//$..*:;DI
T^^%&


499
4,,-
DMMO$"!!#!%DvINDEAA~~K!%!6!6t!<J$$&&E1$2G2G2I8T'  %%bQ
&*&:&:E,1 & 3 &&ra'+';';U.4E ' C) "&0 	

V$
r!   c                     U R                   $ )zReturn the color of the text.)r   rh   s    r   r  Text.get_color  s    {{r!   c                     U R                   $ )z*Return the `.font_manager.FontProperties`.)r   rh   s    r   r  Text.get_fontproperties  s    ###r!   c                 6    U R                   R                  5       $ )zs
Return the list of font families used for font lookup.

See Also
--------
.font_manager.FontProperties.get_family
)r   
get_familyrh   s    r   get_fontfamilyText.get_fontfamily       ##..00r!   c                     U R                   $ )z0
Return a tuple of font feature tags to enable.
)rz   rh   s    r   get_fontfeaturesText.get_fontfeatures  s     ~~r!   c                 6    U R                   R                  5       $ )z\
Return the font name as a string.

See Also
--------
.font_manager.FontProperties.get_name
)r   get_namerh   s    r   get_fontnameText.get_fontname  s     ##,,..r!   c                 6    U R                   R                  5       $ )z^
Return the font style as a string.

See Also
--------
.font_manager.FontProperties.get_style
)r   	get_stylerh   s    r   get_fontstyleText.get_fontstyle  s     ##--//r!   c                 6    U R                   R                  5       $ )zh
Return the font size as an integer.

See Also
--------
.font_manager.FontProperties.get_size_in_points
)r   r  rh   s    r   get_fontsizeText.get_fontsize  s     ##6688r!   c                 6    U R                   R                  5       $ )zb
Return the font variant as a string.

See Also
--------
.font_manager.FontProperties.get_variant
)r   get_variantrh   s    r   get_fontvariantText.get_fontvariant       ##//11r!   c                 6    U R                   R                  5       $ )zl
Return the font weight as a string or a number.

See Also
--------
.font_manager.FontProperties.get_weight
)r   
get_weightrh   s    r   get_fontweightText.get_fontweight  r  r!   c                 6    U R                   R                  5       $ )zn
Return the font stretch as a string or a number.

See Also
--------
.font_manager.FontProperties.get_stretch
)r   get_stretchrh   s    r   r  Text.get_stretch  r  r!   c                     U R                   $ )z[
Return the horizontal alignment as a string.  Will be one of
'left', 'center' or 'right'.
)r   rh   s    r   r  Text.get_horizontalalignment  s    
 (((r!   c                     [        U R                  U R                  5      5      n[        U R                  U R                  5      5      nX4$ )z0Return the (x, y) unitless position of the text.)rh  ri  re   rj  rf   r   s      r   r   Text.get_unitless_position  s=     $%%dgg./$%%dgg./tr!   c                 2    U R                   U R                  4$ )z'Return the (x, y) position of the text.)re   rf   rh   s    r   r  Text.get_position  s     wwr!   c                     U R                   $ )zReturn the text string.)rg   rh   s    r   r  Text.get_text  r  r!   c                     U R                   $ )zx
Return the vertical alignment as a string.  Will be one of
'top', 'center', 'bottom', 'baseline' or 'center_baseline'.
)r   rh   s    r   get_verticalalignmentText.get_verticalalignment  s    
 &&&r!   c                    U R                  5       (       d  [        R                  " 5       $ U R                  SS9nUc  UR                  nU R                  5       S:X  aH  [        R                  " X2S9   U R                  5       u  pE[        R                  " XESS5      sSSS5        $ Ub  Xl
        U R                  c  UR                  5       U l
        U R                  c  [        S5      e[        R                  " X2S9   U R                  U R                  5      u  n  nU R                  5       u  pU R                  5       R!                  X45      u  pUR#                  X5      nUsSSS5        $ ! , (       d  f       N= f! , (       d  f       g= f)a;  
Return the `.Bbox` bounding the text, in display units.

In addition to being used internally, this is useful for specifying
clickable regions in a png file on a web page.

Parameters
----------
renderer : Renderer, optional
    A renderer is needed to compute the bounding box.  If the artist
    has already been drawn, the renderer is cached; thus, it is only
    necessary to pass this argument when calling `get_window_extent`
    before the first draw.  In practice, it is usually easier to
    trigger a draw first, e.g. by calling
    `~.Figure.draw_without_rendering` or ``plt.show()``.

dpi : float, optional
    The dpi value for computing the bbox, defaults to
    ``self.get_figure(root=True).dpi`` (*not* the renderer dpi); should be set
    e.g. if to match regions with a figure saved with a custom dpi value.
Tr   Nrw   )r3   r   zoCannot get window extent of text w/o renderer. You likely want to call 'figure.draw_without_rendering()' first.)r   r   unitr  r3   r  r   _setattr_cmr   r!  r   _get_rendererr8   rV  r   r   r   
translated)
ri   r/   r3   figtxtyr   r6  r(   r)   s
             r   r   Text.get_window_extent	  sK   , !!99;oo4o(;''C==?b ""30--/''15 10 %N>>! ..0DN>>!HI I s,))$..9JD!Q--/DA%%'111&9DA??1(D -, 10 -,s   1*E,<A&E=,
E:=
Fc                   > U R                  5       (       a  U R                  5       S:X  a  [        R                  " 5       $ U R                  (       ai  U R                  5       U R                  R                  :X  aA  U R                  R                  " U R                  5       6 (       d  [        R                  " 5       $ [        TU ])  U5      $ )Nrw   )r   r  r   nullaxesr   	transData_point_in_data_domainr   rx   get_tightbboxri   r/   r   s     r   r  Text.get_tightbbox:  s    !!T]]_%:99; II&&(DII,?,??		779S9S9UV99;w$X..r!   c                     U R                   c  U R                  [        XS95        O"U R                   R                  [        US95        U R	                  5         SU l        g)z
Set the background color of the text.

This is realized through the bbox (see `.set_bbox`),
creating the bbox patch if needed.

Parameters
----------
color : :mpltype:`color`

See Also
--------
.set_bbox : To change the position of the bounding box
N)	facecolor	edgecolor)r!  T)r   r   r   r}   r`  r   ri   rR   s     r   set_backgroundcolorText.set_backgroundcolorE  sM     #MM$@A##D5$9:$$&
r!   c                     [         R                  " US5      (       d  [        R                  R	                  US9  Xl        SU l        g)zV
Set the foreground color of the text

Parameters
----------
color : :mpltype:`color`
auto)rR   TN)r   
_str_equalr   r
   _check_color_liker   r   r#  s     r   r   Text.set_color\  s8     v..JJ((u(5
r!   c                 L    [         R                  " / SQUS9  Xl        SU l        g)z
Set the horizontal alignment relative to the anchor point.

See also :doc:`/gallery/text_labels_and_annotations/text_alignment`.

Parameters
----------
align : {'left', 'center', 'right'}
r  r  rm   alignTN)r   r   r   r   ri   r.  s     r   r   Text.set_horizontalalignmentk  s"     	6eD$)!
r!   c                 L    [         R                  " / SQUS9  Xl        SU l        g)a,  
Set the text alignment for multiline texts.

The layout of the bounding box of all the lines is determined by the
horizontalalignment and verticalalignment properties. This property
controls the alignment of the text lines within that box.

Parameters
----------
align : {'left', 'right', 'center'}
r,  r-  TN)r   r   r   r   r/  s     r   set_multialignmentText.set_multialignmenty  s"     	6eD$
r!   c                     [         R                  " US5      (       d  [        R                  " [        US9  Xl        SU l        g)a7  
Set the line spacing.

Parameters
----------
spacing : 'normal' or float, default: 'normal'
    If 'normal', then the line spacing is automatically determined by font
    metrics for each line individually.

    If a float, then line spacing will be fixed to this multiple of the font
    size for every line.
r   )spacingTN)r   r(  r   check_isinstancer   r   r   )ri   r5  s     r   r   Text.set_linespacing  s4     22!!$8#
r!   c                     U R                   $ )zGet the line spacing.)r   rh   s    r   get_linespacingText.get_linespacing  r   r!   c                 H    U R                   R                  U5        SU l        g)ai  
Set the font family.  Can be either a single string, or a list of
strings in decreasing priority.  Each string may be either a real font
name or a generic font class name.  If the latter, the specific font
names will be looked up in the corresponding rcParams.

If a `Text` instance is constructed with ``fontfamily=None``, then the
font is set to :rc:`font.family`, and the
same is done when `set_fontfamily()` is called on an existing
`Text` instance.

Parameters
----------
fontname : {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'}

See Also
--------
.font_manager.FontProperties.set_family
TN)r   
set_familyr   ri   rU   s     r   set_fontfamilyText.set_fontfamily  s    * 	''1
r!   c                 p    [         R                  " [        S4US9  Ub  [        U5      nXl        SU l        g)a  
Set the feature tags to enable on the font.

Parameters
----------
features : list of str, or tuple of str, or None
    A list of feature tags to be used with the associated font. These strings
    are eventually passed to HarfBuzz, and so all `string formats supported by
    hb_feature_from_string()
    <https://harfbuzz.github.io/harfbuzz-hb-common.html#hb-feature-from-string>`__
    are supported. Note though that subranges are not explicitly supported and
    behaviour may change in the future.

    For example, if your desired font includes Stylistic Sets which enable
    various typographic alternates including one that you do not wish to use
    (e.g., Contextual Ligatures), then you can pass the following to enable one
    and not the other::

        fp.set_features([
            'ss01',  # Use Stylistic Set 1.
            '-clig',  # But disable Contextural Ligatures.
        ])

    Available font feature tags may be found at
    https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist
N)featuresT)r   r6  r   tuplerz   r   )ri   rA  s     r   set_fontfeaturesText.set_fontfeatures  s4    6 	x.BXH!
r!   c                 H    U R                   R                  U5        SU l        g)z
Set the font variant.

Parameters
----------
variant : {'normal', 'small-caps'}

See Also
--------
.font_manager.FontProperties.set_variant
TN)r   set_variantr   )ri   rM   s     r   set_fontvariantText.set_fontvariant  s     	((1
r!   c                 H    U R                   R                  U5        SU l        g)z
Set the font style.

Parameters
----------
fontstyle : {'normal', 'italic', 'oblique'}

See Also
--------
.font_manager.FontProperties.set_style
TN)r   	set_styler   )ri   rX   s     r   set_fontstyleText.set_fontstyle  s     	&&y1
r!   c                 H    U R                   R                  U5        SU l        g)a1  
Set the font size.

Parameters
----------
fontsize : float or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'}
    If a float, the fontsize in points. The string values denote sizes
    relative to the default font size.

See Also
--------
.font_manager.FontProperties.set_size
TN)r   set_sizer   )ri   rV   s     r   set_fontsizeText.set_fontsize  s     	%%h/
r!   c                 6    U R                   R                  5       $ )z
Return the font family name for math text rendered by Matplotlib.

The default value is :rc:`mathtext.fontset`.

See Also
--------
set_math_fontfamily
)r   get_math_fontfamilyrh   s    r   rR  Text.get_math_fontfamily  s     ##7799r!   c                 :    U R                   R                  U5        g)a  
Set the font family for math text rendered by Matplotlib.

This does only affect Matplotlib's own math renderer. It has no effect
when rendering with TeX (``usetex=True``).

Parameters
----------
fontfamily : str
    The name of the font family.

    Available font families are defined in the
    :ref:`default matplotlibrc file
    <customizing-with-matplotlibrc-files>`.

See Also
--------
get_math_fontfamily
N)r   set_math_fontfamily)ri   rT   s     r   rU  Text.set_math_fontfamily  s    ( 	00<r!   c                 H    U R                   R                  U5        SU l        g)a"  
Set the font weight.

Parameters
----------
weight : {a numeric value in range 0-1000, 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'}

See Also
--------
.font_manager.FontProperties.set_weight
TN)r   
set_weightr   )ri   rN   s     r   set_fontweightText.set_fontweight*  s     	''/
r!   c                 H    U R                   R                  U5        SU l        g)aM  
Set the font stretch (horizontal condensation or expansion).

Parameters
----------
stretch : {a numeric value in range 0-1000, 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded'}

See Also
--------
.font_manager.FontProperties.set_stretch
TN)r   set_stretchr   )ri   rK   s     r   set_fontstretchText.set_fontstretch;  s     	((1
r!   c                 T    U R                  US   5        U R                  US   5        g)zU
Set the (*x*, *y*) position of the text.

Parameters
----------
xy : (float, float)
r   r   N)set_xset_y)ri   xys     r   set_positionText.set_positionL  s$     	

2a5

2a5r!   c                     Xl         SU l        g)zD
Set the *x* position of the text.

Parameters
----------
x : float
TN)re   r   )ri   r(   s     r   r`  
Text.set_xW       
r!   c                     Xl         SU l        g)zD
Set the *y* position of the text.

Parameters
----------
y : float
TN)rf   r   )ri   r)   s     r   ra  
Text.set_yb  rg  r!   c                    [        U[        5      (       a  [        U5      S-  U l        OY[        R
                  " US5      (       d  Uc  SU l        O2[        R
                  " US5      (       a  SU l        O[        SU 35      eSU l        g)	z
Set the rotation of the text.

Parameters
----------
s : float or {'vertical', 'horizontal'}
    The rotation angle in degrees in mathematically positive direction
    (counterclockwise). 'horizontal' equals 0, 'vertical' equals 90.
r   
horizontalNr   verticalg     V@z;rotation must be 'vertical', 'horizontal' or a number, not T)r_  r   rh  r   r   r(  
ValueErrorr   ri   ss     r   r   Text.set_rotationm  s{     a"1X^DNa..!)DNa,, DN ../S2 3 3
r!   c                     Xl         SU l        g)z_
Whether rotations of the transform affect the text direction.

Parameters
----------
t : bool
TN)r   r   )ri   ts     r   set_transform_rotates_textText.set_transform_rotates_text  s     ()$
r!   c                 L    [         R                  " / SQUS9  Xl        SU l        g)z
Set the vertical alignment relative to the anchor point.

See also :doc:`/gallery/text_labels_and_annotations/text_alignment`.

Parameters
----------
align : {'baseline', 'bottom', 'center', 'center_baseline', 'top'}
)r  r  r  rl   center_baseliner-  TN)r   r   r   r   r/  s     r   r   Text.set_verticalalignment  s'     	F	 #(
r!   c                 ^    Uc  SO
[        U5      nXR                  :w  a  Xl        SU l        gg)z
Set the text string *s*.

It may contain newlines (``\n``) or math in LaTeX syntax.

Parameters
----------
s : object
    Any object gets converted to its `str` representation, except for
    ``None`` which is converted to an empty string.
Nrw   T)r   rg   r   rn  s     r   r   Text.set_text  s-     )BQ

?JDJ r!   c                     U R                  5       (       a  US:X  a  SnUS4$ U R                  5       (       d  US4$ [        R                  " U5      (       a  US4$ UR	                  SS5      S4$ )a  
Return the string *s* after mathtext preprocessing, and the kind of
mathtext support needed.

- If *self* is configured to use TeX, return *s* unchanged except that
  a single space gets escaped, and the flag "TeX".
- Otherwise, if *s* is mathtext (has an even number of unescaped dollar
  signs) and ``parse_math`` is not set to False, return *s* and the
  flag True.
- Otherwise, return *s* with dollar signs unescaped, and the flag
  False.
r  z\ r
  FTz\$$)r  get_parse_mathr   r  replacern  s     r   r  Text._preprocess_math  sn     ??Cxe8O$$&&e8O""d7N99UC(%//r!   c                 d    [         R                  " U5      R                  5       U l        SU l        g)a2  
Set the font properties that control the text.

Parameters
----------
fp : `.font_manager.FontProperties` or `str` or `pathlib.Path`
    If a `str`, it is interpreted as a fontconfig pattern parsed by
    `.FontProperties`.  If a `pathlib.Path`, it is interpreted as the
    absolute path to a font file.
TN)r   	_from_anyr.   r   r   )ri   fps     r   r   Text.set_fontproperties  s'      .77;@@B
r!   z bool, default: :rc:`text.usetex`c                 \    [        [        R                  " US5      5      U l        SU l        g)z{
Parameters
----------
usetex : bool or None
    Whether to render using TeX, ``None`` means to use
    :rc:`text.usetex`.
ztext.usetexTN)boolr   r   r   r   )ri   rq   s     r   r   Text.set_usetex  s"     CNN6=AB
r!   c                     U R                   $ )z9Return whether this `Text` object uses TeX for rendering.)r   rh   s    r   r  Text.get_usetex  s    ||r!   c                 $    [        U5      U l        g)z
Override switch to disable any mathtext parsing for this `Text`.

Parameters
----------
parse_math : bool
    If False, this `Text` will never use mathtext.  If True, mathtext
    will be used if there is an even number of unescaped dollar signs.
N)r  _parse_math)ri   rt   s     r   r   Text.set_parse_math  s      
+r!   c                     U R                   $ )z>Return whether mathtext parsing is considered for this `Text`.)r  rh   s    r   r|  Text.get_parse_math  s    r!   c                 &    U R                  U5        g)z
Alias for `set_fontfamily`.

One-way alias only: the getter differs.

Parameters
----------
fontname : {FONTNAME, 'serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'}

See Also
--------
.font_manager.FontProperties.set_family

N)r>  r=  s     r   set_fontnameText.set_fontname  s      	H%r!   c                 
   U R                  5       S:H  nUS::  d5  SUs=::  a  S::  d(  O  SU::  d   SUs=::  a  S::  d  O  SUs=::  a  S	::  a   g
  Og
SUs=:  a  S:  d  O  SUs=:  a  S:  a  O  OU(       a  S$ S$ U(       a  S$ S$ )z
Determines horizontal alignment ('ha') for rotation_mode "xtick" based on
the angle of rotation in degrees and the vertical alignment.
r  
   U   _   ^        i	  i  r  rm   r  )r  )ri   r'   anchor_at_bottoms      r   r  Text._ha_for_angle  s    
  5578CRK2,",uu##se':s': (;%_"_e 1c 1-6:7:*w66r!   c                 
   U R                  5       S:H  nUS::  d5  SU::  d/  SUs=::  a  S::  d"  O  SUs=::  a  S::  d  O  SUs=::  a  S	::  a   g
  Og
SUs=:  a  S:  d  O  SUs=:  a  S:  a  O  OU(       a  S$ S$ U(       a  S$ S$ )z
Determines vertical alignment ('va') for rotation_mode "ytick" based on
the angle of rotation in degrees and the horizontal alignment.
rm   r  r  r  r  P   d   i  i  r  rl   r  )r  )ri   r'   anchor_at_lefts      r   r   Text._va_for_angle  s    
 5576ARK3%<3%+>3+>%#%)<)< *=53"u/r/!/::U:&u6J6r!   c                     U R                   $ )z$Return the language this Text is in.)	_languagerh   s    r   get_languageText.get_language       ~~r!   c                    [         R                  " [        [        S4US9  [        R
                  " US5      n[        R                  " U5      (       d  [        U5      nU H  n[        U[        5      (       a  [        U5      S:w  a  [        S5      eUu  p4n[        U[        5      (       d  [        S5      e[        U[        5      (       d  [        S5      e[        U[        5      (       a  M  [        S5      e   Xl        S	U l        g)
a  
Set the language of the text.

Parameters
----------
language : str or None
    The language of the text in a format accepted by libraqm, namely `a BCP47
    language code <https://www.w3.org/International/articles/language-tags/>`_.

    If None, then defaults to :rc:`text.language`.
N)languageztext.languagera   z0language must be list of tuple, not {language!r}z7sub-language specification must be str, not {sublang!r}z)start location must be int, not {start!r}z%end location must be int, not {end!r}T)r   r6  r   r   r   r   r   is_scalar_or_stringrB  r_  r  	TypeErrorintr  r   )ri   r  valsublangstartends         r   r{   Text.set_language$  s     	xd3hG>>(O<((22XH!#u--SQ#$VWW&)#!'3//#QS S!%--#$OPP!#s++#$KLL   "
r!   )r   r   r   rz   r   r   r  r   r   r  r   r   r   r   rg   r   r   r   r  re   rf   r   )r   r   rw   )rw   NNNNFrl   rm   NNFNNNr   NN)___name__
__module____qualname____firstlineno____doc__zorderr   r   rj   ry   r|   r}   r   r   r   r   r   r   r   r   r   r   r   r   rV  r   re  rx  r`  r  r  r  r  r   r  r  r  r  r   allow_rasterizationr  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r   r  r$  r   r   r2  r   r9  r>  rC  rG  rK  rO  rR  rU  rY  r]  rc  r`  ra  r   rs  r   r   r  r   r	   	kwarg_docr   r  r   r|  r  r  r   r  r{   __static_attributes____classcell__r   s   @r   r_   r_      sP     LFfO= !#5#-%+ $ $!#(- !5 5r $"$"NH .6-5@",,#"! yNv-'^ C./'
'
'
*4.	1(f J  JX$1/09212) '/b	/. $!0B$
:=,""			*	 "00 <=	 >	
, &$77 r!   r_   c                   4    \ rS rSrSrS	S jrS rS rS rSr	g)

OffsetFromiE  z4Callable helper class for working with `Annotation`.c                 J    Xl         Uu  pEXE4U l        U R                  U5        g)a  
Parameters
----------
artist : `~matplotlib.artist.Artist` or `.BboxBase` or `.Transform`
    The object to compute the offset from.

ref_coord : (float, float)
    If *artist* is an `.Artist` or `.BboxBase`, this values is
    the location to of the offset origin in fractions of the
    *artist* bounding box.

    If *artist* is a transform, the offset origin is the
    transform applied to this value.

unit : {'points, 'pixels'}, default: 'points'
    The screen units to use (pixels or points) for the offset input.
N)_artist
_ref_coordset_unit)ri   r   	ref_coordr  r(   r)   s         r   ry   OffsetFrom.__init__H  s%    $ $dr!   c                 >    [         R                  " SS/US9  Xl        g)zr
Set the unit for input to the transform used by ``__call__``.

Parameters
----------
unit : {'points', 'pixels'}
pointspixels)r  N)r   r   _unit)ri   r  s     r   r  OffsetFrom.set_unit_  s     	Hh/d;
r!   c                     U R                   $ )z@Return the unit for input to the transform used by ``__call__``.)r  rh   s    r   get_unitOffsetFrom.get_unitj  r  r!   c                 j   [        U R                  [        5      (       ab  U R                  R                  U5      nU R                  u  p4UR
                  UR                  U-  -   nUR                  UR                  U-  -   nO[        U R                  [        5      (       aS  U R                  nU R                  u  p4UR
                  UR                  U-  -   nUR                  UR                  U-  -   nOu[        U R                  [        5      (       a(  U R                  R                  U R                  5      u  pVO.[        R                  " [        [        [        4U R                  S9  U R                  S:X  a  SOUR                  S5      n[!        5       R#                  U5      R%                  WW5      $ )z
Return the offset transform.

Parameters
----------
renderer : `RendererBase`
    The renderer to use to compute the offset

Returns
-------
`Transform`
    Maps (x, y) in pixel or point units to screen units
    relative to the given artist.
)r   r  r   )r_  r  r   r   r  r   r?  r   heightr   r   r   r   r6  r  ro  r   r5  rn  )ri   r/   r   xfyfr(   r)   r5  s           r   __call__OffsetFrom.__call__n  s8    dllF++<<11(;D__FB$**r/)A$++**Ah//<<D__FB$**r/)A$++**Ai00<<))$//:DAq!!68Y"?UZZ8+1J1J11Mz&00A66r!   )r  r  r  N)r  )
r  r  r  r  r  ry   r  r  r  r   r!   r   r  r  E  s    >.	7r!   r  c                   T    \ rS rSr  SS jrS rS rS rS rS r	SS	 jr
SS
 jrSrg)_AnnotationBasei  Nc                 X    Uu  pEXE4U l         X l        U R                  U5        S U l        g r   )rb  xycoordsset_annotation_clip
_draggable)ri   rb  r  annotation_clipr(   r)   s         r   ry   _AnnotationBase.__init__  s.    
 $   1r!   c                    Uu  pE[        U[        5      (       a  UOX34u  pgUS:X  a  [        U R                  U5      5      nUS:X  a  [        U R	                  U5      5      nU R                  X5      R                  XE45      $ )Ndata)r_  rB  rh  ri  rj  _get_xy_transformr   )ri   r/   rb  coordsr(   r)   xcoordycoords           r   _get_xy_AnnotationBase._get_xy  sy    #-fe#<#<6BRVd))!,-AVd))!,-A%%h7AA1&IIr!   c                    [        U[        5      (       a4  Uu  p4SSKJn  U R	                  X5      nU R	                  X5      nU" Xg5      $ [        U5      (       a`  U" U5      n[        U[        5      (       a  [        U5      $ [        U[        5      (       a  U$ [        S[        U5      R                   35      e[        U[        5      (       a  UR                  U5      n	[        U	5      $ [        U[        5      (       a  [        U5      $ [        U[        5      (       a  U$ [        U[        5      (       d!  [        S[        U5      R                   35      eUS:X  a  U R                  R                   $ US:X  a-  SSKJn
  U
R'                  5       U R                  R                   -   $  UR)                  5       u  pS	u  pUS
:X  a  U R-                  SS9R.                  nO<US:X  a  U R-                  SS9R0                  nOUS:X  a  U R                  R0                  nUb  UR2                  nO'US:X  a  U R5                  U5      nO[+        U< S35      eUS:X  a4  [7        5       R9                  U R-                  SS9R:                  S-  5      nOUS:X  a  [7        5       nOUS:X  aE  [7        5       R9                  U R=                  5       U R-                  SS9R:                  -  S-  5      nO7US:X  a"  [7        5       R8                  " UR>                  6 nO[+        U< S35      eUR@                  " U6 $ ! [*         a    [+        U< S35      S ef = f)Nr   )blended_transform_factoryz=xycoords callable must return a BboxBase or Transform, not a z^'xycoords' must be an instance of str, tuple[str, str], Artist, Transform, or Callable, not a r  polar)	PolarAxesz is not a valid coordinater  figureFr   	subfigurer  offsetr  Tr  r  rV   fractionz is not a recognized unit)!r_  rB  matplotlib.transformsr  r  callabler   r   r   r  typer  r   r   r   r  r  matplotlib.projectionsr  PolarTransformr  rm  r  figbboxr   p0_get_position_xyr   r5  r3   r^  rJ   rn  )ri   r/   r  r  r  r  tr1tr2trr   r  	bbox_namer  bbox0xy0s                  r   r  !_AnnotationBase._get_xy_transform  s   fe$$#NFG((:C((:C,S66f!B"h''&r**B	**	SBx(()+, , ''++H5D"4(())"6**	**MFC((115f1F1F0GIJ J V99&&&w8++-		0C0CCC	P$llnOI  
  OOO/77E+%OOO/44E& IINNE ((C("''1Cz)CDEE8!!T*..35BXBZ!!$//t/"<"@"@@2EGBZ!!5::.Bx'@ABB||S!!E  	Pz)CDE4O	Ps   (L- -Mc                     Xl         g)aQ  
Set the annotation's clipping behavior.

Parameters
----------
b : bool or None
    - True: The annotation will be clipped when ``self.xy`` is
      outside the Axes.
    - False: The annotation will always be drawn.
    - None: The annotation will be clipped when ``self.xy`` is
      outside the Axes and ``self.xycoords == "data"``.
N_annotation_clip)ri   r  s     r   r  #_AnnotationBase.set_annotation_clip  s
     !"r!   c                     U R                   $ )zi
Return the annotation's clipping behavior.

See `set_annotation_clip` for the meaning of return values.
r  rh   s    r   get_annotation_clip#_AnnotationBase.get_annotation_clip  s     $$$r!   c                 N    U R                  XR                  U R                  5      $ )z1Return the pixel position of the annotated point.)r  rb  r  )ri   r/   s     r   r   _AnnotationBase._get_position_xy  s    ||Hggt}}==r!   c                     Uc  U R                  SS9R                  5       nU R                  5       nU(       d  Uc<  U R                  S:X  a,  U R	                  U5      nU R
                  R                  U5      $ g)z;Check whether the annotation at *xy_pixel* should be drawn.Tr   r  )r  r  r  r  r  r  contains_point)ri   r/   r  xy_pixels       r   	_check_xy_AnnotationBase._check_xy
  si    D1??AH$$&t}}6,,X6H99++H55r!   c                    SSK Jn  U R                  SLnUc  U(       + nU(       a&  U R                  c  U" X5      U l        U R                  $ U R                  b  U R                  R                  5         SU l        U R                  $ )a  
Set whether the annotation is draggable with the mouse.

Parameters
----------
state : bool or None
    - True or False: set the draggability.
    - None: toggle the draggability.
use_blit : bool, default: False
    Use blitting for faster image composition. For details see
    :ref:`func-animation`.

Returns
-------
DraggableAnnotation or None
    If the annotation is draggable, the corresponding
    `.DraggableAnnotation` helper is returned.
r   )DraggableAnnotationN)matplotlib.offsetboxr  r  
disconnect)ri   stateuse_blitr  is_draggables        r   	draggable_AnnotationBase.draggable  sv    & 	=d2 =$$E&"5d"E 	 ***,"DOr!   )r  r  rb  r  )r  Nr   NF)r  r  r  r  ry   r  r  r  r  r  r  r  r  r  r!   r   r  r    s5     !!%
JH"T"%>	"r!   r  c                     ^  \ rS rSrSrS r     SS jrS r\S 5       r	\	R                  S 5       r	\S 5       r\R                  S	 5       rS
 rS r\" \\SS9rS rS r\R$                  S 5       rSS jrSU 4S jjrSrU =r$ )
Annotationi:  a4  
An `.Annotation` is a `.Text` that can refer to a specific position *xy*.
Optionally an arrow pointing from the text to *xy* can be drawn.

Attributes
----------
xy
    The annotated position.
xycoords
    The coordinate system for *xy*.
arrow_patch
    A `.FancyArrowPatch` to point from *xytext* to *xy*.
c                 h    SU R                   S   S SU R                   S   S SU R                  < S3$ )NzAnnotation(r   grc   r   rd   )rb  rg   rh   s    r   __str__Annotation.__str__I  s5    TWWQZN"TWWQZN"TZZN!LLr!   c                    [         R                  U UUUS9  Uc  Ub  XT:w  a  [        R                  " S5        Uc  U R                  nXPl        Uc  U R                  nUu  pX`l        UbZ  UR                  5       nSU;   a  UR                  SS5      U l
        OS H  nUR                  US5        M     [        S0 UD6U l        OSU l        [        R                  " X	X40 UD6  g)	a  
Annotate the point *xy* with text *text*.

In the simplest form, the text is placed at *xy*.

Optionally, the text can be displayed in another position *xytext*.
An arrow pointing from the text to the annotated point *xy* can then
be added by defining *arrowprops*.

Parameters
----------
text : str
    The text of the annotation.

xy : (float, float)
    The point *(x, y)* to annotate. The coordinate system is determined
    by *xycoords*.

xytext : (float, float), default: *xy*
    The position *(x, y)* to place the text at. The coordinate system
    is determined by *textcoords*.

xycoords : single or two-tuple of str or `.Artist` or `.Transform` or callable, default: 'data'

    The coordinate system that *xy* is given in. The following types
    of values are supported:

    - One of the following strings:

      ==================== ============================================
      Value                Description
      ==================== ============================================
      'figure points'      Points from the lower left of the figure
      'figure pixels'      Pixels from the lower left of the figure
      'figure fraction'    Fraction of figure from lower left
      'subfigure points'   Points from the lower left of the subfigure
      'subfigure pixels'   Pixels from the lower left of the subfigure
      'subfigure fraction' Fraction of subfigure from lower left
      'axes points'        Points from lower left corner of the Axes
      'axes pixels'        Pixels from lower left corner of the Axes
      'axes fraction'      Fraction of Axes from lower left
      'data'               Use the coordinate system of the object
                           being annotated (default)
      'polar'              *(theta, r)* if not native 'data'
                           coordinates
      ==================== ============================================

      Note that 'subfigure pixels' and 'figure pixels' are the same
      for the parent figure, so users who want code that is usable in
      a subfigure can use 'subfigure pixels'.

    - An `.Artist`: *xy* is interpreted as a fraction of the artist's
      `~matplotlib.transforms.Bbox`. E.g. *(0, 0)* would be the lower
      left corner of the bounding box and *(0.5, 1)* would be the
      center top of the bounding box.

    - A `.Transform` to transform *xy* to screen coordinates.

    - A function with one of the following signatures::

        def transform(renderer) -> Bbox
        def transform(renderer) -> Transform

      where *renderer* is a `.RendererBase` subclass.

      The result of the function is interpreted like the `.Artist` and
      `.Transform` cases above.

    - A tuple *(xcoords, ycoords)* specifying separate coordinate
      systems for *x* and *y*. *xcoords* and *ycoords* must each be
      of one of the above described types.

    See :ref:`plotting-guide-annotation` for more details.

textcoords : single or two-tuple of str or `.Artist` or `.Transform` or callable, default: value of *xycoords*
    The coordinate system that *xytext* is given in.

    All *xycoords* values are valid as well as the following strings:

    =================   =================================================
    Value               Description
    =================   =================================================
    'offset points'     Offset, in points, from the *xy* value
    'offset pixels'     Offset, in pixels, from the *xy* value
    'offset fontsize'   Offset, relative to fontsize, from the *xy* value
    =================   =================================================

arrowprops : dict, optional
    The properties used to draw a `.FancyArrowPatch` arrow between the
    positions *xy* and *xytext*.  Defaults to None, i.e. no arrow is
    drawn.

    For historical reasons there are two different ways to specify
    arrows, "simple" and "fancy":

    **Simple arrow:**

    If *arrowprops* does not contain the key 'arrowstyle' the
    allowed keys are:

    ==========  =================================================
    Key         Description
    ==========  =================================================
    width       The width of the arrow in points
    headwidth   The width of the base of the arrow head in points
    headlength  The length of the arrow head in points
    shrink      Fraction of total length to shrink from both ends
    ?           Any `.FancyArrowPatch` property
    ==========  =================================================

    The arrow is attached to the edge of the text box, the exact
    position (corners or centers) depending on where it's pointing to.

    **Fancy arrow:**

    This is used if 'arrowstyle' is provided in the *arrowprops*.

    Valid keys are the following `.FancyArrowPatch` parameters:

    ===============  ===================================
    Key              Description
    ===============  ===================================
    arrowstyle       The arrow style
    connectionstyle  The connection style
    relpos           See below; default is (0.5, 0.5)
    patchA           Default is bounding box of the text
    patchB           Default is None
    shrinkA          In points. Default is 2 points
    shrinkB          In points. Default is 2 points
    mutation_scale   Default is text size (in points)
    mutation_aspect  Default is 1
    ?                Any `.FancyArrowPatch` property
    ===============  ===================================

    The exact starting point position of the arrow is defined by
    *relpos*. It's a tuple of relative coordinates of the text box,
    where (0, 0) is the lower left corner and (1, 1) is the upper
    right corner. Values <0 and >1 are supported and specify points
    outside the text box. By default (0.5, 0.5), so the starting point
    is centered in the text box.

annotation_clip : bool or None, default: None
    Whether to clip (i.e. not draw) the annotation when the annotation
    point *xy* is outside the Axes area.

    - If *True*, the annotation will be clipped when *xy* is outside
      the Axes.
    - If *False*, the annotation will always be drawn.
    - If *None*, the annotation will be clipped when *xy* is outside
      the Axes and *xycoords* is 'data'.

**kwargs
    Additional kwargs are passed to `.Text`.

Returns
-------
`.Annotation`

See Also
--------
:ref:`annotations`

)r  r  NzgYou have used the `textcoords` kwarg, but not the `xytext` kwarg.  This can lead to surprising results.
arrowstylerelpos)      ?r  )r?  	headwidth
headlengthshrink)r]  )r   r   )r  ry   r   warn_externalr  _textcoordsrb  
arrowpropsr.   r   _arrow_relposr   arrow_patchr_   )ri   r0   rb  xytextr  
textcoordsr  r  r~   r(   r)   keys               r   ry   Annotation.__init__L  s    X 	  !#*21@ 	! 	B
 N&&  5 6
 J% >WWF$!#*Jz)%/^^Hj%I" JCNN3- J.LLD#D 	dq1&1r!   c                     U R                  U5      (       a  S0 4$ [        R                  X5      u  p#U R                  b(  U R                  R                  U5      u  pEU=(       d    UnX#4$ r  )r   r_   r   r   )ri   r   r   tinfoin_patchr6  s         r   r   Annotation.contains  sc    !!*--"9--9'**33J?KH+8Hr!   c                     U R                   $ r   )	_xycoordsrh   s    r   r  Annotation.xycoords'  r  r!   c                     S n[        U[        5      (       a  [        [        X!5      5      (       d  U" U5      (       a  [	        S5      eXl        g )Nc                 R    [        U [        5      =(       a    U R                  S5      $ )Nr  )r_  r   
startswith)ro  s    r   	is_offset&Annotation.xycoords.<locals>.is_offset-  s    a%@!,,x*@@r!   z'xycoords cannot be an offset coordinate)r_  rB  anymaprm  r*  )ri   r  r/  s      r   r  r+  +  sB    	A x''CI0H,I,IX&&FGG!r!   c                 "    U R                  5       $ )z9
The text position.

See also *xytext* in `.Annotation`.
)r  rh   s    r   xyannAnnotation.xyann5  s       ""r!   c                 &    U R                  U5        g r   )rc  )ri   r!  s     r   r4  r5  >  s    &!r!   c                     U R                   $ )ze
Return the coordinate system to use for `.Annotation.xyann`.

See also *xycoords* in `.Annotation`.
r  rh   s    r   get_anncoordsAnnotation.get_anncoordsB  s     r!   c                     Xl         g)zb
Set the coordinate system to use for `.Annotation.xyann`.

See also *xycoords* in `.Annotation`.
Nr8  )ri   r  s     r   set_anncoordsAnnotation.set_anncoordsJ  s
     "r!   z>
        The coordinate system to use for `.Annotation.xyann`.)docc                     U R                   b  U R                   R                  U5        [        R                  " X5        g r   )r   
set_figurer   )ri   r  s     r   r@  Annotation.set_figureU  s0    ''',$$r!   c                 $  ^^ U R                  U R                  XR                  5      5        U R                  nUc  g[        R                  X5      nU R                  U5      =nu  mmUR                  SU R                  5       5      nU R                  R                  U5        SU;  Gag  UR                  SS5      nUR                  SS5      nUR                  SS	5      nUR                  S
S	5      n	[        X-  X-  Xu-  S9n
U R                  R                  " S0 U
D6  UR                  S4UR                  UR                  -   S-  S4UR                  S4/nUR                  S4UR                  UR                   -   S-  S4UR                   S4/n[#        UU4S jS9u  p[#        UU4S jS9u  nnUU4U l        [&        R(                  " UT-
  UT-
  5      nUU-  UR+                  S5      -  nU=U R                  l        U R                  l        UR0                  UR2                  U R$                  -  -   nU R                  R5                  UU5        SU;   a  US   nOU R6                  (       a  U R6                  nOyU R9                  5       S:X  a  SnObUR+                  S5      n[;        UR                  US-  -
  UR                  US-  -
  4UR<                  U-   UR>                  U-   [A        5       SS9nU R                  RC                  U5        g)zH
Update the pixel positions of the annotation text and the arrow patch.
Nmutation_scaler  r  r   r?  r\  r     r  )head_length
head_width
tail_widthr   r  r  r   c                 &   > [        U S   T-
  5      $ Nr   r   )vr   s    r   <lambda>-Annotation.update_positions.<locals>.<lambda>      QqTBYr!   )r#  c                 &   > [        U S   T-
  5      $ rI  rJ  )rK  r   s    r   rL  rM    rN  r!   patchArw   F)rb  r?  r  r   r}  )simple)"rl  r  	anncoordsr  r_   r   r  r>   r^  r   rp  r   set_arrowstyler   r   r   r   r  r  r   hypotro  shrinkAshrinkBr  rJ   set_positionsr   r  r   r?  r  r   
set_patchA)ri   r/   r  r   	arrow_endmsr  r?  r  r  stylekwxposyposr(   relposxr)   relposyr
shrink_ptsarrow_beginrP  rZ  r   r   s                         @@r   update_positionsAnnotation.update_positions[  s   
 	411(NNKL__
%%d5!228<<	FB^^,dmmo>++B/z)^^Hc2FNN7A.E"{B7I#b9J z&/n&+j2G ++@@ WWaLDGGdgg$5#:C"@477A,ODWWaLDGGdgg$5#:C"@477A,ODT'?@JAT'?@JAw")7!3DRR(A!h&?&?&BBJBLLD$t'7'7'? gg		D,>,> >> 	&&{I>z!)F%%F]]_"F++A.CGGcAg%twwq'89jj3&t{{S/@+-u>F 	##F+r!   c                    Ub  Xl         U R                  5       (       a  U R                  U5      (       d  g U R                  U5        U R	                  U5        U R
                  bb  U R
                  R                  SS9c-  U R                  SS9=nb  U R
                  R                  U5        U R
                  R                  U5        [        R                  X5        g )NFr   )
r   r   r  rc  rx  r   r  r@  r  r_   )ri   r/   r  s      r   r  Annotation.draw  s     %N!!)A)A 	h'&&x0'  +++7? OOO77SD  ++C0!!(+ 			$!r!   c                     U R                  5       (       a  U R                  U5      (       d  [        R                  " 5       $ Ub  Xl        U R                  c"  U R                  SS9R                  5       U l        U R                  c  [        S5      eU R                  U R                  5        [        R                  U 5      nU/nU R                  b)  UR                  U R                  R                  5       5        [        R                  " U5      $ )NTr   z)Cannot get window extent without renderer)r   r  r   r  r   r  r  r8   rc  r_   r   r   r   union)ri   r/   	text_bboxbboxess       r   r   Annotation.get_window_extent  s     !!)A)A99;%N>>!!__$_7EEGDN>>!JKKdnn-**40	'MM$**<<>?zz&!!r!   c                 x   > U R                  U5      (       d  [        R                  " 5       $ [        TU ]  U5      $ r   )r  r   r  rx   r  r  s     r   r  Annotation.get_tightbbox  s.    ~~h''99;w$X..r!   )r  r   r  r*  r   r  )Nr  NNNr   )r  r  r  r  r  r  ry   r   propertyr  setterr4  r9  r<  rR  r@  rc  r   r  r  r   r  r  r  r  s   @r   r  r  :  s    M    !%P2d   __" " # # \\" " "  <A BI%?,B "  "&"./ /r!   r  )r  )9r  collections.abcr   rA   r"  loggingr#   numbersr   r?   numpyr   
matplotlibr   rw   r   r   r   r	   r
   r  r   font_managerr   r   r   patchesr   r   r   textpathr   r   
transformsr   r   r   r   r   r   	getLoggerr  r  rB   r    r+   r5   WeakKeyDictionaryr-   interpddefine_aliasesr_   r  r  r  registerry   r  r!   r   <module>r~     si   %         @ @  ? ? ? ? *M M " S!$ "$2@ 7>6O6O6Q EP U01*;;* 6f m6 m m`-G7 G7Th hVQ/ Q/h     z':':'B'B  Cr!   