
    h/                         S SK rS SKJrJr  S SKJrJr  S r	 " S S5      r
 " S S\5      r " S	 S
5      r " S S\R                  5      r " S S5      r " S S5      r " S S5      rg)    N)ticker_api)Bbox	Transformc                 j   / nU SS U SS -
  n[        S5      [        SSS5      4 GH  nU R                  U   u  pVUR                  U   u  pxUR                  U   u  pUR                  U   u  pXU	:  4XU:  44 H  u  p/ nUSS USS -  R	                  5       u  nU Hw  nUU   XU   -
  UU   -  UU   -  -   nU
Us=::  a  U::  d  O  M-  UU4U   n[
        R                  " [
        R                  " UU   SSS2   6 5      nUR                  UU45        My     UR                  U5        M     GM     U$ )a  
Find the points where a polyline crosses a bbox, and the crossing angles.

Parameters
----------
xys : (N, 2) array
    The polyline coordinates.
bbox : `.Bbox`
    The bounding box.

Returns
-------
list of ((float, float), float)
    Four separate lists of crossings, for the left, right, bottom, and top
    sides of the bbox, respectively.  For each list, the entries are the
    ``((x, y), ccw_angle_in_degrees)`` of the crossing, where an angle of 0
    means that the polyline is moving to the right at the crossing point.

    The entries are computed by linearly interpolating at each crossing
    between the nearest points on either side of the bbox edges.
   N)	sliceTminmaxnonzeronpdegreesarctan2append)xysbbox	crossingsdxysslusvsdusdvsuminvminumaxvmaxu0insidecrossidxsidxvcrossingthetas                        U/var/www/html/env/lib/python3.13/site-packages/mpl_toolkits/axisartist/grid_finder.py_find_line_box_crossingsr)      sV   , Iqr7S"XDT{E$b12r66":XXb\
XXb\
 t),t$Y.?@JBECR[6!":-668EDsGrsG|s3x7#c(BBq(D(72;

2::tCy2#?@h./  U# A 3      c                   *    \ rS rSrSrS rS rS rSrg)ExtremeFinderSimple2   zM
A helper class to figure out the range of grid lines that need to be drawn.
c                     Xl         X l        g)zQ
Parameters
----------
nx, ny : int
    The number of samples in each direction.
Nnxny)selfr0   r1   s      r(   __init__ExtremeFinderSimple.__init__7   s     r*   c                    [         R                  " [         R                  " X$U R                  5      [         R                  " X5U R                  5      5      u  pgU" [         R
                  " U5      [         R
                  " U5      5      u  pU R                  UR                  5       UR                  5       U	R                  5       U	R                  5       5      $ )a  
Compute an approximation of the bounding box obtained by applying
*transform_xy* to the box delimited by ``(x1, y1, x2, y2)``.

The intended use is to have ``(x1, y1, x2, y2)`` in axes coordinates,
and have *transform_xy* be the transform from axes coordinates to data
coordinates; this method then returns the range of data coordinates
that span the actual axes.

The computation is done by sampling ``nx * ny`` equispaced points in
the ``(x1, y1, x2, y2)`` box and finding the resulting points with
extremal coordinates; then adding some padding to take into account the
finite sampling.

As each sampling step covers a relative range of *1/nx* or *1/ny*,
the padding is computed by expanding the span covered by the extremal
coordinates by these fractions.
)	r   meshgridlinspacer0   r1   ravel_add_padr   r   )
r2   transform_xyx1y1x2y2xyxtyts
             r(   __call__ExtremeFinderSimple.__call__A   s    & {{KK("++bdgg*FHbhhqk288A;7}}RVVXrvvx2668DDr*   c                 b    X!-
  U R                   -  nXC-
  U R                  -  nX-
  X%-   X6-
  XF-   4$ )z,Perform the padding mentioned in `__call__`.r/   )r2   x_minx_maxy_miny_maxdxdys          r(   r9   ExtremeFinderSimple._add_padY   s9    mtww&mtww&z5:uz5:==r*   r/   N)	__name__
__module____qualname____firstlineno____doc__r3   rC   r9   __static_attributes__ r*   r(   r,   r,   2   s    E0>r*   r,   c                   @   ^  \ rS rSrSrS=rrU 4S jrS rS r	Sr
U =r$ )_User2DTransform`   z.A transform defined by two user-set functions.   c                 :   > [         TU ]  5         Xl        X l        g)z
Parameters
----------
forward, backward : callable
    The forward and backward transforms, taking ``x`` and ``y`` as
    separate arguments and returning ``(tr_x, tr_y)``.
N)superr3   _forward	_backward)r2   forwardbackward	__class__s      r(   r3   _User2DTransform.__init__e   s     	!r*   c                 p    [         R                  " U R                  " [         R                  " U5      6 5      $ N)r   	transposerZ   )r2   valuess     r(   transform_non_affine%_User2DTransform.transform_non_affines   s#    ||DMM2<<+?@AAr*   c                 N    [        U 5      " U R                  U R                  5      $ ra   )typer[   rZ   r2   s    r(   inverted_User2DTransform.invertedw   s    Dz$..$--88r*   )r[   rZ   )rM   rN   rO   rP   rQ   
input_dimsoutput_dimsr3   rd   ri   rR   __classcell__r^   s   @r(   rU   rU   `   s%    8  J"B9 9r*   rU   c                   `    \ rS rSrSr     SS jrS rS rS rS r	S	 r
\	rS
 rS rS rSrg)
GridFinder|   z
Internal helper for `~.grid_helper_curvelinear.GridHelperCurveLinear`, with
the same constructor parameters; should not be directly instantiated.
Nc                     Uc  [        SS5      nUc
  [        5       nUc
  [        5       nUc
  [        5       nUc
  [        5       nX l        X0l        X@l        XPl        X`l        U R                  U5        g )N   )	r,   MaxNLocatorFormatterPrettyPrintextreme_findergrid_locator1grid_locator2tick_formatter1tick_formatter2set_transform)r2   	transformrv   rw   rx   ry   rz   s          r(   r3   GridFinder.__init__   sx     !0R8N 'MM 'MM"24O"24O,**..9%r*   c                     [         R                  " U R                  U R                  S.US9n[	        U[
        R                  5      (       a  UR                  U5      $ U" X#U5      $ )ai  
Helper to support both standard formatters (inheriting from
`.mticker.Formatter`) and axisartist-specific ones; should be called instead of
directly calling ``self.tick_formatter1`` and ``self.tick_formatter2``.  This
method should be considered as a temporary workaround which will be removed in
the future at the same time as axisartist-specific formatters.
)r   rW   )r$   )r   check_getitemry   rz   
isinstancemticker	Formatterformat_ticks)r2   r$   	directionfactorlevelsfmts         r(   _format_ticksGridFinder._format_ticks   s_       $$)=)=>CI,6sG<M<M,N,N  ( 	5F3	5r*   c           	         U R                  U R                  XX45      nUu  pgpU R                  Xg5      u  pn[        R                  " U
5      n
U R                  X5      u  pn[        R                  " U5      nU
SU U-  nUSU U-  nU R                  UUXgX5      u  nn[        R                  " XX45      R                  SS5      nSU0nSSXUU4SSXUU44 GH   u  nnnnnnU Vs/ s H  nU/PM     sn/ / / / S.S	.=UU'   n[        UUU5       Hg  u  u  nnn n![        [        R                  " UU/5      U5      n"[        / SQU"5       H)  u  n#n$U$ H  n%US
   U#   R                  U!U%S.5        M     M+     Mi     US
    HS  n#US
   U#    V&s/ s H  n&U&S   PM
     nn&U R                  UU#UU5      n'[        US
   U#   U'5       H  u  n&n(U(U&S'   M     MU     GM     U$ s  snf s  sn&f )z
lon_values, lat_values : list of grid values. if integer is given,
                   rough number of grids in each direction.
Ngp   ?extremesr   lonrW   lat)leftrightbottomtop)linesticksr   )levellocr   label)rv   inv_transform_xyrw   r   asarrayrx   _get_raw_grid_linesr   from_extentsexpandedzipr)   column_stackr   r   ))r2   r;   r<   r=   r>   r   lon_minlon_maxlat_minlat_maxlon_levslon_n
lon_factorlat_levslat_n
lat_factor
lon_values
lat_values	lon_lines	lat_linesbb	grid_infor$   
lon_or_latlevsr   rc   r   lgilxlyr%   r   all_crossingssider   r&   ticklabelsr   s)                                            r(   get_grid_infoGridFinder.get_grid_info   sL    &&t'<'<bbM
 .6*'&*&8&8&J#::h'&*&8&8&J#::h'fu%
2
fu%
2
#77
8B8?8? J	9
 rr.77	9M 
	 E8YGE8YG=
8CT665
 (--u!1#u-"$rRK* Ij!B '*%&>"R!U 8"b9RTV W'*:M(KOD)$-7D)0051RS %.(K '? 724W+d2CD2C$W2CD++CvtD#&r'{4'8&#AKD%$)DM $B $=
(  . Es   &GG#c           
      P   [         R                  " X4S5      n[         R                  " XVS5      nU V	s/ s H)  n	U R                  [         R                  " X5      U5      PM+     n
n	U Vs/ s H)  nU R                  U[         R                  " X{5      5      PM+     nnX4$ s  sn	f s  snf )Nd   )r   r7   r:   	full_like)r2   r   r   r   r   r   r   lons_ilats_ir   r   r   r   s                r(   r   GridFinder._get_raw_grid_lines   s     Ws3Ws3 !+, * &&r||F'@&I * 	 , !+, * &&vr||F/HI * 	 , ##,,s   0B)0B#c                     [        U[        5      (       a  Xl        g [        U5      S:X  a,  [	        [        [        U5      5      (       a  [        U6 U l        g [        S5      e)NrW   zF'aux_trans' must be either a Transform instance or a pair of callables)	r   r   _aux_transformlenallmapcallablerU   	TypeError)r2   	aux_transs     r(   r{   GridFinder.set_transform   sQ    i++"+^q SXy)A%B%B"2I">D > ? ?r*   c                     U R                   $ ra   )r   rh   s    r(   get_transformGridFinder.get_transform   s    """r*   c                 v    U R                   R                  [        R                  " X/5      5      R                  $ ra   )r   r|   r   r   r   r2   r?   r@   s      r(   r:   GridFinder.transform_xy   s*    "",,R__aV-DEGGGr*   c                     U R                   R                  5       R                  [        R                  " X/5      5      R
                  $ ra   )r   ri   r|   r   r   r   r   s      r(   r   GridFinder.inv_transform_xy   s7    ""++-77OOQF#%%&Q	'r*   c                 x    UR                  5        H&  u  p#US;   a  [        XU5        M  [        SU< 35      e   g )N)rv   rw   rx   ry   rz   zUnknown update property )itemssetattr
ValueError)r2   kwargskr%   s       r(   updateGridFinder.update   s@    LLNDA ( (
 # #;A5!ABB #r*   )r   rv   rw   rx   ry   rz   )NNNNN)rM   rN   rO   rP   rQ   r3   r   r   r   r{   r   update_transformr:   r   r   rR   rS   r*   r(   rp   rp   |   sP     !%##!%!%&054l$?# %H'	Cr*   rp   c                   B   ^  \ rS rSr     SU 4S jjrU 4S jrSrU =r$ )rt   i  c                 D   > [         TU ]  XUXVS9  U R                  5         g )N)stepsinteger	symmetricprune)rY   r3   create_dummy_axis)r2   nbinsr   trimr   r   r   r^   s          r(   r3   MaxNLocator.__init__  s*     	W#, 	 	; r*   c                 f   > [         TU ]  X5      n[        R                  " U5      [	        U5      S4$ Nr   )rY   tick_valuesr   arrayr   )r2   v1v2locsr^   s       r(   rC   MaxNLocator.__call__  s+    w"2*xx~s4y!++r*   rS   )
   NTFFNrM   rN   rO   rP   r3   rC   rR   rm   rn   s   @r(   rt   rt     s!    '+ 	!, ,r*   rt   c                        \ rS rSrS rS rSrg)FixedLocatori  c                     Xl         g ra   _locs)r2   r   s     r(   r3   FixedLocator.__init__  s    
r*   c                     [        X/5      u  p[        R                  " U R                   Vs/ s H  o1Us=::  a  U::  d  M  O  M  UPM     sn5      nU[	        U5      S4$ s  snf r   )sortedr   r   r   r   )r2   r   r   r   r   s        r(   rC   FixedLocator.__call__   sT    !xxDJJ@Jq-R--J@ASY!! As   A A A r   NrM   rN   rO   rP   r3   rC   rR   rS   r*   r(   r   r     s    "r*   r   c                   $    \ rS rSrSS jrS rSrg)ru   i(  c                 l    [         R                  " USS9U l        U R                  R                  5         g )NF)useMathText	useOffset)r   ScalarFormatter_fmtr   )r2   r   s     r(   r3   FormatterPrettyPrint.__init__)  s)    ++#u6			##%r*   c                 8    U R                   R                  U5      $ ra   )r   r   )r2   r   r   rc   s       r(   rC   FormatterPrettyPrint.__call__.  s    yy%%f--r*   )r   N)Tr   rS   r*   r(   ru   ru   (  s    &
.r*   ru   c                   2   ^  \ rS rSrSU 4S jjrS rSrU =r$ )DictFormatteri2  c                 :   > [         TU ]  5         Xl        X l        g)zY
format_dict : dictionary for format strings to be used.
formatter : fall-back formatter
N)rY   r3   _format_dict_fallback_formatter)r2   format_dict	formatterr^   s      r(   r3   DictFormatter.__init__3  s    
 	'#, r*   c                     U R                   (       a  U R                  XU5      nOS/[        U5      -  n[        X45       VVs/ s H   u  pVU R                  R	                  XV5      PM"     snn$ s  snnf )z7
factor is ignored if value is found in the dictionary
 )r  r   r   r  get)r2   r   r   rc   fallback_stringsr   r%   s          r(   rC   DictFormatter.__call__<  ss     ###776 + !#tc&k19;9DA !!%%a+9; 	; ;s   'A-)r  r  ra   r   rn   s   @r(   r  r  2  s    -
; 
;r*   r  )numpyr   
matplotlibr   r   r   matplotlib.transformsr   r   r)   r,   rU   rp   rt   r   ru   r  rS   r*   r(   <module>r     sj     . 1(V+> +>\9y 98MC MC`,'%% , " ". .; ;r*   