o
    tBh2                     @   s   d 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 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 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   |/var/www/html/riverr-enterprise-integrations-main/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                    s$      j }|t| |gjS r    )get_transform	transData	transformnpcolumn_stackT)xytrf)r#   grid_finderr   r   transform_xyK   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>`       z<FixedAxisArtistHelper.get_tick_iterators.<locals>.<listcomp>r   
lon_labelsc                 S   r4   r   r   r5   r   r   r   r9   s   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   f1u   s   Hz4FixedAxisArtistHelper.get_tick_iterators.<locals>.f1)r   r0   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ymaxr1   maskxx00yy00rW   r   )r#   r0   rL   r   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   r   get_tick_iterators0   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*   r+   )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
    Ur   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   r1   x1y1x2y2r   r   r   __call__   s   zExtremeFinderFixed.__call__N)r   r   r   r   r   r   r   r   r   r      s    r   c                       sd   e Zd Z				d fdd	Zdd Z				dddZdd	 ZdddZe	d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   r0   r   inv_transform_xyrZ   r   r   r   r   r*   rX   _get_raw_grid_lines)r   r   r   r   r   	grid_infor0   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_gridlinesz3.5c              	   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)   array	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   
deprecatedr   r   r   r   r   r   r      s     
(
5r   c                       s8   e Zd Z fddZdd Z fddZdd Z  ZS )	FloatingAxesBasec                    sV   | dd }|d u rtdt|dstdt j|i | | d |   d S )Nr   z*FloatingAxes requires grid_helper argumentr   z.grid_helper must implement get_boundary methodg      ?)get
ValueErrorhasattrr   r   
set_aspectadjust_axes_lim)r   argskwargsr   r   r   r   r   :  s   

zFloatingAxesBase.__init__c                 C   s\   t |  jg d\\}}\}}\}}\}}t||f||f||f||fg}d| _|S )Nrt   r   )mapget_grid_helperr   mpatchesPolygonget_path_interpolation_steps)r   r   _r   r   r   patchr   r   r   _gen_axes_patchD  s   "
z FloatingAxesBase._gen_axes_patchc                    sd   t    | j|  j | j  t   }|	| j
 || j | j| | j| d S r    )r   clar   set_transformr   r0   r'   r(   r   
set_figurefigurer?   set_clip_path	gridlines)r   
orig_patchr   r   r   r   N  s   

zFloatingAxesBase.clac                 C   sL   | j  | j  | j }|dd}| |j|j | 	|j
|j d S )NgRQ?)r   r   get_extentsr'   r(   expandedset_xlimrj   rk   set_ylimrl   rm   )r   r   r   r   r   r   [  s   
z FloatingAxesBase.adjust_axes_lim)r   r   r   r   r   r   r   r   r   r   r   r   r   8  s
    

r   z
Floating{})"__doc__numpyr*   
matplotlibr   r   matplotlib.patchespatchesr   matplotlib.pathr   matplotlib.axesr#   maxes%mpl_toolkits.axes_grid1.parasite_axesr    r   r   axis_artistr	   r0   r
   r   r   r   r   r   _make_class_factoryfloatingaxes_class_factoryAxesFloatingAxessubplot_class_factoryFloatingSubplotr   r   r   r   <module>   s2    
t ,