o
    li *                     @   s   d Z ddlZddlZddlZddlmZmZ ddlm	Z
 ddlmZ ddl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G dd dejZG dd dZeedZeeejZeZdS )z/
An experimental support for curvilinear grid.
    N)_apicbook)Path)host_axes_class_factory   )	axislinesgrid_helper_curvelinear)
AxisArtist)ExtremeFinderSimplec                   @   s   e Zd ZdS )FloatingAxisArtistHelperN)__name__
__module____qualname__ r   r   c/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/mpl_toolkits/axisartist/floating_axes.pyr      s    r   c                       s6   e Zd Zd
 fdd	Zdd Zdd Zdd	 Z  ZS )FixedAxisArtistHelperNc                    sJ   | |\}}t j||||d |du r|}|| _|| _|| _|| _dS )z}
        nth_coord = along which coordinate value varies.
         nth_coord = 0 ->  x axis, nth_coord = 1 -> y axis
        axis_directionN)get_data_boundarysuper__init__nth_coord_ticksvaluegrid_helper_side)selfr   sider   r   	nth_coord	__class__r   r   r      s   
zFixedAxisArtistHelper.__init__c                 C   s   | j | | j j| _d S N)r   
update_lim
_grid_info)r   axesr   r   r   r!   .   s   z FixedAxisArtistHelper.update_limc                    s  | j j| jd \}}}|| }| jd \}}}|| }	| j j}
t|
dd \}}t|
dd \}}fdd}| jdkrg||k||k@ }t|| j|| ||f||f\\\}}\}}| jd n+| jd	kr||	k|	|k@ }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_labellat_infolon_infoN   c                    s(      j }|tt| |jS r    )get_transform	transData	transformnpcolumn_stackbroadcast_arraysT)xytrf)r#   grid_finderr   r   trf_xyA   s   z8FixedAxisArtistHelper.get_tick_iterators.<locals>.trf_xyr   
lat_labelsr   
lon_labelsc                 S   s   g | ]\}}|r|qS r   r   ).0lmr   r   r   
<listcomp>S   s    z<FixedAxisArtistHelper.get_tick_iterators.<locals>.<listcomp>)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*   rad2deg)r.   r/   normaltangentlabc2)angle_normalangle_tangentin_01labelstick_to_axesxx1yy1r   r   f1^   s    z4FixedAxisArtistHelper.get_tick_iterators.<locals>.f1)r   r1   r"   	_extremessortedr   r   _value_and_jacobianr   r9   r*   arctan2piget_tick_transform	transAxes	functoolspartialmpl
transforms_interval_contains_closeiter)r   r#   lat_levslat_n
lat_factoryy0lon_levslon_n
lon_factorxx0extremesxminxmaxyminymaxr2   maskdxx1dyy1dxx2dyy2mmrF   r   )	r?   r@   r#   r1   rA   rB   rC   rD   rE   r   get_tick_iterators2   sD   


z(FixedAxisArtistHelper.get_tick_iteratorsc                 C   sH   |  | tddddd| j \}}| j| | \}}tt||gS )N)
lon_lines0r   )rh   r   )
lat_lines0r   )ri   r   leftrightbottomtop)r!   dictr   r"   r   r*   r+   )r   r#   kvxxyyr   r   r   get_lineg   s   
zFixedAxisArtistHelper.get_liner    )r   r   r   r   r!   rg   rt   __classcell__r   r   r   r   r      s
    5r   c                   @   s   e Zd Zdd Zdd ZdS )ExtremeFinderFixedc                 C   s
   || _ dS )z
        This subclass always returns the same bounding box.

        Parameters
        ----------
        extremes : (float, float, float, float)
            The bounding box that this helper always returns.
        NrG   )r   r\   r   r   r   r   t   s   
	zExtremeFinderFixed.__init__c                 C   s   | j S r    rw   )r   transform_xyx1y1x2y2r   r   r   __call__   s   zExtremeFinderFixed.__call__N)r   r   r   r   r}   r   r   r   r   rv   q   s    rv   c                       sR   e Zd Z				d fdd	Zdd Z				dddZdd	 ZdddZ  ZS )GridHelperCurveLinearNc                    s*   || _ t|}t j||||||d d S )N)grid_locator1grid_locator2tick_formatter1tick_formatter2)rG   rv   r   r   )r   	aux_transr\   r   r   r   r   extreme_finderr   r   r   r      s   
zGridHelperCurveLinear.__init__c                 C   s2   | j \}}}}t|df|df|df|dfd| S )z$
        Return v=0, nth=1.
        r   r   rj   )rG   ro   )r   r   lon1lon2lat1lat2r   r   r   r      s   z'GridHelperCurveLinear.get_data_boundaryc                 C   sV   |d u r| j }|d u r|}t| ||d}t|||d}|jd |j|j j |S )N)r   r   T)r#   r   r	   lineset_clip_onset_clip_boxbbox)r   locr   r   offsetr#   _helperaxisliner   r   r   new_fixed_axis   s   z$GridHelperCurveLinear.new_fixed_axisc                 C   s  | j d u r	t | _ | j }| j}||j||||}t|d d \}}	t|dd  \}
}||	|
|f|d< |||	\}}}t|}|	|
|\}}}t|}|||f|d< |||f|d< |
d|||d< |d|||d< |d | | }|d | | }||||k ||	k @  ||
|k ||k @  ||	|
|\}}||d< ||d	< |j|d d |dd  g|R  \}}||d
< ||d< d S )Nr&   r\   r%   r$   rm   r4   r3   	lon_lines	lat_linesrh   ri   )r"   ro   r1   r   inv_transform_xyrH   r   r*   asarrayr   r   r   _get_raw_grid_lines)r   ry   rz   r{   r|   	grid_infor1   r\   lon_minlon_maxlat_minlat_maxrX   rY   rZ   rT   rU   rV   
lon_values
lat_valuesr   r   r   r   r   _update_grid   sP   




z"GridHelperCurveLinear._update_gridmajorbothc                 C   s8   g }|dv r| | jd  |dv r| | jd  |S )N)r   r.   r   )r   r/   r   )extendr"   )r   whichaxis
grid_linesr   r   r   get_gridlines   s   z#GridHelperCurveLinear.get_gridlines)NNNN)r   r   )	r   r   r   r   r   r   r   r   ru   r   r   r   r   r~      s    
(/r~   c                       s8   e Zd Z fddZdd Z fddZdd Z  ZS )	FloatingAxesBasec                   s:   t jt|d t j|d|i| | d |   d S )N)r   r   g      ?)r   check_isinstancer~   r   r   
set_aspectadjust_axes_lim)r   r   argskwargsr   r   r   r     s   
zFloatingAxesBase.__init__c                 C   s\   t |  jg d\\}}\}}\}}\}}t||f||f||f||fg}d| _|S )Nrj   d   )mapget_grid_helperr   mpatchesPolygonget_path_interpolation_steps)r   x0_ry   y0rz   patchr   r   r   _gen_axes_patch  s   "
z FloatingAxesBase._gen_axes_patchc                    sd   t    | j|  j | j  t   }|	| j
 || j | j| | j| d S r    )r   clearr   set_transformr   r1   r'   r(   r   
set_figurefigurerM   set_clip_path	gridlines)r   
orig_patchr   r   r   r     s   

zFloatingAxesBase.clearc                 C   sL   | j  | j  | j }|dd}| |j|j | 	|j
|j d S )NgRQ?)r   r   get_extentsr'   r(   expandedset_xlimr]   r^   set_ylimr_   r`   )r   r   r   r   r   r     s   
z FloatingAxesBase.adjust_axes_lim)r   r   r   r   r   r   r   ru   r   r   r   r   r      s
    
r   z
Floating{}) __doc__rN   numpyr*   
matplotlibrP   r   r   matplotlib.patchespatchesr   matplotlib.pathr   %mpl_toolkits.axes_grid1.parasite_axesr    r   r   axis_artistr	   r1   r
   r   r   rv   r~   r   _make_class_factoryfloatingaxes_class_factoryAxesFloatingAxesFloatingSubplotr   r   r   r   <module>   s2    
T{(