a
    r=icvK                     @   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eeZG dd deZe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 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 )	AxisArtistHelperac  
    AxisArtistHelper should define
    following method with given APIs. Note that the first axes argument
    will be axes attribute of the caller artist.::


        # LINE (spinal line?)

        def get_line(self, axes):
            # path : Path
            return path

        def get_line_transform(self, axes):
            # ...
            # trans : transform
            return trans

        # LABEL

        def get_label_pos(self, axes):
            # x, y : position
            return (x, y), trans


        def get_label_offset_transform(self,
                axes,
                pad_points, fontprops, renderer,
                bboxes,
                ):
            # va : vertical alignment
            # ha : horizontal alignment
            # a : angle
            return trans, va, ha, a

        # TICK

        def get_tick_transform(self, axes):
            return trans

        def get_tick_iterators(self, axes):
            # iter : iterable object that yields (c, angle, l) where
            # c, angle, l is position, tick angle, and label

            return iter_major, iter_minor
    c                   @   sP   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
S )zAxisArtistHelper._BasezBase class for axis helper.c                 C   s   d S N selfaxesr   r   r/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/mpl_toolkits/axisartist/axislines.py
update_limg   s    z!AxisArtistHelper._Base.update_lim3.6c                 C   s   dS Ngh㈵>r   r   r   r   r   <lambda>k       zAxisArtistHelper._Base.<lambda>c                 C   s   d S r
   r   r   valuer   r   r   r   k   r   c                 C   s   dS r   r   r   r   r   r   r   m   r   c                 C   s   d S r
   r   r   r   r   r   r   m   r   N)
__name__
__module____qualname____doc__r   r   
deprecatedpropertyZdelta1Zdelta2r   r   r   r   _Based   s   r   c                       sb   e Zd ZdZeddd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.)r   r   )r   r   r   r   leftrightbottomtopNc                    s   t jg d|d || _|du r:|dv r.d}n|dv r:d}|| _t   | j| | _t	ddgd	d	gg}d| }| j| |dd|f< t
|| _dS )

            nth_coord = along which coordinate value varies
            in 2D, nth_coord = 0 ->  x axis, nth_coord = 1 -> y axis
            r    )locN)r!   r"   r   r#   r$   r                 ?)r   Zcheck_in_list_loc	nth_coordsuper__init___default_passthru_ptpassthru_ptnparrayr   _path)r   r&   r+   _vertsfixed_coord	__class__r   r   r-   w   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
   )r2   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)
            ))r(         ?Z   ))r)   r?   r@   ))r?   r(   r   ))r?   r)   r   r    )dictr*   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   rA   r.   r-   r8   r9   r<   r=   rB   rC   __classcell__r   r   r5   r   Fixedo   s   rE   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+   _valuer,   r-   )r   r+   r   r5   r   r   r-      s    z"AxisArtistHelper.Floating.__init__c                 C   s   | j S r
   r7   r   r   r   r   r8      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   r9      s    z"AxisArtistHelper.Floating.get_line)r   r   r   r-   r8   r9   rD   r   r   r5   r   Floating   s   rH   N)r   r   r   r   r   rE   rH   r   r   r   r   r	   5   s   .Er	   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 )r%   N)r,   r-   xaxisyaxisr+   axis)r   r   r&   r+   r5   r   r   r-      s    z)AxisArtistHelperRectlinear.Fixed.__init__c           	         s   j dv rd\ nd\ jj}| }|j|}jj}| }|j|}||j  fdd}||||||fS ) tick_loc, tick_angle, tick_labelr'   r@   r   r   r@   c                 3   sX   t | |D ]H\}}tj}||j< |}tjd|j r
| |fV  q
d S )Nr   )ziplistr/   r+   	transformmplZ
transformsZ_interval_contains_close)locslabelsxlcc2angle_normalangle_tangentr   Ztick_to_axesr   r   _f   s    



z?AxisArtistHelperRectlinear.Fixed.get_tick_iterators.<locals>._f)	r*   rL   majorlocator	formatterformat_ticksminorrC   r;   	r   r   r^   Z
major_locsZmajor_labelsrb   Z
minor_locsZminor_labelsr]   r   rZ   r   get_tick_iterators   s    


z3AxisArtistHelperRectlinear.Fixed.get_tick_iterators)N)r   r   r   r-   rd   rD   r   r   r5   r   rE      s   
rE   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
   )r,   r-   Z_axis_directionrJ   rK   r+   rL   )r   r   r+   Zpassingthrough_pointaxis_directionr5   r   r   r-      s    z,AxisArtistHelperRectlinear.Floating.__init__c                 C   sZ   t ddgddgg}d| j }|j|j }|| j| jg}|| |d d |f< t|S )Nr(   r)   r   )r0   r1   r+   	transDatar;   rR   rF   r   )r   r   r3   r4   data_to_axespr   r   r   r9      s    

z,AxisArtistHelperRectlinear.Floating.get_linec                 C   s   |j S r
   r:   r   r   r   r   r<      s    z6AxisArtistHelperRectlinear.Floating.get_line_transformc                 C   s   |j S r
   r:   r   r   r   r   r=     s    z;AxisArtistHelperRectlinear.Floating.get_axislabel_transformc                 C   sv   ddg| j  }ddg}d| j  }|j|j }|| j| jg}|| ||< d||   krbdkrnn n||fS dS dS )r>   r   r@   r?   r   )NNN)r+   rf   r;   rR   rF   )r   r   Zangler3   r4   rg   rh   r   r   r   rB     s    
z;AxisArtistHelperRectlinear.Floating.get_axislabel_pos_anglec                 C   s   |j S r
   )rf   r   r   r   r   rC     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 )rM   r   rN   rO   c                 3   sz   t | |D ]j\}}jjg}||j< |\}}d|  krJdkr
n q
d|  krbdkr
n q
| |fV  q
d S )Nr   r   )rP   rF   r+   rR   )rT   rU   rV   rW   rX   c1rY   r[   r\   rg   r   r   r   r]   +  s    
0zBAxisArtistHelperRectlinear.Floating.get_tick_iterators.<locals>._f)	r+   rL   r^   r_   r`   ra   rb   rf   r;   rc   r   rj   r   rd     s    

z6AxisArtistHelperRectlinear.Floating.get_tick_iterators)r#   )r   r   r   r-   r9   r<   r=   rB   rC   rd   rD   r   r   r5   r   rH      s    rH   N)r   r   r   r	   rE   rH   r   r   r   r   rI      s   )rI   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_limitsr,   r-   r   r5   r   r   r-   8  s    zGridHelperBase.__init__c                 C   sL   |  \}}| \}}| j||||fkrH| |||| ||||f| _d S r
   )get_xlimget_ylimrl   _update_grid)r   r   x1x2y1y2r   r   r   r   <  s
    zGridHelperBase.update_limc                 C   s   dS )z>Cache relevant computations when the axes limits have changed.Nr   )r   rp   rr   rq   rs   r   r   r   ro   C  s    zGridHelperBase._update_gridc                 C   s   g S )z
        Return list of grid lines as a list of paths (list of points).

        *which* : "major" or "minor"
        *axis* : "both", "x" or "y"
        r   )r   whichrL   r   r   r   get_gridlinesF  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rR   colorsZ
linestylesZ
linewidths)r   rf   rS   rcParams_set_artist_propsset_grid_helperr   )r   ax	gridlinesr   r   r   new_gridlinesO  s    	

zGridHelperBase.new_gridlines)r   r   r   r-   r   ro   ru   r   r   r   rD   r   r   r5   r   rk   6  s   	rk   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
   )r,   r-   r   r   r5   r   r   r-   i  s    
zGridHelperRectlinear.__init__Nc                 C   sF   |d u rt d | j}t|||}|d u r2|}t||||d}|S )Nz6'new_fixed_axis' explicitly requires the axes keyword.)offsetre   )r   warn_externalr   rI   rE   r   )r   r&   r+   re   r   r   _helperaxisliner   r   r   new_fixed_axism  s    z#GridHelperRectlinear.new_fixed_axisr#   c                 C   sV   |d u rt d | j}t||||}t|||d}|jd |j|jj	 |S )Nz9'new_floating_axis' explicitly requires the axes keyword.)re   T)
r   r   r   rI   rH   r   lineZset_clip_onZset_clip_boxZbbox)r   r+   r   re   r   r   r   r   r   r   new_floating_axis  s    z&GridHelperRectlinear.new_floating_axisr^   bothc                 C   s   g }|dv rvg }| j  \}}|dv r:|| j jj  |dv rV|| j jj  |D ]}|||g||gg qZ|dv 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.

        *which* : "major" or "minor"
        *axis* : "both", "x" or "y"
        )r   rV   )r   r^   )r   rb   )r   ygridOn)r   rn   extendrJ   r^   r_   rb   appendrm   rK   _major_tick_kw_minor_tick_kw)r   rt   rL   r   rT   rr   rs   rV   rp   rq   r   r   r   r   ru     s(    z"GridHelperRectlinear.get_gridlines)NNNN)r#   N)r^   r   )r   r   r   r-   r   r   ru   rD   r   r   r5   r   r   g  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eddd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g|R i |S r
   )maxesr   rL   r   )r   argskwargsr   r   r   __call__  s    zAxes.__call__N)grid_helperc                   s8   d| _ |r|nt| | _t j|i | | d d S )NT)_axisline_onr   _grid_helperr,   r-   toggle_axisline)r   r   r   r   r5   r   r   r-     s    zAxes.__init__c                 C   s~   |d u 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_visiblerJ   rK   )r   br   r   r   r     s    zAxes.toggle_axislinec                 C   s   | j S r
   )
_axislinesr   r   r   r   rL     s    z	Axes.axisr   c                 C   s   |du r|   }|| }|S )rv   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
 qd S )Nrw   rx   ry   rz   c                    s   i | ]}| ||d qS ))r&   r   re   r   ).0r&   r   r   r   r   
<dictcomp>  s   zAxes.clear.<locals>.<dictcomp>)r#   r$   r!   r"   r$   r"   F)r   rf   rS   r|   r   r}   r~   r   r,   clearset_clip_pathr   patchr   r   ZAxisDictr   r   updatelabelr   Zmajor_ticklabelsZminor_ticklabels)r   r   r   r5   r   r   r     s&    


z
Axes.clearc                 C   s   | j S r
   )r   r   r   r   r   r     s    zAxes.get_grid_helperz3.5r   visibler^   r   c                    s   t  j|f||d| | js$dS |du 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 i | dS )zW
        Toggle the gridlines, and optionally set the properties of the lines.
        )rt   rL   Nr   )rt   rL   r   )
r,   gridr   r   rJ   r   r   rK   r   set)r   r   rt   rL   r   r5   r   r   r     s    z	Axes.gridc                    s4   | j rg | j | j}ng }|t   |S r
   )r   r   valuesr   r   r,   get_children)r   childrenr5   r   r   r     s
    zAxes.get_childrenc                 C   s    |   }|j|d d || d}|S )N)r+   re   r   r   )r   r   )r   r&   r   ghrL   r   r   r   r     s    zAxes.new_fixed_axisr#   c                 C   s   |   }|j|||| d}|S )N)re   r   )r   r   )r   r+   r   re   r   rL   r   r   r   r   )  s    zAxes.new_floating_axis)N)N)Nr^   r   )N)r#   )r   r   r   r   r-   r   r   rL   r   r   r   r   r   Zrename_parameterr   r   r   r   rD   r   r   r5   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   r(   r#   )r+   r   re   r   r   r!   )ZxzeroZyzeroF)
r,   r   r   r   r   r   r   r   r   r   )r   r   kr5   r   r   r   6  s    

zAxesZero.clear)r   r   r   r   rD   r   r   r5   r   r   4  s   r   )r   numpyr0   Z
matplotlibrS   r   Zmatplotlib.axesr   r   Zmatplotlib.pathr   Zmpl_toolkits.axes_grid1r   Zaxisline_styler   Zaxis_artistr   r   r	   rI   rk   r   r   Zsubplot_class_factoryZSubplotr   ZSubplotZeror   r   r   r   <module>   s"   ) s1Qy
