o
    -h=0                     @   s   d Z ddlZddlZddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZmZmZ ddlmZ dd	lmZ d
d ZG dd deZG dd deZG dd deZdS )z/
An experimental support for curvilinear grid.
    N)_api)Path)Affine2DIdentityTransform   )_FixedAxisArtistHelperBase_FloatingAxisArtistHelperBaseGridHelperBase)
AxisArtist)
GridFinderc                 C   s   t tjd }| ||}t|\}}|| }	|| }
t ddg|
|	kt |t |	|
 }| || |}t|\}}|| }|| }t ddg||kt |t || }| ||| }||| | || | fS )z
    Compute *func* and its derivatives along x and y at positions *xs*, *ys*,
    while ensuring that finite difference calculations don't try to evaluate
    values outside of *xlims*, *ylims*.
    g      ?r   )npfinfofloatepssortedtakeminimummaximum)funcxsysxlimsylimsr   valxloxhidxlodxhixepsval_dxyloyhidylodyhiyepsval_dy r'   c/var/www/vscode/kcb/lib/python3.10/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.py_value_and_jacobian   s"   
r)   c                       s:   e Zd ZdZd fdd	Zdd Zdd Zd	d
 Z  ZS )FixedAxisArtistHelperz(
    Helper class for a fixed axis.
    Nc                    s2   t  j|d || _|du r| j}|| _|| _dS )}
        nth_coord = along which coordinate value varies.
         nth_coord = 0 ->  x axis, nth_coord = 1 -> y axis
        )locN)super__init__grid_helper	nth_coordnth_coord_ticksside)selfr/   r2   r1   	__class__r'   r(   r.   1   s   
zFixedAxisArtistHelper.__init__c                 C   s   | j | d S N)r/   
update_limr3   axesr'   r'   r(   r7   @   s   z FixedAxisArtistHelper.update_limc                 C      |j S r6   	transDatar8   r'   r'   r(   get_tick_transformC      z(FixedAxisArtistHelper.get_tick_transformc                    st   j dkr	| n| \}}||krdddddj njtddddd   fd	d
}| tg fS )z tick_loc, tick_angle, tick_labelr   rightleftbottomtop)r@   r?   rB   rA   Z   r@   r?   rA   rB   c                  3   sr    j dfdj  dffD ])\} }jjddg|   }|d  D ]}g |d  |r0|d nd	R V  q!qd S )
NTr   Flonlatticksr,   label )r1   r/   
_grid_info)r0   show_labelsgitickangle_tangentr3   r2   r'   r(   
iter_majorQ   s   
z<FixedAxisArtistHelper.get_tick_iterators.<locals>.iter_major)r0   get_ylimget_xlimr2   dictiter)r3   r9   v1v2rP   r'   rN   r(   get_tick_iteratorsF   s   z(FixedAxisArtistHelper.get_tick_iteratorsr6   )	__name__
__module____qualname____doc__r.   r7   r=   rW   __classcell__r'   r'   r4   r(   r*   ,   s    r*   c                       s^   e Zd Zd fdd	Zdd Zdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Z  ZS )FloatingAxisArtistHelperNc                    s4   t  || || _|| _tj tjf| _d| _dS )r+   d   N)r-   r.   valuer/   r   inf	_extremes_line_num_points)r3   r/   r0   r_   axis_directionr4   r'   r(   r.   ^   s
   
z!FloatingAxisArtistHelper.__init__c                 C   s,   |d u rt j }|d u rt j}||f| _d S r6   )r   r`   ra   )r3   e1e2r'   r'   r(   set_extremesi   s
   z%FloatingAxisArtistHelper.set_extremesc              
   C   s  | j | | \}}| \}}| j j}||j||||}|\}}	}
}| j\}}| jdkr;t	||
}
t
||}n| jdkrJt	||}t
||	}	|||	\}}}||
|\}}}| jdkrzt| j| j}t|
|| j}|||\}}n| jdkrt||	| j}t| j| j}|||\}}||	|
|f||t|f||t|f|dd|||dd||||fd| _d S )Nr   r   rA      )extremeslon_infolat_info
lon_labels
lat_labelsline_xy)r/   r7   rR   rQ   grid_finderextreme_finderinv_transform_xyra   r0   maxmingrid_locator1grid_locator2r   fullrb   r_   linspacetransform_xyasarray_format_ticksrJ   )r3   r9   x1x2y1y2rn   rh   lon_minlon_maxlat_minlat_maxe_mine_maxlon_levslon_n
lon_factorlat_levslat_n
lat_factorxx0yy0xxyyr'   r'   r(   r7   p   sL   










z#FloatingAxisArtistHelper.update_limc                 C      t  S r6   )r   r8   r'   r'   r(   get_axislabel_transform   r>   z0FloatingAxisArtistHelper.get_axislabel_transformc                    s    fdd}j d \}}}}jdkrj}|| d }njdkr-|| d }j}t|||||f||f\}	}
} j |	}d|d   krPdkrxn dS d|d   kr_dkrxn dS ||
gj }|	ttj	|d d d  fS dS )	Nc                    s"   j j  j }|| |gjS r6   )r/   rn   get_transformr<   	transformTxytrfr9   r3   r'   r(   trf_xy   s   z@FloatingAxisArtistHelper.get_axislabel_pos_angle.<locals>.trf_xyrh   r   rg   r   r   )NN)
rJ   r0   r_   r)   	transAxesinvertedr   r   rad2degarctan2)r3   r9   r   xminxmaxyminymaxr   r   xy1dxy1_dxdxy1_dypdr'   r   r(   get_axislabel_pos_angle   s&   


z0FloatingAxisArtistHelper.get_axislabel_pos_anglec                 C   r   r6   )r   r8   r'   r'   r(   r=      r>   z+FloatingAxisArtistHelper.get_tick_transformc                    s  j d \}}}|| }j d \}}}|| }	j\}
}fdd}jdkrR|
|k||k@ }t|j|| tj tjf|
|f\\\}}\}}j d n-jdkr|
|	k|	|k@ }t||	| jtj tjf|
|f\\\}}\}}j d d	d
 t|D t|| t|||dk|dk@ }| tj	d   |< 
j ttjjd fdd}| tg fS )z9tick_loc, tick_angle, tick_label, (optionally) tick_labelrj   ri   c                    s,   j j  j }|tt| |jS r6   )	r/   rn   r   r<   r   r   column_stackbroadcast_arraysr   r   r   r'   r(   r      s   z;FloatingAxisArtistHelper.get_tick_iterators.<locals>.trf_xyr   rl   r   rk   c                 S   s   g | ]\}}|r|qS r'   r'   ).0lmr'   r'   r(   
<listcomp>   s    z?FloatingAxisArtistHelper.get_tick_iterators.<locals>.<listcomp>rg   )r   r   c                  3   sl    t  D ]*\} }}}}| |f}|d r3|d r3| |ggt||g|R V  q	d S )Nr   r   )zipr   r   r   )r   r   normaltangentlabc2)angle_normalrO   in_01labelstick_to_axesxx1yy1r'   r(   rP      s    z?FloatingAxisArtistHelper.get_tick_iterators.<locals>.iter_major)rJ   ra   r0   r)   r_   r   r`   r   r   pir=   r   	functoolspartialmpl
transforms_interval_contains_closerT   )r3   r9   r   r   r   r   r   r   r   r   e0rd   r   maskdxx1dyy1dxx2dyy2mmrP   r'   )	r   rO   r9   r   r   r3   r   r   r   r(   rW      s:   



z+FloatingAxisArtistHelper.get_tick_iteratorsc                 C   r:   r6   r;   r8   r'   r'   r(   get_line_transform   r>   z+FloatingAxisArtistHelper.get_line_transformc                 C   s*   |  | | jd \}}tt||gS )Nrm   )r7   rJ   r   r   r   )r3   r9   r   r   r'   r'   r(   get_line   s   
z!FloatingAxisArtistHelper.get_liner6   )rX   rY   rZ   r.   rf   r7   r   r   r=   rW   r   r   r\   r'   r'   r4   r(   r]   \   s    +0r]   c                       sz   e Zd Z					d fdd	ZdddZedd	ddd	ZdddZdd Z	dddZ
eddddZ  ZS )GridHelperCurveLinearNc                    s(   t    d| _t||||||| _dS )a  
        Parameters
        ----------
        aux_trans : `.Transform` or tuple[Callable, Callable]
            The transform from curved coordinates to rectilinear coordinate:
            either a `.Transform` instance (which provides also its inverse),
            or a pair of callables ``(trans, inv_trans)`` that define the
            transform and its inverse.  The callables should have signature::

                x_rect, y_rect = trans(x_curved, y_curved)
                x_curved, y_curved = inv_trans(x_rect, y_rect)

        extreme_finder

        grid_locator1, grid_locator2
            Grid locators for each axis.

        tick_formatter1, tick_formatter2
            Tick formatters for each axis.
        N)r-   r.   rJ   r   rn   )r3   	aux_transro   rs   rt   tick_formatter1tick_formatter2r4   r'   r(   r.      s   

zGridHelperCurveLinear.__init__c                 K   s0   |d ur
| j | | j jdi | d | _d S )Nr'   )rn   update_transformupdate_old_limits)r3   r   kwargsr'   r'   r(   update_grid_finder  s   
z(GridHelperCurveLinear.update_grid_finderz3.9r0   c                 C   s:   |d u r| j }|d u r|}t| ||d}t|||d}|S )N)r1   )rc   )r9   r*   r
   )r3   r,   r0   rc   offsetr9   helperaxisliner'   r'   r(   new_fixed_axis  s   z$GridHelperCurveLinear.new_fixed_axisrA   c                 C   sF   |d u r| j }t| |||}t||}|jd |j|j j |S )NT)r9   r]   r
   lineset_clip_onset_clip_boxbbox)r3   r0   r_   r9   rc   r   r   r'   r'   r(   new_floating_axis&  s   
z'GridHelperCurveLinear.new_floating_axisc                 C   s   | j ||||| _d S r6   )rn   get_grid_inforJ   )r3   rz   r|   r{   r}   r'   r'   r(   _update_grid2  s   z"GridHelperCurveLinear._update_gridmajorbothc                 C   sT   g }|dv r| j d d D ]}|| q|dv r(| j d d D ]}|| q |S )N)r   r   rE   lines)r   r   rF   )rJ   extend)r3   whichaxis
grid_linesglr'   r'   r(   get_gridlines5  s   z#GridHelperCurveLinear.get_gridlinesFc                 c   s    t ddddd| }ddg| }|s/| j| d | D ]}g |d ||d R V  qd S | j| d | D ]}g |d |d	R V  q8d S )
NrC   r   rD   rE   rF   rG   r,   rH   rI   )rS   rJ   )r3   r0   	axis_sideminorrO   
lon_or_latrM   r'   r'   r(   get_tick_iterator?  s   z'GridHelperCurveLinear.get_tick_iterator)NNNNNr6   )NNNN)NrA   )r   r   )F)rX   rY   rZ   r.   r   r   make_keyword_onlyr   r   r   r   
deprecatedr   r\   r'   r'   r4   r(   r      s     
#



r   )r[   r   numpyr   
matplotlibr   r   matplotlib.pathr   matplotlib.transformsr   r   	axislinesr   r   r	   axis_artistr
   rn   r   r)   r*   r]   r   r'   r'   r'   r(   <module>   s    0 