U
    Âmœd'M  ã                   @   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 ddlmZmZ G d	d
„ d
ƒZG dd„ dƒZG dd„ dƒZG dd„ deƒZG dd„ dejƒZG dd„ deƒZeZeZdS )a�  
Axislines includes modified implementation of the Axes class. The
biggest difference is that the artists responsible for drawing the axis spine,
ticks, ticklabels and axis labels are separated out from Matplotlib's Axis
class. Originally, this change was motivated to support curvilinear
grid. Here are a few reasons that I came up with a new axes class:

* "top" and "bottom" x-axis (or "left" and "right" y-axis) can have
  different ticks (tick locations and labels). This is not possible
  with the current Matplotlib, although some twin axes trick can help.

* Curvilinear grid.

* angled ticks.

In the new axes class, xaxis and yaxis is set to not visible by
default, and new set of artist (AxisArtist) are defined to draw axis
line, ticks, ticklabels and axis label. Axes.axis attribute serves as
a dictionary of these artists, i.e., ax.axis["left"] is a AxisArtist
instance responsible to draw left y-axis. The default Axes.axis contains
"bottom", "left", "top" and "right".

AxisArtist can be considered as a container artist and has the following
children artists which will draw ticks, labels, etc.

* line
* major_ticks, major_ticklabels
* minor_ticks, minor_ticklabels
* offsetText
* label

Note that these are separate artists from `matplotlib.axis.Axis`, thus most
tick-related functions in Matplotlib won't work. For example, color and
markerwidth of the ``ax.axis["bottom"].major_ticks`` will follow those of
Axes.xaxis unless explicitly specified.

In addition to AxisArtist, the Axes will have *gridlines* attribute,
which obviously draws grid lines. The gridlines needs to be separated
from the axis as some gridlines can never pass any axis.
é    N)Ú_api)ÚPath)Úmpl_axesé   )ÚAxislineStyle)Ú
AxisArtistÚGridlinesCollectionc                   @   s>   e Zd ZdZG dd„ dƒZG dd„ deƒZG dd„ deƒZdS )	ÚAxisArtistHelperaG  
    Axis helpers should define the methods listed below.  The *axes* argument
    will be the axes attribute of the caller artist.

    ::

        # Construct the spine.

        def get_line_transform(self, axes):
            return transform

        def get_line(self, axes):
            return path

        # Construct the label.

        def get_axislabel_transform(self, axes):
            return transform

        def get_axislabel_pos_angle(self, axes):
            return (x, y), angle

        # Construct the ticks.

        def get_tick_transform(self, axes):
            return transform

        def get_tick_iterators(self, axes):
            # A pair of iterables (one for major ticks, one for minor ticks)
            # that yield (tick_position, tick_angle, tick_label).
            return iter_major, iter_minor
    c                   @   sX   e Zd ZdZdd„ Ze d¡edd„ dd„ ƒƒZe d¡edd„ d	d„ ƒƒZ	d
d„ Z
dS )zAxisArtistHelper._BasezBase class for axis helper.c                 C   s   d S ©N© ©ÚselfÚaxesr   r   úZ/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/mpl_toolkits/axisartist/axislines.pyÚ
update_limZ   s    z!AxisArtistHelper._Base.update_limú3.6c                 C   s   dS ©Ngñhãˆµøä>r   ©r   r   r   r   Ú<lambda>^   ó    zAxisArtistHelper._Base.<lambda>c                 C   s   d S r
   r   ©r   Úvaluer   r   r   r   ^   r   c                 C   s   dS r   r   r   r   r   r   r   `   r   c                 C   s   d S r
   r   r   r   r   r   r   `   r   c                 C   sL   | j dkr tjt ||¡dd�S | j dkr@tjt ||¡dd�S tdƒ‚dS )aÂ  
            Create a (*values.shape, 2)-shape array representing (x, y) pairs.

            *values* go into the coordinate determined by ``self.nth_coord``.
            The other coordinate is filled with the constant *const*.

            Example::

                >>> self.nth_coord = 0
                >>> self._to_xy([1, 2, 3], const=0)
                array([[1, 0],
                       [2, 0],
                       [3, 0]])
            r   éÿÿÿÿ©Úaxisr   zUnexpected nth_coordN)Ú	nth_coordÚnpÚstackZbroadcast_arraysÚ
ValueError)r   ÚvaluesÚconstr   r   r   Ú_to_xyb   s
    

zAxisArtistHelper._Base._to_xyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú
deprecatedÚpropertyZdelta1Zdelta2r!   r   r   r   r   Ú_BaseW   s   ÿÿr(   c                       sh   e Zd ZdZe d¡edd„ ƒƒZd‡ fdd„	Zdd	„ Z	d
d„ Z
dd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )zAxisArtistHelper.Fixedz7Helper class for a fixed (in the axes coordinate) axis.ú3.7c                 C   s   dddddœ| j  S )N)r   r   )r   r   ©r   r   ©ÚleftÚrightÚbottomÚtop)Ú_locr   r   r   r   r   |   s
    ÿÿzAxisArtistHelper.Fixed.<lambda>Nc                    sš   |dk	r|nt jdddddœ|d�| _|dkr6|dksF|dkr\|dkr\t jdd	|›d
�d� || _dddddœ| | _tƒ  ¡  t| j	d| jd�ƒ| _
dS )z5``nth_coord = 0``: x-axis; ``nth_coord = 1``: y-axis.Nr   r   ©r.   r/   r,   r-   )Úloc)r,   r-   ©r.   r/   r)   zloc=zI is incompatible with {nth_coord=}; support is deprecated since %(since)s)Úmessager*   ©r    )r   Zcheck_getitemr   Zwarn_deprecatedr0   Ú_posÚsuperÚ__init__r   r!   Ú_path)r   r2   r   ©Ú	__class__r   r   r8      s&     ÿþÿÿ 
ÿ
zAxisArtistHelper.Fixed.__init__c                 C   s   | j S r
   ©r   r   r   r   r   Úget_nth_coord�   s    z$AxisArtistHelper.Fixed.get_nth_coordc                 C   s   | j S r
   )r9   r   r   r   r   Úget_line•   s    zAxisArtistHelper.Fixed.get_linec                 C   s   |j S r
   ©Ú	transAxesr   r   r   r   Úget_line_transform˜   s    z)AxisArtistHelper.Fixed.get_line_transformc                 C   s   |j S r
   r?   r   r   r   r   Úget_axislabel_transform�   s    z.AxisArtistHelper.Fixed.get_axislabel_transformc                 C   s   t ddddd�| j S )ú˜
            Return the label reference position in transAxes.

            get_label_transform() returns a transform of (transAxes+offset)
            ))ç        ç      à?éZ   ))ç      ð?rE   rF   ))rE   rD   r   ))rE   rG   r   r+   )Údictr0   r   r   r   r   Úget_axislabel_pos_angle    s    ýýz.AxisArtistHelper.Fixed.get_axislabel_pos_anglec                 C   s   |  ¡ | ¡ g| j S r
   )Zget_xaxis_transformZget_yaxis_transformr   r   r   r   r   Úget_tick_transform­   s
    ÿÿz)AxisArtistHelper.Fixed.get_tick_transform)N)r"   r#   r$   r%   r   r&   r'   Zpassthru_ptr8   r=   r>   rA   rB   rI   rJ   Ú__classcell__r   r   r:   r   ÚFixedx   s   
ÿrL   c                       s,   e Zd Z‡ fdd„Zdd„ Zdd„ Z‡  ZS )zAxisArtistHelper.Floatingc                    s   || _ || _tƒ  ¡  d S r
   )r   Ú_valuer7   r8   )r   r   r   r:   r   r   r8   ³   s    z"AxisArtistHelper.Floating.__init__c                 C   s   | j S r
   r<   r   r   r   r   r=   ¸   s    z'AxisArtistHelper.Floating.get_nth_coordc                 C   s   t dƒ‚d S )Nz6get_line method should be defined by the derived class)ÚRuntimeErrorr   r   r   r   r>   »   s    ÿz"AxisArtistHelper.Floating.get_line)r"   r#   r$   r8   r=   r>   rK   r   r   r:   r   ÚFloating±   s   rO   N)r"   r#   r$   r%   r(   rL   rO   r   r   r   r   r	   5   s   !!9r	   c                   @   s0   e Zd ZG dd„ dejƒZG dd„ dejƒZdS )ÚAxisArtistHelperRectlinearc                       s&   e Zd Zd‡ fdd„	Zdd„ Z‡  ZS )z AxisArtistHelperRectlinear.FixedNc                    s&   t ƒ  ||¡ |j|jg| j | _dS )zŽ
            nth_coord = along which coordinate value varies
            in 2D, nth_coord = 0 ->  x axis, nth_coord = 1 -> y axis
            N)r7   r8   ÚxaxisÚyaxisr   r   )r   r   r2   r   r:   r   r   r8   Ä   s    z)AxisArtistHelperRectlinear.Fixed.__init__c           	         sŠ   ˆj dkrd\‰ ‰nd\‰ ‰ˆjj}| ¡ }|j |¡}ˆjj}| ¡ }|j |¡}ˆ |¡|j ‰‡ ‡‡‡fdd„}|||ƒ|||ƒfS )ú tick_loc, tick_angle, tick_labelr3   ©rF   r   ©r   rF   c                 3   sT   t | |ƒD ]D\}}ˆj|ˆjd�}ˆ |¡}tj d|ˆj ¡r
|ˆ ˆ|fV  q
d S )Nr5   r*   )Úzipr!   r6   Ú	transformÚmplZ
transformsZ_interval_contains_closer   )ÚlocsÚlabelsr2   ÚlabelÚcÚc2©Úangle_normalÚangle_tangentr   Ztick_to_axesr   r   Ú_fß   s    
 ÿz?AxisArtistHelperRectlinear.Fixed.get_tick_iterators.<locals>._f)	r0   r   ÚmajorÚlocatorÚ	formatterÚformat_ticksÚminorrJ   r@   ©	r   r   rb   Z
major_locsZmajor_labelsrf   Z
minor_locsZminor_labelsra   r   r^   r   Úget_tick_iteratorsÎ   s    

	z3AxisArtistHelperRectlinear.Fixed.get_tick_iterators)N)r"   r#   r$   r8   rh   rK   r   r   r:   r   rL   Â   s   
rL   c                       sN   e Zd Zd‡ fdd„	Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	‡  Z
S )z#AxisArtistHelperRectlinear.Floatingr.   c                    s,   t ƒ  ||¡ || _|j|jg| j | _d S r
   )r7   r8   Z_axis_directionrQ   rR   r   r   )r   r   r   Zpassingthrough_pointÚaxis_directionr:   r   r   r8   ë   s    z,AxisArtistHelperRectlinear.Floating.__init__c                 C   s>   d| j  }|j|j }| | j| jg¡}t| jd|| d�ƒS )Nr   r*   r5   )r   Ú	transDatar@   rW   rM   r   r!   )r   r   Úfixed_coordÚdata_to_axesÚpr   r   r   r>   ñ   s    
z,AxisArtistHelperRectlinear.Floating.get_linec                 C   s   |j S r
   r?   r   r   r   r   rA   ÷   s    z6AxisArtistHelperRectlinear.Floating.get_line_transformc                 C   s   |j S r
   r?   r   r   r   r   rB   ú   s    z;AxisArtistHelperRectlinear.Floating.get_axislabel_transformc                 C   st   ddg| j  }d| j  }|j|j }| | j| jg¡}| jd|| d�}d||   kr`dkrln n||fS dS dS )rC   r   rF   r   rE   r5   )NNN)r   rj   r@   rW   rM   r!   )r   r   Zanglerk   rl   rm   Zvertsr   r   r   rI   ý   s    
z;AxisArtistHelperRectlinear.Floating.get_axislabel_pos_anglec                 C   s   |j S r
   )rj   r   r   r   r   rJ     s    z6AxisArtistHelperRectlinear.Floating.get_tick_transformc           	         s†   ˆj dkrd\‰ ‰nd\‰ ‰ˆjj}| ¡ }|j |¡}ˆjj}| ¡ }|j |¡}|j|j ‰‡ ‡‡‡fdd„}|||ƒ|||ƒfS )rS   r   rT   rU   c                 3   st   t | |ƒD ]d\}}ˆj|ˆjd�}ˆ |¡\}}d|  krDdkr
n q
d|  kr\dkr
n q
|ˆ ˆ|fV  q
d S )Nr5   r   r   )rV   r!   rM   rW   )rY   rZ   r2   r[   r\   Úc1r]   ©r_   r`   rl   r   r   r   ra   !  s
    0zBAxisArtistHelperRectlinear.Floating.get_tick_iterators.<locals>._f)	r   r   rb   rc   rd   re   rf   rj   r@   rg   r   ro   r   rh     s    

z6AxisArtistHelperRectlinear.Floating.get_tick_iterators)r.   )r"   r#   r$   r8   r>   rA   rB   rI   rJ   rh   rK   r   r   r:   r   rO   ê   s    ÿrO   N)r"   r#   r$   r	   rL   rO   r   r   r   r   rP   À   s   (rP   c                       sF   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Ze d	¡d
d„ ƒZ	‡  Z
S )ÚGridHelperBasec                    s   d | _ tƒ  ¡  d S r
   )Ú_old_limitsr7   r8   r   r:   r   r   r8   -  s    zGridHelperBase.__init__c                 C   sL   |  ¡ \}}| ¡ \}}| j||||fkrH|  ||||¡ ||||f| _d S r
   )Úget_xlimÚget_ylimrq   Ú_update_grid)r   r   Úx1Úx2Úy1Úy2r   r   r   r   1  s
    zGridHelperBase.update_limc                 C   s   dS )z>Cache relevant computations when the axes limits have changed.Nr   )r   ru   rw   rv   rx   r   r   r   rt   8  s    zGridHelperBase._update_gridc                 C   s   g S )zÄ
        Return list of grid lines as a list of paths (list of points).

        Parameters
        ----------
        which : {"both", "major", "minor"}
        axis : {"both", "x", "y"}
        r   )r   Úwhichr   r   r   r   Úget_gridlines;  s    	zGridHelperBase.get_gridlinesr   c                 C   sJ   t d|jtjd tjd tjd d�}| |¡ | | ¡ |j |¡ |S )ú‘
        Create and return a new GridlineCollection instance.

        *which* : "major" or "minor"
        *axis* : "both", "x" or "y"

        Nú
grid.colorúgrid.linestyleúgrid.linewidth©rW   ÚcolorsZ
linestylesZ
linewidths)r   rj   rX   ÚrcParamsÚ_set_artist_propsÚset_grid_helperr   )r   ZaxÚ	gridlinesr   r   r   Únew_gridlinesF  s    	  ý

zGridHelperBase.new_gridlines)r"   r#   r$   r8   r   rt   rz   r   r&   r…   rK   r   r   r:   r   rp   +  s   rp   c                       s:   e Zd Z‡ fdd„Zddd„Zddd„Zddd„Z‡  ZS )ÚGridHelperRectlinearc                    s   t ƒ  ¡  || _d S r
   )r7   r8   r   r   r:   r   r   r8   `  s    
zGridHelperRectlinear.__init__Nc                 C   sF   |d krt  d¡ | j}t |||¡}|d kr2|}t||||d�}|S )Nz6'new_fixed_axis' explicitly requires the axes keyword.)Úoffsetri   )r   Úwarn_externalr   rP   rL   r   )r   r2   r   ri   r‡   r   Ú_helperÚaxisliner   r   r   Únew_fixed_axisd  s    ÿÿz#GridHelperRectlinear.new_fixed_axisr.   c                 C   sV   |d krt  d¡ | j}t ||||¡}t|||d�}|j d¡ |j |jj	¡ |S )Nz9'new_floating_axis' explicitly requires the axes keyword.)ri   T)
r   rˆ   r   rP   rO   r   ÚlineZset_clip_onZset_clip_boxZbbox)r   r   r   ri   r   r‰   rŠ   r   r   r   Únew_floating_axisz  s    ÿ   ÿz&GridHelperRectlinear.new_floating_axisrb   Úbothc                 C   s$  t jdddg|d� t jdddg|d� g }|dkržg }| j ¡ \}}|d	krb| | jjj ¡ ¡ |d
kr~| | jjj ¡ ¡ |D ]}| 	||g||gg¡ q‚|dk�r | j 
¡ \}}	g }| jjjd rÜ| | jjj ¡ ¡ | jjjd rþ| | jjj ¡ ¡ |D ]}
| 	||	g|
|
gg¡ �q|S )z¾
        Return list of gridline coordinates in data coordinates.

        Parameters
        ----------
        which : {"both", "major", "minor"}
        axis : {"both", "x", "y"}
        rŽ   rb   rf   )ry   ÚxÚyr   )rŽ   r�   )rŽ   rb   )rŽ   rf   )rŽ   r�   ÚgridOn)r   Zcheck_in_listr   rs   ÚextendrQ   rb   rc   rf   Úappendrr   rR   Ú_major_tick_kwÚ_minor_tick_kw)r   ry   r   r„   rY   rw   rx   r�   ru   rv   r�   r   r   r   rz   �  s,    	
z"GridHelperRectlinear.get_gridlines)NNNN)r.   N)rb   rŽ   )r"   r#   r$   r8   r‹   r�   rz   rK   r   r   r:   r   r†   ^  s       ü
  þ
r†   c                       s–   e Zd Zdd„ Zddœ‡ fdd„
Zddd„Zed	d
„ ƒZe 	d¡ddd„ƒZ
‡ fdd„Zdd„ Zd‡ fdd„	Z‡ fdd„Zd dd„Zd!dd„Z‡  ZS )"ÚAxesc                 O   s   t jj| jf|ž|ŽS r
   )Úmaxesr–   r   r   )r   ÚargsÚkwargsr   r   r   Ú__call__µ  s    zAxes.__call__N)Úgrid_helperc                   s4   d| _ |r|nt| ƒ| _tƒ j||Ž |  d¡ d S )NT)Ú_axisline_onr†   Ú_grid_helperr7   r8   Útoggle_axisline)r   r›   r˜   r™   r:   r   r   r8   ¸  s    ÿzAxes.__init__c                 C   s~   |d kr| j  }|rHd| _ | jd d …  d¡ | j d¡ | j d¡ n2d| _ | jd d …  d¡ | j d¡ | j d¡ d S )NTF)rœ   ZspinesÚset_visiblerQ   rR   )r   Úbr   r   r   rž   ¿  s    zAxes.toggle_axislinec                 C   s   | j S r
   )Ú
_axislinesr   r   r   r   r   Í  s    z	Axes.axisr   c                 C   s   |dkr|   ¡ }| | ¡}|S )r{   N)Úget_grid_helperr…   )r   r›   r„   r   r   r   r…   Ñ  s    	
zAxes.new_gridlinesc                    sÒ   t d ˆjtjd tjd tjd d� ˆ_}ˆ |¡ | ˆ ¡ ¡ tƒ  	¡  | 
ˆjj¡ tj ˆ¡ˆ_ˆ ¡ j‰ ˆj ‡ ‡fdd„dD ƒ¡ ˆjd ˆjd	 fD ](}|j d
¡ |j d
¡ |j d
¡ q¤d S )Nr|   r}   r~   r   c                    s   i | ]}|ˆ |ˆ|d �“qS ))r2   r   ri   r   )Ú.0r2   ©r‹   r   r   r   Ú
<dictcomp>ô  s   ÿ zAxes.clear.<locals>.<dictcomp>r1   r/   r-   F)r   rj   rX   r�   r„   r‚   rƒ   r¢   r7   ÚclearÚset_clip_pathr   Úpatchr   r–   ZAxisDictr¡   r‹   Úupdater[   rŸ   Zmajor_ticklabelsZminor_ticklabels)r   r„   rŠ   r:   r¤   r   r¦   à  s(     ü


þz
Axes.clearc                 C   s   | j S r
   )r�   r   r   r   r   r¢   ü  s    zAxes.get_grid_helperrb   rŽ   c                    sˆ   t ƒ j|f||dœ|—Ž | js$dS |dkrd| jjjd pb| jjjd pb| jjjd pb| jjjd }| jj	|||d� | jj	f |Ž dS )zW
        Toggle the gridlines, and optionally set the properties of the lines.
        )ry   r   Nr‘   )ry   r   Úvisible)
r7   Úgridrœ   r   rQ   r•   r”   rR   r„   Úset)r   rª   ry   r   r™   r:   r   r   r«   ÿ  s    ÿþýz	Axes.gridc                    s2   | j r| j ¡ | jf•}ng }| tƒ  ¡ ¡ |S r
   )rœ   r¡   r   r„   r’   r7   Úget_children)r   Úchildrenr:   r   r   r­     s
    zAxes.get_childrenc                 C   s    |   ¡ }|j|d d || d�}|S )N)r   ri   r‡   r   )r¢   r‹   )r   r2   r‡   Úghr   r   r   r   r‹     s    üzAxes.new_fixed_axisr.   c                 C   s   |   ¡ }|j|||| d�}|S )N)ri   r   )r¢   r�   )r   r   r   ri   r¯   r   r   r   r   r�   #  s    þzAxes.new_floating_axis)N)N)Nrb   rŽ   )N)r.   )r"   r#   r$   rš   r8   rž   r'   r   r   r&   r…   r¦   r¢   r«   r­   r‹   r�   rK   r   r   r:   r   r–   ³  s   



r–   c                       s   e Zd Z‡ fdd„Z‡  ZS )ÚAxesZeroc                    sn   t ƒ  ¡  |  ¡ j}| jj|ddd| d�|ddd| d�d� dD ](}| j| j | j¡ | j|  	d¡ q@d S )	Nr   rD   r.   )r   r   ri   r   r   r,   )ZxzeroZyzeroF)
r7   r¦   r¢   r�   r¡   r©   rŒ   r§   r¨   rŸ   )r   r�   Úkr:   r   r   r¦   -  s&    

   ÿ   ÿýzAxesZero.clear)r"   r#   r$   r¦   rK   r   r   r:   r   r°   +  s   r°   )r%   Únumpyr   Z
matplotlibrX   r   Zmatplotlib.axesr   r—   Zmatplotlib.pathr   Zmpl_toolkits.axes_grid1r   Zaxisline_styler   Zaxis_artistr   r   r	   rP   rp   r†   r–   r°   ZSubplotZSubplotZeror   r   r   r   Ú<module>   s"   ) k3Ux