o
    j=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   )npZfinfofloatepssortedZtakeminimummaximum)funcZxsZysZxlimsZylimsr   valZxloZxhiZdxloZdxhiZxepsZval_dxZyloZyhiZdyloZdyhiZyepsZval_dy r   p/var/www/html/Deteccion_Ine/venv/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   r    r   	__class__r   r   r   1   s   
zFixedAxisArtistHelper.__init__c                 C   s   | j | d S N)r   
update_limr!   axesr   r   r   r%   @   s   z FixedAxisArtistHelper.update_limc                 C      |j S r$   	transDatar&   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-   r0   r/   Z   r.   r-   r/   r0   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 )r   r   
_grid_info)r   Zshow_labelsgitickangle_tangentr!   r    r   r   
iter_majorQ   s   
z<FixedAxisArtistHelper.get_tick_iterators.<locals>.iter_major)r   get_ylimget_xlimr    dictiter)r!   r'   Zv1Zv2r=   r   r;   r   get_tick_iteratorsF   s   z(FixedAxisArtistHelper.get_tick_iteratorsr$   )	__name__
__module____qualname____doc__r   r%   r+   rB   __classcell__r   r   r"   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)r!   r   r   rJ   axis_directionr"   r   r   r   ^   s
   
z!FloatingAxisArtistHelper.__init__c                 C   s,   |d u rt j }|d u rt j}||f| _d S r$   )r   rK   rL   )r!   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   r/      )extremeslon_infolat_info
lon_labels
lat_labelsline_xy)r   r%   r?   r>   grid_finderextreme_finderZinv_transform_xyrL   r   maxmingrid_locator1grid_locator2r   fullrM   rJ   ZlinspaceZtransform_xyZasarrayZ_format_ticksr8   )r!   r'   x1x2y1y2rY   rS   Zlon_minZlon_maxZlat_minZlat_maxZe_minZe_maxlon_levslon_n
lon_factorlat_levslat_n
lat_factorxx0yy0xxyyr   r   r   r%   p   sL   










z#FloatingAxisArtistHelper.update_limc                 C      t  S r$   )r   r&   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 r$   )r   rY   get_transformr*   	transformTxyZtrfr'   r!   r   r   trf_xy   s   z@FloatingAxisArtistHelper.get_axislabel_pos_angle.<locals>.trf_xyrS   r   rR   r   r   )NN)
r8   r   rJ   r   	transAxesinvertedrq   r   rad2degarctan2)r!   r'   rw   ZxminZxmaxZyminZymaxrj   rk   Zxy1Zdxy1_dxZdxy1_dypdr   rv   r   get_axislabel_pos_angle   s&   


z0FloatingAxisArtistHelper.get_axislabel_pos_anglec                 C   rn   r$   )r   r&   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_labelrU   rT   c                    s,   j j  j }|tt| |jS r$   )	r   rY   rp   r*   rq   r   column_stackZbroadcast_arraysrr   rs   rv   r   r   rw      s   z;FloatingAxisArtistHelper.get_tick_iterators.<locals>.trf_xyr   rW   r   rV   c                 S   s   g | ]\}}|r|qS r   r   ).0lmr   r   r   
<listcomp>   s    z?FloatingAxisArtistHelper.get_tick_iterators.<locals>.<listcomp>rR   )r   r   c                  3   sl    t  D ]*\} }}}}| |f}|d r3|d r3| |ggt||g|R V  q	d S )Nr   r   )ziprq   r   rz   )rt   ru   normalZtangentZlabc2)angle_normalr<   in_01labelstick_to_axesxx1yy1r   r   r=      s    z?FloatingAxisArtistHelper.get_tick_iterators.<locals>.iter_major)r8   rL   r   r   rJ   r   rK   r   r{   pir+   rx   	functoolspartialmplZ
transformsZ_interval_contains_closerA   )r!   r'   rg   rh   ri   rk   rd   re   rf   rj   Ze0rO   rw   maskZdxx1Zdyy1Zdxx2Zdyy2mmr=   r   )	r   r<   r'   r   r   r!   r   r   r   r   rB      s:   



z+FloatingAxisArtistHelper.get_tick_iteratorsc                 C   r(   r$   r)   r&   r   r   r   get_line_transform   r,   z+FloatingAxisArtistHelper.get_line_transformc                 C   s*   |  | | jd \}}tt||gS )NrX   )r%   r8   r   r   r   )r!   r'   rt   ru   r   r   r   get_line   s   
z!FloatingAxisArtistHelper.get_liner$   )rC   rD   rE   r   rQ   r%   ro   r~   r+   rB   r   r   rG   r   r   r"   r   rH   \   s    +0rH   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   r8   r   rY   )r!   	aux_transrZ   r]   r^   Ztick_formatter1Ztick_formatter2r"   r   r   r      s   

zGridHelperCurveLinear.__init__c                 K   s0   |d ur
| j | | j jdi | d | _d S )Nr   )rY   Zupdate_transformupdateZ_old_limits)r!   r   kwargsr   r   r   update_grid_finder  s   
z(GridHelperCurveLinear.update_grid_finderz3.9r   c                 C   s:   |d u r| j }|d u r|}t| ||d}t|||d}|S )N)r   )rN   )r'   r   r
   )r!   r   r   rN   offsetr'   helperaxisliner   r   r   new_fixed_axis  s   z$GridHelperCurveLinear.new_fixed_axisr/   c                 C   sF   |d u r| j }t| |||}t||}|jd |j|j j |S )NT)r'   rH   r
   lineZset_clip_onZset_clip_boxZbbox)r!   r   rJ   r'   rN   r   r   r   r   r   new_floating_axis&  s   
z'GridHelperCurveLinear.new_floating_axisc                 C   s   | j ||||| _d S r$   )rY   Zget_grid_infor8   )r!   r`   rb   ra   rc   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   rt   r3   lines)r   ru   r4   )r8   extend)r!   whichZaxisZ
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 )
Nr1   r   r2   r3   r4   r5   r   r6   r7   )r@   r8   )r!   r   Z	axis_sideminorr<   Z
lon_or_latr:   r   r   r   get_tick_iterator?  s   z'GridHelperCurveLinear.get_tick_iterator)NNNNNr$   )NNNN)Nr/   )r   r   )F)rC   rD   rE   r   r   r   Zmake_keyword_onlyr   r   r   r   
deprecatedr   rG   r   r   r"   r   r      s     
#



r   )rF   r   numpyr   Z
matplotlibr   r   Zmatplotlib.pathr   Zmatplotlib.transformsr   r   Z	axislinesr   r   r	   Zaxis_artistr
   rY   r   r   r   rH   r   r   r   r   r   <module>   s    0 