o
    i*                     @   s   d dl Zd dlmZmZ d dlmZmZ ddl	m
Z
 dd ZG dd	 d	ZG d
d dZedG dd deZG dd dejZG dd dZG dd dZG dd dZdS )    N)cbookticker)Bbox	Transform   )clip_line_to_rectc                 C   s   | d u rt jddd d} | S )N3.2znfactor=None is deprecated since %(since)s and support will be removed %(removal)s; use/return factor=1 instead)messager   )r   warn_deprecated)factor r   ^/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/mpl_toolkits/axisartist/grid_finder.py_deprecate_factor_none   s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ExtremeFinderSimplezU
    A helper class to figure out the range of grid lines that need to be drawn.
    c                 C   s   || _ || _dS )zy
        Parameters
        ----------
        nx, ny : int
            The number of samples in each direction.
        Nnxny)selfr   r   r   r   r   __init__   s   
zExtremeFinderSimple.__init__c           
      C   sb   t t ||| jt ||| j\}}|t |t |\}}	| | | |	 |	 S )ai  
        Compute an approximation of the bounding box obtained by applying
        *transform_xy* to the box delimited by ``(x1, y1, x2, y2)``.

        The intended use is to have ``(x1, y1, x2, y2)`` in axes coordinates,
        and have *transform_xy* be the transform from axes coordinates to data
        coordinates; this method then returns the range of data coordinates
        that span the actual axes.

        The computation is done by sampling ``nx * ny`` equispaced points in
        the ``(x1, y1, x2, y2)`` box and finding the resulting points with
        extremal coordinates; then adding some padding to take into account the
        finite sampling.

        As each sampling step covers a relative range of *1/nx* or *1/ny*,
        the padding is computed by expanding the span covered by the extremal
        coordinates by these fractions.
        )	npmeshgridlinspacer   r   ravel_add_padminmax)
r   transform_xyx1y1x2y2xyxtytr   r   r   __call__"   s
    zExtremeFinderSimple.__call__c                 C   s8   || | j  }|| | j }|| || || || fS )z,Perform the padding mentioned in `__call__`.r   )r   x_minx_maxy_miny_maxdxdyr   r   r   r   :   s   zExtremeFinderSimple._add_padN)__name__
__module____qualname____doc__r   r%   r   r   r   r   r   r      s
    
r   c                   @   sH   e Zd Z					dddZdd Zdd Zdd	 Zd
d Zdd ZdS )
GridFinderNc                 C   sv   |du r	t dd}|du rt }|du rt }|du rt }|du r%t }|| _|| _|| _|| _|| _| | dS )a  
        transform : transform from the image coordinate (which will be
        the transData of the axes to the world coordinate.

        or transform = (transform_xy, inv_transform_xy)

        locator1, locator2 : grid locator for 1st and 2nd axis.
        N   )	r   MaxNLocatorFormatterPrettyPrintextreme_findergrid_locator1grid_locator2tick_formatter1tick_formatter2update_transform)r   	transformr4   r5   r6   r7   r8   r   r   r   r   B   s    
zGridFinder.__init__c              
   C   s`  |  | j||||}|\}}}}	| ||\}
}}| ||	\}}}|
d| t| }|d| t| }| ||||||	\}}|| d }|| d }t|| || || || }|||| |||
|| ||||d}i  }|d d< dD ]}|d d | }| 	|||||< q|i  }|d d< dD ]}|d d | }| 
|||||< q|S )	z
        lon_values, lat_values : list of grid values. if integer is given,
                           rough number of grids in each direction.
        Ng|=)extremes	lon_lines	lat_lineslonlatr>   tick_labelsleftbottomrighttoptick_levelsr?   )r4   inv_transform_xyr5   r6   r   _get_raw_grid_linesr   from_extents_clip_grid_lines_and_find_ticksr7   r8   )r   r   r   r   r    r;   lon_minlon_maxlat_minlat_maxlon_levslon_n
lon_factorlat_levslat_n
lat_factor
lon_values
lat_valuesr<   r=   ddxddybb	grid_info
tck_labels	directionlevsr   r   r   get_grid_infob   sJ    


zGridFinder.get_grid_infoc           	         sL   t ||dt ||d  fdd|D }fdd|D }||fS )Nd   c                    s    g | ]} t | qS r   r   r   	full_like).0r>   )lats_ir   r   r   
<listcomp>       z2GridFinder._get_raw_grid_lines.<locals>.<listcomp>c              	      s    g | ]}  t |qS r   r`   )rb   r?   )lons_ir   r   r   rd      re   )r   r   )	r   rU   rV   rK   rL   rM   rN   r<   r=   r   )rc   rf   r   r   rH      s   zGridFinder._get_raw_grid_linesc              	   C   s   g g t g g g g dt g g g g dg d}|d }|d }t|||D ]?\\}}	}
}t||	|\}}|s4q"|d |
 |d | t|g dD ]\}}|D ]}|| | || | qOqIq"|S )NrA   )valueslevelsrF   	tick_locslinesrF   ri   rh   rj   )dictzipr   append)r   rj   rg   r]   rY   gi
tck_levelstck_locslxlyvlevxytckstckr\   tr   r   r   rJ      s.   z*GridFinder._clip_grid_lines_and_find_ticksc                    s<   t  tr fdd} fdd}n \}}|| _|| _d S )Nc                    sB   t | |g} |}|d d df |d d df }}||fS Nr   r   )r   column_stackr:   r!   r"   ll1ll2r>   r?   	aux_transr   r   r      s   
"z1GridFinder.update_transform.<locals>.transform_xyc                    sF   t | |g}  |}|d d df |d d df }}||fS ry   )r   rz   invertedr:   r{   r~   r   r   rG      s   "z5GridFinder.update_transform.<locals>.inv_transform_xy)
isinstancer   r   rG   )r   r   r   rG   r   r~   r   r9      s   

zGridFinder.update_transformc                 K   s2   |D ]}|dv rt | |||  qtd| d S )N)r4   r5   r6   r7   r8   zUnknown update property '%s')setattr
ValueError)r   kwkr   r   r   update   s
   zGridFinder.update)NNNNN)	r,   r-   r.   r   r^   rH   rJ   r9   r   r   r   r   r   r0   A   s    
 3r0   r   c                       s&   e Zd Z				d fdd	Z  ZS )GridFinderBaseNc                    s   t  d||||| d S )N)NN)superr   )r   r4   r5   r6   r7   r8   	__class__r   r   r      s   
zGridFinderBase.__init__)NNNN)r,   r-   r.   r   __classcell__r   r   r   r   r      s    r   c                   @   s:   e Zd Z					dddZdd Zed	d
d ZdS )r2   
   NTFc                 C   s*   t jj| |||||d |   d| _d S )N)stepsinteger	symmetricpruner   )mtickerr2   r   create_dummy_axis_factor)r   nbinsr   trimr   r   r   r   r   r   r      s   
zMaxNLocator.__init__c                 C   s:   |  || j || j  tj| }t|t|| jfS N)
set_boundsr   r   r2   r%   r   arraylenr   v1v2locsr   r   r   r%      s   zMaxNLocator.__call__3.3c                 C      t || _d S r   r   r   r   fr   r   r   
set_factor      zMaxNLocator.set_factor)r   NTFFNr,   r-   r.   r   r%   r   
deprecatedr   r   r   r   r   r2      s    
r2   c                   @   s.   e Zd Zdd Zdd Zeddd ZdS )	FixedLocatorc                 C   s   || _ d| _d S )Nr   )_locsr   )r   r   r   r   r   r     s   
zFixedLocator.__init__c                    sH   t  | j | j g\ t fdd| jD }|t|| jfS )Nc                    s(   g | ]} |  krkrn n|qS r   r   )rb   lr   r   r   r   rd     s   ( z)FixedLocator.__call__.<locals>.<listcomp>)sortedr   r   r   r   r   r   r   r   r   r%     s   zFixedLocator.__call__r   c                 C   r   r   r   r   r   r   r   r     r   zFixedLocator.set_factorNr   r   r   r   r   r     s
    r   c                   @   s   e Zd ZdddZdd ZdS )r3   Tc                 C   s   t j|dd| _| j  d S )NF)useMathText	useOffset)r   ScalarFormatter_fmtr   )r   r   r   r   r   r     s   zFormatterPrettyPrint.__init__c                 C   s   | j |S r   )r   format_ticks)r   r\   r   rg   r   r   r   r%     s   zFormatterPrettyPrint.__call__N)T)r,   r-   r.   r   r%   r   r   r   r   r3     s    
r3   c                       s&   e Zd Zd fdd	Zdd Z  ZS )DictFormatterNc                    s   t    || _|| _dS )zq
        format_dict : dictionary for format strings to be used.
        formatter : fall-back formatter
        N)r   r   _format_dict_fallback_formatter)r   format_dict	formatterr   r   r   r     s   

zDictFormatter.__init__c                    s<    j r  |||}ndgt| } fddt||D S )zG
        factor is ignored if value is found in the dictionary
         c                    s   g | ]\}} j ||qS r   )r   get)rb   r   rs   r   r   r   rd   /  s    z*DictFormatter.__call__.<locals>.<listcomp>)r   r   rl   )r   r\   r   rg   fallback_stringsr   r   r   r%   &  s   
zDictFormatter.__call__r   )r,   r-   r.   r   r%   r   r   r   r   r   r     s    	r   )numpyr   
matplotlibr   r   r   matplotlib.transformsr   r   	clip_pathr   r   r   r0   r   r   r2   r   r3   r   r   r   r   r   <module>   s    . 
