o
    g=2                     @   s   d Z ddlZddlZddl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ddd ZeeejZeeZdS )z/
An experimental support for curvilinear grid.
    N)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/cloudmapper/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 \}}}t|t|}}|dur,|| }d| }	n|}d}	|dur=|| }
d| }n|}
d}j j}t|dd \}}t|dd \}} fdd}jdkr||k||k@ }|| }t|j	}
||
|\	|
j
td	d
}||
| |k  |8  < |||\
||| |\|j
td	d
}|||	 |k  |	8  < ||
|\||
||	 \jd dd t|D nujdkrJ||
k|
|k@ }|
| }
t|
j	}||
|\	|j
td	d
}|||	 |k  |	8  < ||
|\
||
||	 \|
j
td	d
}||
| |k  |8  < |||\||| |\jd dd t|D  	
fdd}| tg fS )z9tick_loc, tick_angle, tick_label, (optionally) tick_labellat_infolon_infoNgMbP?   c                    s6    | |\}} jt||gjj\}}||fS r   )transform_xy	transData	transformnparrayT)xyx1y1x2y2)r!   grid_finderr   r   r%   L   s   z>FixedAxisArtistHelper.get_tick_iterators.<locals>.transform_xyr   T)copy
lat_labelsc                 S      g | ]\}}|r|qS r   r   .0lmr   r   r   
<listcomp>b       z<FixedAxisArtistHelper.get_tick_iterators.<locals>.<listcomp>r   
lon_labelsc                 S   r4   r   r   r5   r   r   r   r9   u   r:   c                  3   s
   t 
	  } t   }
	 dk dk@ }|| t jd  | |<   j }t| |D ]F\}}}}}|||f}	d}
d|
 |	d   kr\d|
 krn q<d|
 |	d   krnd|
 krn q<t ||g\}}||g|||fV  q<d S )Nr   r$   gh㈵>r   )r(   arctan2piget_tick_transform	transAxeszipr'   rad2deg)dddd2mmtick_to_axesr+   r,   dd2labc2deltad1)r!   labelsr   xx1xx1axx1bxx2axx2byy1yy1ayy1byy2ayy2br   r   f1w   s   Hz4FixedAxisArtistHelper.get_tick_iterators.<locals>.f1)r   r1   r    r(   asarray	_extremessortedr   	full_liker   astypefloatr@   iter)r   r!   lat_levslat_n
lat_factorlon_levslon_n
lon_factoryy0dyxx0dxextremesxminxmaxyminymaxr%   maskxx00yy00rW   r   )r!   r1   rL   r   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   r   get_tick_iterators1   sd   




$z(FixedAxisArtistHelper.get_tick_iteratorsc                 C   sH   |  | tddddd| j \}}| j| | \}}tt||gS )N)
lon_lines0r   )rr   r   )
lat_lines0r   )rs   r   leftrightbottomtop)r   dictr   r    r   r(   column_stack)r   r!   kvxxyyr   r   r   get_line   s   
zFixedAxisArtistHelper.get_liner   )r
   r   r   r   r   rq   r   __classcell__r   r   r   r   r      s
    Vr   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rY   )r   ri   r   r   r   r      s   
	zExtremeFinderFixed.__init__c                 C   s   | j S r   r   )r   r%   r-   r.   r/   r0   r   r   r   __call__   s   zExtremeFinderFixed.__call__N)r
   r   r   r   r   r   r   r   r   r      s    r   c                       sZ   e Zd Z				d fdd	Zdd Z				dddZdd	 ZdddZdd Z  Z	S )GridHelperCurveLinearNc                    s*   || _ t|}t j||||||d d S )N)grid_locator1grid_locator2tick_formatter1tick_formatter2)rY   r   r   r   )r   	aux_transri   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   rt   )rY   ry   )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< |||f|d< |||f|d< |d|||d< |	d|||d< |d u rut
|d | }nt
|d | | }|d u rt
|d | }nt
|d | | }||||k ||	k @  ||
|k ||k @  ||	|
|\}}||d< ||d	< |j|d d |dd  g|R  \}}||d
< ||d< d S )Nr$   ri   r#   r"   rw   r;   r3   	lon_lines	lat_linesrr   rs   )r    ry   r1   r   inv_transform_xyrZ   r   r   r   r   r(   rX   _get_raw_grid_lines)r   r-   r.   r/   r0   r    r1   ri   lon_minlon_maxlat_minlat_maxrb   rc   rd   r_   r`   ra   
lon_values
lat_valuesr   r   r   r   r   _update_grid   sX   


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_gridlinesc              	   C   s   | j \}}}}| j}t||d}t||}t||}t||d}	t|	|}
t|	|}t|dd |dd |ddd |
g}t|dd |	dd |dd |	ddd g}|t||g }|S )zK
        Return (N, 2) array of (x, y) coordinate of the boundary.
        d   Nr   )	rY   
_aux_transr(   linspacer[   concatenater'   r)   	transpose)r   x0r-   y0r.   trr}   re   rR   r~   rg   rM   xxxyyytr   r   r   get_boundary$  s   ,4z"GridHelperCurveLinear.get_boundary)NNNN)r   r   )
r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s    
(
5r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
FloatingAxesBasec                 O   s^   | dd }|d u rtdt|dstd| jj| g|R i | | d |   d S )Nr   z*FloatingAxes requires grid_helper argumentr   z.grid_helper must implement get_boundary methodg      ?)get
ValueErrorhasattr_axes_class_floatingr   
set_aspectadjust_axes_lim)r   argskwargsr   r   r   r   r   ;  s   

zFloatingAxesBase.__init__c                 C   s   |   }| }t|S r   )get_grid_helperr   mpatchesPolygon)r   r   r   r   r   r   _gen_axes_patchG  s   
z FloatingAxesBase._gen_axes_patchc                 C   sj   | j |  | j| j | j | }|| j |d || j	 | j
| | j
| || _d S )NF)r   clapatchset_transformr&   r   
set_figurefigureset_visibler?   set_clip_path	gridlines_original_patch)r   r   r   r   r   r   M  s   

zFloatingAxesBase.clac                 C   s   |   }| }|d d df |d d df }}t|t|}}t|t|}}|| d }	|| d }
| ||	 ||	  | ||
 ||
  d S )Nr   r   r   )r   r   minmaxset_xlimset_ylim)r   r   r   r+   r,   rj   rk   rl   rm   rh   rf   r   r   r   r   \  s   "z FloatingAxesBase.adjust_axes_limN)r
   r   r   r   r   r   r   r   r   r   r   r   9  s
    r   c                 C   s   t d| j t| fd| iS )NzFloating %sr   )typer
   r   )
axes_classr   r   r   floatingaxes_class_factoryk  s   
r   ) __doc__	functoolsnumpyr(   matplotlib.patchespatchesr   matplotlib.pathr   matplotlib.axesr!   maxes%mpl_toolkits.axes_grid1.parasite_axesr    r   r   axis_artistr   r1   r   r	   r   r   r   r   	lru_cacher   AxesFloatingAxessubplot_class_factoryFloatingSubplotr   r   r   r   <module>   s0    
u 2
