o
    :a2                     @   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   G/usr/lib/python3/dist-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yZ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   r3   r   r   r4   r   r   r   r8   s   r9   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*   Zarctan2ZpiZget_tick_transform	transAxeszipr)   Zrad2deg)ddZdd2ZmmZtick_to_axesr-   r.   dZd2ZlabZc2ZdeltaZd1)r#   labelsr   xx1xx1axx1bxx2axx2byy1yy1ayy1byy2ayy2br   r   f1u   s   Hz4FixedAxisArtistHelper.get_tick_iterators.<locals>.f1)r   r/   r"   r*   asarray	_extremessortedr   	full_liker   Zastypefloatr<   iter)r   r#   lat_levslat_n
lat_factorlon_levslon_n
lon_factoryy0Zdyxx0Zdxextremesxminxmaxyminymaxr0   maskZxx00Zyy00rJ   r   )r#   r/   r?   r   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   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   )r`   r   )
lat_lines0r   )ra   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!   r_   rl   __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rL   )r   rY   r   r   r   r      s   
	zExtremeFinderFixed.__init__c                 C   s   | j S r    ro   )r   r0   x1y1x2y2r   r   r   __call__   s   zExtremeFinderFixed.__call__N)r   r   r   r   rt   r   r   r   r   rn      s    rn   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)rL   rn   r   r   )r   Z	aux_transrY   rv   rw   rx   ry   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   rb   )rL   rg   )r   r   Zlon1Zlon2Zlat1Z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	   lineZset_clip_onZset_clip_boxbbox)r   locr   r   offsetr#   Z_helperZ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&   rY   r%   r$   re   r:   r2   	lon_lines	lat_linesr`   ra   )r"   rg   r/   rz   Zinv_transform_xyrM   rv   rw   rx   ry   r*   rK   Z_get_raw_grid_lines)r   rp   rq   rr   rs   Z	grid_infor/   rY   Zlon_minZlon_maxZlat_minZlat_maxrT   rU   rV   rQ   rR   rS   Z
lon_valuesZ
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   whichZaxisZ
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   )	rL   Z
_aux_transr*   ZlinspacerN   Zconcatenater)   ZarrayZ	transpose)r   x0rp   y0rq   trrj   rW   rE   rk   rX   r@   ZxxxZyyytr   r   r   get_boundary"  s   ,4z"GridHelperCurveLinear.get_boundary)NNNN)r   r   )r   r   r   r   r   r   r   r   r   Z
deprecatedr   rm   r   r   r   r   ru      s     
(
5ru   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   Z
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 )Nrb   r   )mapget_grid_helperr   mpatchesZPolygonget_pathZ_interpolation_steps)r   r   _rp   r   rq   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   Zset_transformr   r/   r'   r(   r   Z
set_figureZfigurer;   Zset_clip_pathZ	gridlines)r   Z
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   Zget_extentsr'   r(   ZexpandedZset_xlimrZ   r[   Zset_ylimr\   r]   )r   r|   r   r   r   r   [  s   
z FloatingAxesBase.adjust_axes_lim)r   r   r   r   r   r   r   rm   r   r   r   r   r   8  s
    

r   z
Floating{})"__doc__Znumpyr*   Z
matplotlibr   r   Zmatplotlib.patchesZpatchesr   Zmatplotlib.pathr   Zmatplotlib.axesr#   ZmaxesZ%mpl_toolkits.axes_grid1.parasite_axesr    r   r   Zaxis_artistr	   r/   r
   r   r   rn   ru   r   Z_make_class_factoryZfloatingaxes_class_factoryZAxesZFloatingAxesZsubplot_class_factoryZFloatingSubplotr   r   r   r   <module>   s2    
t ,