o
    ha(                     @   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   y/var/www/html/construction_image-detection-poc/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           
         s   |j jdgd  \}}}}tjt|df|df|df|dfd|d\}}	t j||	||d |du r4|	}|| _|| _|| _	|| _
dS )z}
        nth_coord = along which coordinate value varies.
         nth_coord = 0 ->  x axis, nth_coord = 1 -> y axis
        N   r   r   leftrightbottomtop)sideaxis_direction)grid_finderextreme_finderr   check_getitemdictsuper__init__nth_coord_ticksvaluegrid_helper_side)
selfr#   r   r!   lon1lon2lat1lat2r"   	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.   1   s   z FixedAxisArtistHelper.update_limc                    s  | j j| jd \}}}|| }| jd \}}}|| }	| j jjdgd  }
t|
dd \}}t|
dd \}}fdd}| jdkrm||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_infoNr      c                    s(      j }|tt| |jS r-   )get_transform	transData	transformnpcolumn_stackbroadcast_arraysT)xytrf)r0   r   r   r   trf_xyD   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>V   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   )zipr6   r7   rad2deg)r;   r<   normaltangentlabc2)angle_normalangle_tangentin_01labelstick_to_axesxx1yy1r   r   f1a   s    z4FixedAxisArtistHelper.get_tick_iterators.<locals>.f1)r#   r   r/   r   sortedr*   r   _value_and_jacobianr"   rE   r7   arctan2piget_tick_transform	transAxes	functoolspartialmpl
transforms_interval_contains_closeiter)r%   r0   lat_levslat_n
lat_factoryy0lon_levslon_n
lon_factorxx0extremesxminxmaxyminymaxr>   maskdxx1dyy1dxx2dyy2mmrR   r   )	rK   rL   r0   r   rM   rN   rO   rP   rQ   r   get_tick_iterators5   sD   


z(FixedAxisArtistHelper.get_tick_iteratorsc                 C   sH   |  | tddddd| j \}}| j| | \}}tt||gS )N)
lon_lines0r   )rs   r   )
lat_lines0r   )rt   r   r   )r.   r   r$   r/   r   r7   r8   )r%   r0   kvxxyyr   r   r   get_linej   s   
zFixedAxisArtistHelper.get_liner-   )r   r   r   r    r.   rr   ry   __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	_extremes)r%   rg   r   r   r   r    w   s   
	zExtremeFinderFixed.__init__c                 C   s   | j S r-   r|   )r%   transform_xyx1y1x2y2r   r   r   __call__   s   zExtremeFinderFixed.__call__N)r   r   r   r    r   r   r   r   r   r{   t   s    r{   c                       sD   e Zd Z				d fdd	Z	dddZdd Zdd
dZ  ZS )GridHelperCurveLinearNc                    s    t  j|t|||||d d S )N)r   grid_locator1grid_locator2tick_formatter1tick_formatter2)r   r    r{   )r%   	aux_transrg   r   r   r   r   r+   r   r   r       s   
zGridHelperCurveLinear.__init__c                 C   sV   |d u r| j }|d u r|}t| ||d}t|||d}|jd |j|j j |S )N)r!   r   T)r0   r   r	   lineset_clip_onset_clip_boxbbox)r%   locr*   r   offsetr0   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< |d | | }|d | | }||||k ||	k @  ||
|k ||k @  ||	|
|\}}||d	< ||d
< |j|d d |dd  g|R  \}}||d< ||d< d S )Nr3   rg   r2   r1   r   r   r@   r?   	lon_lines	lat_linesrs   rt   )r/   r   r   r   inv_transform_xyrS   r   r7   asarrayr   _format_ticks_get_raw_grid_lines)r%   r   r   r   r   	grid_infor   rg   lon_minlon_maxlat_minlat_maxrc   rd   re   r_   r`   ra   
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   rz   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                   s2   t jt|d t j|d|i| | d d S )N)r#   r#   g      ?)r   check_isinstancer   r   r    
set_aspect)r%   r#   argskwargsr+   r   r   r       s   zFloatingAxesBase.__init__c                 C   sN   |   jjd gd  \}}}}t||f||f||f||fg}d| _|S )Nr   d   )get_grid_helperr   r   mpatchesPolygonget_path_interpolation_steps)r%   x0r   y0r   patchr   r   r   _gen_axes_patch   s   "
z FloatingAxesBase._gen_axes_patchc                    sr   t    | j|  j | j  t   }|	| j
dd || j | j| | j| |   d S )NF)root)r   clearr   set_transformr   r   r4   r5   r   
set_figure
get_figurerX   set_clip_path	gridlinesadjust_axes_lim)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_extentsr4   r5   expandedset_xlimrh   ri   set_ylimrj   rk   )r%   r   r   r   r   r     s   
z FloatingAxesBase.adjust_axes_lim)r   r   r   r    r   r   r   rz   r   r   r+   r   r      s
    r   z
Floating{}) __doc__rY   numpyr7   
matplotlibr[   r   r   matplotlib.patchespatchesr   matplotlib.pathr   %mpl_toolkits.axes_grid1.parasite_axesr    r   r   axis_artistr	   r   r
   r   r   r{   r   r   _make_class_factoryfloatingaxes_class_factoryAxesFloatingAxesFloatingSubplotr   r   r   r   <module>   s*    
We%