o
    tBh3                     @   s   d Z ddlm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 dd	lmZ dd
lmZ G dd dejZG dd dejZG dd deZdS )z/
An experimental support for curvilinear grid.
    )chainN)_api)Path)Affine2DIdentityTransform   )AxisArtistHelperGridHelperBase)
AxisArtist)
GridFinderc                       sN   e Zd ZdZd fdd	Zdd Zedd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__ /var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyr      s   
zFixedAxisArtistHelper.__init__c                 C   s   | j | d S N)r   
update_limr   axesr   r   r   r   $   s   z FixedAxisArtistHelper.update_lim3.5c                 C   s2   |d u rd| j  | _ d S |dv r|| _ d S td)Nr   )r   r   zwrong coord number)r   	Exception)r   coord_numberr   r   r   change_tick_coord'   s
   
z'FixedAxisArtistHelper.change_tick_coordc                 C      |j S r   	transDatar   r   r   r   get_tick_transform0      z(FixedAxisArtistHelper.get_tick_transformc                 C   s~   | j dkr	| n| \}}||krddddd| j }n| j}| j}|| j|}|jd| j |dd	}t||tg fS )
z tick_loc, tick_angle, tick_labelr   rightleftbottomtop)r(   r'   r*   r)   r   T)minor)	r   get_ylimget_xlimr   r   get_tick_iteratorr   r   iter)r   r   v1v2r   gti1ti2r   r   r   get_tick_iterators3   s   z(FixedAxisArtistHelper.get_tick_iteratorsr   )__name__
__module____qualname____doc__r   r   r   
deprecatedr!   r%   r5   __classcell__r   r   r   r   r      s    r   c                       sh   e Zd Ze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 )FloatingAxisArtistHelperr   Nc                    s4   t  || || _|| _tj tjf| _d| _dS )r   d   N)r   r   valuer   npinf	_extremes_line_num_points)r   r   r   r>   axis_directionr   r   r   r   D   s
   
z!FloatingAxisArtistHelper.__init__c                 C   s,   |d u rt j }|d u rt j}||f| _d S r   )r?   r@   rA   )r   e1e2r   r   r   set_extremesO   s
   z%FloatingAxisArtistHelper.set_extremesc              	   C   sr  | 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|||f|||f|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_finderinv_transform_xyrA   r   maxmingrid_locator1grid_locator2r?   fullrB   r>   linspacetransform_xytick_formatter1tick_formatter2
_grid_info)r   r   x1x2y1y2rM   rG   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   r   V   sL   










z#FloatingAxisArtistHelper.update_limc                 C      t  S r   )r   r   r   r   r   get_axislabel_transform   r&   z0FloatingAxisArtistHelper.get_axislabel_transformc                 C   sp  | j d }| jdkr&| j}|d |d  d }d}t|d |d  d }n | jdkrF|d |d  d }| j}t|d |d  d }d}| jj}||g|g\\}\}	|j|j }
|
	||	g}d|d   krodkrn dS d|d   kr~dkrn dS |j	||	g\}}||| g|| g\\}\}|j	||g\}}||ft
t
|| || fS dS )NrG   r         i  r   )NN)rY   r   r>   absr   rM   rV   r$   	transAxes	transformr?   rad2degarctan2)r   r   rG   rj   rk   dxxdyyrM   xx1yy1data_to_axespxx1cyy1cxx2yy2xx2cyy2cr   r   r   get_axislabel_pos_angle   s0   


 "z0FloatingAxisArtistHelper.get_axislabel_pos_anglec                 C   rn   r   )r   r   r   r   r   r%      r&   z+FloatingAxisArtistHelper.get_tick_transformc                    s8  j jjd \}}}t|}|| }d| }jd \}}}	t|}||	 }
d|	 }j\}}jdkrE||k||k@ }|| }njdkrV||
k|
|k@ }|
| }
 fdd}jdkrt|j}
||
|\	|
	 }||
| |k  |8  < |||\
||| |\||
|\||
|| \jd d	d
 t
|D nSjdkrt|
j}||
|\	||
|\
||
|| \|
	 }||
| |k  |8  < |||\||| |\jd dd
 t
|D  	
fdd}| tg fS )z9tick_loc, tick_angle, tick_label, (optionally) tick_labelrI   g{Gz?rH   r   r   c                    s$      j }|t| |gjS r   )get_transformr$   rt   r?   column_stackT)xytrf)r   rM   r   r   rV      s   zAFloatingAxisArtistHelper.get_tick_iterators.<locals>.transform_xyrK   c                 S      g | ]\}}|r|qS r   r   .0lmr   r   r   
<listcomp>       z?FloatingAxisArtistHelper.get_tick_iterators.<locals>.<listcomp>rJ   c                 S   r   r   r   r   r   r   r   r      r   c                  3   s   t 
	  } t   }
	kk@ }|| t jd  | |<   j }t| |D ]F\}}}}}|||f}	d}
d|
 |	d   krXd|
 kr~n q8d|
 |	d   krjd|
 kr~n q8t ||g\}}||g|||fV  q8d S )Nrp   gh㈵>r   r   )r?   rv   pir%   rs   ziprt   ru   )dddd2mmtick_to_axesr   r   dd2labc2deltad1)r   labelsr   ry   xx1axx1bxx2axx2brz   yy1ayy1byy2ayy2br   r   f1   s   Hz7FloatingAxisArtistHelper.get_tick_iterators.<locals>.f1)r   rM   rY   r?   asarrayrA   r   	full_liker>   copyr   r/   )r   r   rg   rh   ri   rk   dyrd   re   rf   rj   dxe0rD   maskrV   xx00r   r   )r   rM   r   r   ry   r   r   r   r   rz   r   r   r   r   r   r5      sR   








$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 )NrL   )r   rY   r   r?   r   )r   r   r   r   r   r   r   get_line   s   
z!FloatingAxisArtistHelper.get_liner   )r6   r7   r8   r   deprecate_privatize_attribute	grid_infor   rF   r   ro   r   r%   r5   r   r   r;   r   r   r   r   r<   A   s    
+Or<   c                       sx   e Zd ZedZ					d fdd	ZdddZ				dddZ			dd
dZ	dd Z
dddZdddZ  ZS )GridHelperCurveLinearr   Nc                    s.   t    d| _|| _t||||||| _dS )a  
        aux_trans : a transform from the source (curved) coordinate to
        target (rectilinear) coordinate. An instance of MPL's Transform
        (inverse transform should be defined) or a tuple of two callable
        objects which defines the transform and its inverse. The callables
        need take two arguments of array of source coordinates and
        should return two target coordinates.

        e.g., ``x2, y2 = trans(x1, y1)``
        N)r   r   rY   
_aux_transr   rM   )r   	aux_transrN   rR   rS   rW   rX   r   r   r   r      s   

zGridHelperCurveLinear.__init__c                 K   s0   |d ur
| j | | j jdi | d | _d S )Nr   )rM   update_transformupdate_old_limits)r   r   kwr   r   r   update_grid_finder  s   
z(GridHelperCurveLinear.update_grid_finderc                 C   s:   |d u r| j }|d u r|}t| ||d}t|||d}|S )N)r   )rC   )r   r   r
   )r   r   r   rC   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   r<   r
   lineset_clip_onset_clip_boxbbox)r   r   r>   r   rC   r   r   r   r   r   new_floating_axis.  s   
	z'GridHelperCurveLinear.new_floating_axisc                 C   s   | j ||||| _d S r   )rM   get_grid_inforY   )r   rZ   r\   r[   r]   r   r   r   _update_gridJ  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   lonlines)r   r   lat)rY   extend)r   whichaxis
grid_linesglr   r   r   get_gridlinesM  s   z#GridHelperCurveLinear.get_gridlinesFc           
      c   s    t ddddd| }ddg| }|s8t| j| d | | j| d | D ]\\}}}|}	||	||fV  q&d S t| j| d | | j| d | D ]\\}}}|}	||	|dfV  qKd S )	NZ   r   )r(   r'   r)   r*   r   r   	tick_locstick_labels )dictr   rY   )
r   r   	axis_sider+   angle_tangent
lon_or_latxyar   angle_normalr   r   r   r.   W  s$   z'GridHelperCurveLinear.get_tick_iterator)NNNNNr   )NNNN)Nr)   )r   r   )F)r6   r7   r8   r   r   r   r   r   r   r   r   r   r.   r;   r   r   r   r   r      s(    





r   )r9   	itertoolsr   numpyr?   
matplotlibr   matplotlib.pathr   matplotlib.transformsr   r   	axislinesr   r	   axis_artistr
   rM   r   Fixedr   Floatingr<   r   r   r   r   r   <module>   s    1 <