a
    ضaLe                    @   sl  d Z ddlZddlZddl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 ddlmZ ddlmZ ddlmZ e e!Z"dZ#e$ej%Z&e&' Z(dd e&j)* D Z+dd e(e+ D Z,G dd	 d	ej-Z.G d
d de.Z/G dd de.Z0G dd dZ1G dd dZ2G dd dej-Z3dd Z4G dd de3Z5G dd de3Z6dS )z)
Classes for the ticks and x and y axis.
    N)_api   c                 C   s   g | ]}t |d  qS r   )list).0d r   _/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/matplotlib/axis.py
<listcomp>       r
   c                 C   s   g | ]}d | qS )grid_r   )r   namer   r   r	   r
      s   c                       s`  e Zd ZdZdddddddddddddddddddd fdd
Zeejd	d
dddd Zdd Z	dd Z
ejddddd Zdd Zdd Zdd ZdG fdd	Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zejd3d4 Zd5d6 ZeZd7d8 Z fd9d:Z d;d< Z!d=d> Z"d?d@ Z#dAdB Z$dCdD Z%dEdF Z&  Z'S )HTicka  
    Abstract base class for the axis ticks, grid lines and labels.

    Ticks mark a position on an Axis. They contain two lines as markers and
    two labels; one each for the bottom and top positions (in case of an
    `.XAxis`) or for the left and right positions (in case of a `.YAxis`).

    Attributes
    ----------
    tick1line : `.Line2D`
        The left/bottom tick marker.
    tick2line : `.Line2D`
        The right/top tick marker.
    gridline : `.Line2D`
        The grid line associated with the label position.
    label1 : `.Text`
        The left/bottom tick label.
    label2 : `.Text`
        The right/top tick label.

    NTFr   )sizewidthcolortickdirpad	labelsize
labelcolorzordergridOntick1Ontick2Onlabel1Onlabel2Onmajorlabelrotation
grid_colorgrid_linestylegrid_linewidth
grid_alphac                   s  t    |du rR|r0tjd dv r0tjd }n"|sNtjd dv rNtjd }nd}| |j || _|| _|| _| j	}|r~dnd}|du rtj| d	| d
 }|| _
|du rtj| d	| d }|| _|du rtj| d }|du rtj| d	| d }|| _|	du r"tj| d }	|	dkr<tj| d }	|du rVtj| d }| | |
du r|r~tjjd }
ntjj}
|
| _|du rtjd }|du rtjd }|du rtjd }|du rtjd }dd | D }tjg g |d|
||||d	| _tjg g |d|
||||d	| _tjg g f|||||dd|| _t| j _tjtjtj||	|| jd d| _tjtjtj||	|| jd d| _|  | | j| j| j| j| jfD ]}| !| q| "| dS )z
        bbox is the Bound2D bounding box in display coords of the Axes
        loc is the tick location in data coords
        size is the tick size in points
        Naxes.grid.whichbothr   	axes.gridr$   minorFr   r'   .z.sizez.widthz.colorz.padz.labelcolorZinheritz
.labelsizeg{Gz?z
grid.colorzgrid.linestylezgrid.linewidthz
grid.alphac                 S   s   i | ]\}}|d d |qS    Nr   r   kvr   r   r	   
<dictcomp>   r   z!Tick.__init__.<locals>.<dictcomp>none)r   	linestyler   visiblemarkeredgecolorZ
markersizeZmarkeredgewidth )r   alphar1   r0   Z	linewidthmarker   )fontsizer   r1   rotation)#super__init__mplrcParams
set_figurefigureaxes_loc_major__name___size_width	_base_pad_set_labelrotationmlinesLine2Dr   Z_zorderitems	tick1line	tick2linegridlineGRIDLINE_INTERPOLATION_STEPSget_pathZ_interpolation_stepsmtextTextnpnan_labelrotationlabel1label2_apply_tickdir_set_artist_propsupdate_position)selfr?   locr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   kwr   Zmajor_minorgrid_kwartist	__class__r   r	   r:   9   s    
















zTick.__init__z3.1zTick.label1)alternativependingc                 C   s   | j S N)rT   rY   r   r   r	   label   s    z
Tick.labelc                 C   sT   t |tr|}d}n t |ttfr,|\}}nd}|}tjddg|d ||f| _d S )Nr   defaultauto)r   )
isinstancestrtupler   r   check_in_listrS   )rY   r   modeZangler   r   r	   rF      s    

zTick._set_labelrotationc                 C   sF   |du rt j| j d }tjg d|d || _| j|   | _dS )z;Set tick direction.  Valid values are 'out', 'in', 'inout'.Nz
.direction)inoutinout)r   )	r;   r<   rB   r   rj   _tickdirrE   get_tick_padding_padrY   r   r   r   r	   rV      s
    zTick._apply_tickdir3.5zaxis.set_tick_paramsr`   c                 C   s   |  | d| _d S NT)rV   stalerr   r   r   r	   apply_tickdir   s    
zTick.apply_tickdirc                 C   s   | j S rb   ro   rc   r   r   r	   get_tickdir   s    zTick.get_tickdirc                 C   s   dddd}| j || j  S )z/Get the length of the tick outside of the axes.              ?      ?)rl   rn   rm   )rC   ro   )rY   paddingr   r   r	   rp      s
    zTick.get_tick_paddingc                 C   s   | j | j| j| j| jg}|S rb   )rJ   rK   rL   rT   rU   )rY   childrenr   r   r	   get_children   s    zTick.get_childrenc                    s&   t  || | j|| d| _d S ru   )r9   set_clip_pathrL   rv   )rY   clippath	transformr^   r   r	   r      s    zTick.set_clip_pathc                 C   s   | j j| j d S )NH   )r>   dpirE   rc   r   r   r	   get_pad_pixels   s    zTick.get_pad_pixelsc                 C   s&   |  |\}}|dur||fS di fS )z
        Test whether the mouse event occurred in the Tick marks.

        This function always returns false.  It is more useful to test if the
        axis as a whole contains the mouse rather than the set of tick marks.
        NF)_default_contains)rY   
mouseeventinsideinfor   r   r	   contains   s    zTick.containsc                 C   s   | j |d d| _dS )zm
        Set the tick label pad in points

        Parameters
        ----------
        val : float
        )r   TN)_apply_paramsrv   rY   valr   r   r	   set_pad  s    zTick.set_padc                 C   s   | j S )z.Get the value of the tick label pad in points.)rE   rc   r   r   r	   get_pad  s    zTick.get_padc                 C   s   dS )z Get the default Text 1 instance.Nr   rc   r   r   r	   
_get_text1  s    zTick._get_text1c                 C   s   dS )z Get the default Text 2 instance.Nr   rc   r   r   r	   
_get_text2  s    zTick._get_text2c                 C   s   dS )z*Get the default line2D instance for tick1.Nr   rc   r   r   r	   _get_tick1line  s    zTick._get_tick1linec                 C   s   dS )z*Get the default line2D instance for tick2.Nr   rc   r   r   r	   _get_tick2line  s    zTick._get_tick2linec                 C   s   dS )z3Get the default grid Line2d instance for this tick.Nr   rc   r   r   r	   _get_gridline  s    zTick._get_gridlinec                 C   s   | j S )z3Return the tick location (data coords) as a scalar.)r@   rc   r   r   r	   get_loc  s    zTick.get_locc                 C   sd   |   sd| _d S |j| j|  d | j| j| j| j| j	fD ]}|
| q>|| j d| _d S )NFgid)get_visiblerv   
open_grouprB   get_gidrL   rJ   rK   rT   rU   drawclose_group)rY   rendererr]   r   r   r	   r   #  s    z	Tick.drawc                 C   s   | j | d| _dS )z]
        Set the label1 text.

        Parameters
        ----------
        s : str
        TN)rT   set_textrv   rY   sr   r   r	   
set_label1/  s    zTick.set_label1c                 C   s   | j | d| _dS )z]
        Set the label2 text.

        Parameters
        ----------
        s : str
        TN)rU   r   rv   r   r   r   r	   
set_label2<  s    zTick.set_label2c                    s.   t  | | j| | j| d| _dS )zl
        Set the url of label1 and label2.

        Parameters
        ----------
        url : str
        TN)r9   set_urlrT   rU   rv   )rY   urlr^   r   r	   r   G  s    zTick.set_urlc                 C   s   | | j d S rb   r=   r>   rY   ar   r   r	   rW   T  s    zTick._set_artist_propsc                 C   s   t ddS )zX
        Return the view limits ``(min, max)`` of the axis the tick belongs to.
        Derived must overrideNNotImplementedErrorrc   r   r   r	   get_view_intervalW  s    zTick.get_view_intervalc                    s  d| j fd| jfd| jfd| jfd| jffD ] \}}| v r,| | q,t fdddD r d	| j| _ d
| j	| _	 d| j
| _
|  d| j | j| jfD ]}|| j || j	 q|  d }| j| |  d }| j| dd   D }d v r, d |d< | jjf i | | jjf i | | D ]\}}t| d| | qXd v r|  d | jj| jd d | jj| jd d dd   D }	| jjf i |	 | jjf i |	 dd   D }
| j jf i |
 d S )Nr   r   r   r   r   c                 3   s   | ]}| v V  qd S rb   r   )r   r,   r[   r   r	   	<genexpr>e  r   z%Tick._apply_params.<locals>.<genexpr>)r   r   r   r   r   r   r   r   r   c                 S   s   i | ]\}}|d v r||qS ))r   r   r   r+   r   r   r	   r.   v  r   z&Tick._apply_params.<locals>.<dictcomp>r   r2   _r   r6   )r8   c                 S   s&   i | ]\}}|d v r|dd |qS ))r   r   r*   Nr   r+   r   r   r	   r.     s   c                 S   s&   i | ]\}}|t v r|d d |qS r)   )_gridline_param_namesr+   r   r   r	   r.     s   )rL   rJ   rK   rT   rU   set_visiblepopanyrC   rD   rE   rV   ro   Zset_markersizeZset_markeredgewidth_get_text1_transformset_transform_get_text2_transformrI   setsetattrrF   rS   )rY   r[   r   targetlinetranstick_kwr,   r-   Zlabel_kwr\   r   r   r	   r   ]  sH    

zTick._apply_paramsc                 C   s   t ddS ):Set the location of tick in data coords with scalar *loc*.r   Nr   rY   rZ   r   r   r	   rX     s    zTick.update_positionc                 C   s   t dd S Nr   r   rc   r   r   r	   r     s    zTick._get_text1_transformc                 C   s   t dd S r   r   rc   r   r   r	   r     s    zTick._get_text2_transform)N)(rB   
__module____qualname____doc__r:   propertyr   
deprecatedrd   rF   rV   rw   ry   rp   r   r   r   r   r   r   r   r   r   r   r   r   martistallow_rasterizationr   r   Z	set_labelr   r   rW   r   r   rX   r   r   __classcell__r   r   r^   r	   r   #   sn    
	
/r   c                       sP   e Zd ZdZdZ  fddZdd Zdd Z fd	d
Zdd Zdd Z	  Z
S )XTickzq
    Contains all the Artists needed to make an x tick - the tick line,
    the label text and the grid line
    Zxtickc                    s   t  j|i | | j}| jjdgdgf|dd | jjdgdgf|dd | jjddgddgf|dd |  \}}}| j	jdd|||d | 
 \}}}| jjdd|||d d S Nr   Ztick1)datar   r6   Ztick2gridxyverticalalignmenthorizontalalignmentr   )r9   r:   r?   rJ   r   Zget_xaxis_transformrK   rL   r   rT   r   rU   rY   argskwargsaxr   vaZhar^   r   r	   r:     s*    zXTick.__init__c                 C   s   | j | jS rb   )r?   Zget_xaxis_text1_transformrq   rc   r   r   r	   r     s    zXTick._get_text1_transformc                 C   s   | j | jS rb   )r?   Zget_xaxis_text2_transformrq   rc   r   r   r	   r     s    zXTick._get_text2_transformc                    sN   t  | tjtjftjtjfdd| j \}}| j| | j| d S )N)|r   rm   rl   rn   )	r9   rV   rG   ZTICKDOWNZTICKUPro   rJ   
set_markerrK   rY   r   Zmark1Zmark2r^   r   r	   rV     s    

zXTick._apply_tickdirc                 C   sR   | j |f | j|f | j|f | j| | j| || _d| _dS r   TN)	rJ   Z	set_xdatarK   rL   rT   Zset_xrU   r@   rv   r   r   r   r	   rX     s    zXTick.update_positionc                 C   s
   | j jjS rb   )r?   viewLim	intervalxrc   r   r   r	   r     s    zXTick.get_view_intervalrB   r   r   r   r:   r   r   rV   rX   r   r   r   r   r^   r	   r     s   
r   c                       sP   e Zd ZdZdZ  fddZdd Zdd Z fd	d
Zdd Zdd Z	  Z
S )YTickzp
    Contains all the Artists needed to make a Y tick - the tick line,
    the label text and the grid line
    Zytickc                    s   t  j|i | | j}| jjdgdgf|dd | jjdgdgf|dd | jjddgddgf|dd |  \}}}| j	jdd|||d | 
 \}}}| jjdd|||d d S r   )r9   r:   r?   rJ   r   Zget_yaxis_transformrK   rL   r   rT   r   rU   r   r^   r   r	   r:     s*    zYTick.__init__c                 C   s   | j | jS rb   )r?   Zget_yaxis_text1_transformrq   rc   r   r   r	   r     s    zYTick._get_text1_transformc                 C   s   | j | jS rb   )r?   Zget_yaxis_text2_transformrq   rc   r   r   r	   r     s    zYTick._get_text2_transformc                    sN   t  | tjtjftjtjfdd| j \}}| j| | j| d S )N)r   r   r   )	r9   rV   rG   ZTICKLEFTZ	TICKRIGHTro   rJ   r   rK   r   r^   r   r	   rV     s    

zYTick._apply_tickdirc                 C   sR   | j |f | j|f | j|f | j| | j| || _d| _dS r   )	rJ   Z	set_ydatarK   rL   rT   Zset_yrU   r@   rv   r   r   r   r	   rX     s    zYTick.update_positionc                 C   s
   | j jjS rb   )r?   r   	intervalyrc   r   r   r	   r     s    zYTick.get_view_intervalr   r   r   r^   r	   r     s   
r   c                   @   sL   e Zd ZdZdd Zedd Zejdd Zedd Zejd	d Zd
S )Tickera2  
    A container for the objects defining tick position and format.

    Attributes
    ----------
    locator : `matplotlib.ticker.Locator` subclass
        Determines the positions of the ticks.
    formatter : `matplotlib.ticker.Formatter` subclass
        Determines the format of the tick labels.
    c                 C   s   d | _ d | _d| _d| _d S ru   )_locator
_formatter_locator_is_default_formatter_is_defaultrc   r   r   r	   r:     s    zTicker.__init__c                 C   s   | j S rb   )r   rc   r   r   r	   locator#  s    zTicker.locatorc                 C   s   t |tjstd|| _d S )Nz7locator must be a subclass of matplotlib.ticker.Locator)rg   mtickerLocator	TypeErrorr   rY   r   r   r   r	   r   '  s    c                 C   s   | j S rb   )r   rc   r   r   r	   	formatter.  s    zTicker.formatterc                 C   s   t |tjstd|| _d S )Nz;formatter must be a subclass of matplotlib.ticker.Formatter)rg   r   	Formatterr   r   rY   r   r   r   r	   r   2  s    N)	rB   r   r   r   r:   r   r   setterr   r   r   r   r	   r     s   


r   c                   @   s    e Zd ZdZdd Zdd ZdS )_LazyTickListz
    A descriptor for lazy instantiation of tick lists.

    See comment above definition of the ``majorTicks`` and ``minorTicks``
    attributes.
    c                 C   s
   || _ d S rb   )rA   rY   r   r   r   r	   r:   B  s    z_LazyTickList.__init__c                 C   s^   |d u r| S | j r6g |_|jdd}|j| |jS g |_|jdd}|j| |jS d S )NTr   F)rA   
majorTicks	_get_tickappend
minorTicks)rY   instanceclstickr   r   r	   __get__E  s    z_LazyTickList.__get__N)rB   r   r   r   r:   r   r   r   r   r	   r   :  s   r   c                       s  e Zd ZdZdZdd Zdȇ fdd	Zedd	 Zej	d
d	 Zedd Z
e
j	dd Z
edd Zej	dd Zedd Zej	dd ZeddZeddZdd Zdd ZeeeddZdddZd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zejd0d1d2d3d4 Zd5d6 Zdd8d9Z e!d:d; Z"dˇ fd<d=	Z#d>d? Z$dd@dAZ%dBdC Z&ddDdEZ'dFdG Z(dHdI Z)dJdK Z*dLdM Z+dNdO Z,dPdQ Z-dRdS Z.ddTdUdVZ/dWdX Z0e1j2dYdZ Z3d[d\ Z4d]d^ Z5d_d` Z6dadb Z7dcdd Z8dedf Z9ddgdhZ:didj Z;dkdl Z<ddmdnZ=dodp Z>dqdr Z?ddsdtduZ@ddvdwZAdxdy ZBdzd{ ZCd|d} ZDd~d ZEdd ZFdd ZGdd ZHdd ZIdddZJdddZKeLddddddZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdddZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZe!dd Z[ddsddZ\dddddZ]ddsddZ^dddsddZ_dd Z`dd Zadd ZbdddZcdd Zddd ZeddÄ Zfddń ZgddǄ Zh  ZiS )Axisa  
    Base class for `.XAxis` and `.YAxis`.

    Attributes
    ----------
    isDefault_label : bool

    axes : `matplotlib.axes.Axes`
        The `~.axes.Axes` to which the Axis belongs.
    major : `matplotlib.axis.Ticker`
        Determines the major tick positions and their label format.
    minor : `matplotlib.axis.Ticker`
        Determines the minor tick positions and their label format.
    callbacks : `matplotlib.cbook.CallbackRegistry`

    label : `.Text`
        The axis label.
    labelpad : float
        The distance between the axis label and the tick labels.
        Defaults to :rc:`axes.labelpad` = 4.
    offsetText : `.Text`
        A `.Text` object containing the data offset of the ticks (if any).
    pickradius : float
        The acceptance radius for containment tests. See also `.Axis.contains`.
    majorTicks : list of `.Tick`
        The major ticks.
    minorTicks : list of `.Tick`
        The minor ticks.
       c                 C   s"   dj t| jg| jjdR  S )Nz	{}({},{})r   r   )formattyperB   r?   	transAxesr   rc   r   r   r	   __str__z  s
    zAxis.__str__   c                    s   t    d| _| |j d| _|| _t | _t | _	t
 | _d| _tjtjtjtjd tjd tjd d| _| | j ttjtj| _| | j tjd | _|| _t | _t | _|   | d dS )	a  
        Parameters
        ----------
        axes : `matplotlib.axes.Axes`
            The `~.axes.Axes` to which the created Axis belongs.
        pickradius : float
            The acceptance radius for containment tests. See also
            `.Axis.contains`.
        Tzaxes.labelsizezaxes.labelweightzaxes.labelcolor)r7   Z
fontweightr   zaxes.labelpadlinearN)r9   r:   _remove_overlapping_locsr=   r>   isDefault_labelr?   r   r   r'   cbookCallbackRegistry	callbacks_autolabelposrO   rP   rQ   rR   r;   r<   rd   rW   
offsetTextlabelpad
pickradiusdict_major_tick_kw_minor_tick_kwclear
_set_scale)rY   r?   r	  r^   r   r	   r:   ~  s0    


zAxis.__init__c                 C   s   | j jS rb   r   r   rc   r   r   r	   isDefault_majloc  s    zAxis.isDefault_majlocc                 C   s   || j _d S rb   r  rY   valuer   r   r	   r    s    c                 C   s   | j jS rb   r   r   rc   r   r   r	   isDefault_majfmt  s    zAxis.isDefault_majfmtc                 C   s   || j _d S rb   r  r  r   r   r	   r    s    c                 C   s   | j jS rb   r'   r   rc   r   r   r	   isDefault_minloc  s    zAxis.isDefault_minlocc                 C   s   || j _d S rb   r  r  r   r   r	   r    s    c                 C   s   | j jS rb   r'   r   rc   r   r   r	   isDefault_minfmt  s    zAxis.isDefault_minfmtc                 C   s   || j _d S rb   r  r  r   r   r	   r    s    Tr   Fc                 C   s   | j S rb   )r  rc   r   r   r	   get_remove_overlapping_locs  s    z Axis.get_remove_overlapping_locsc                 C   s   t || _d S rb   )boolr  r   r   r   r	   set_remove_overlapping_locs  s    z Axis.set_remove_overlapping_locszUIf minor ticker locations that overlap with major ticker locations should be trimmed.)docNc                 C   s<   d| _ |du r| jj}| j| | j||f d| _dS )a  
        Set the coordinates of the label.

        By default, the x coordinate of the y label and the y coordinate of the
        x label are determined by the tick label bounding boxes, but this can
        lead to poor alignment of multiple labels if there are multiple axes.

        You can also specify the coordinate system of the label with the
        transform.  If None, the default coordinate system will be the axes
        coordinate system: (0, 0) is bottom left, (0.5, 0.5) is center, etc.
        FNT)r  r?   r   rd   r   set_positionrv   )rY   r   r   r   r   r   r	   set_label_coords  s    zAxis.set_label_coordsc                 C   s
   | j  S rb   )_scaleget_transformrc   r   r   r	   r     s    zAxis.get_transformc                 C   s   | j jS )z#Return this Axis' scale (as a str).)r  r   rc   r   r   r	   	get_scale  s    zAxis.get_scalec                 K   sR   t |tjs$tj|| fi || _n|| _| j|  d| _d| _d| _d| _	d S ru   )
rg   mscaleZ	ScaleBaseZscale_factoryr  Z#set_default_locators_and_formattersr  r  r  r  )rY   r  r   r   r   r	   r    s    zAxis._set_scalec                 C   s   | j |||  S rb   )r  limit_range_for_scale
get_minpos)rY   vminvmaxr   r   r	   r#    s    zAxis.limit_range_for_scalec                 C   s   | j | jg|  |  S rb   )rd   r  get_major_ticksget_minor_ticksrc   r   r   r	   r     s
    
zAxis.get_childrenc                 C   s,   | j   tjd o tjd dv | j d< d S )Nr%   r"   r#   r   )r  r  r;   r<   rc   r   r   r	   _reset_major_tick_kw
  s    

zAxis._reset_major_tick_kwc                 C   s,   | j   tjd o tjd dv | j d< d S )Nr%   r"   r&   r   )r  r  r;   r<   rc   r   r   r	   _reset_minor_tick_kw  s    

zAxis._reset_minor_tick_kwc                 C   s   | j d | d t | _tjd o6tjd dv | jd< tjd oTtjd dv | j	d< | 
  d| _d| _| d d	| _dS )
z
        Clear the axis.

        This resets axis properties to their default values:

        - the label
        - the scale
        - locators, formatters and ticks
        - major and minor grid
        - units
        - registered callbacks
        r3   r   r%   r"   r#   r   r&   NT)rd   r   r  r  r  r  r;   r<   r  r  reset_ticks	converterunits	set_unitsrv   rc   r   r   r	   r    s    




z
Axis.clearz3.4zAxis.clear()rt   c                 C   s   |   S )zClear this axis.)r  rc   r   r   r	   cla9  s    zAxis.clac                 C   sb   z| ` W n ty   Y n0 z| `W n ty6   Y n0 z| | jj W n ty\   Y n0 dS )zs
        Re-initialize the major and minor Tick lists.

        Each list starts with a single fresh Tick.
        N)r   AttributeErrorr   r   r?   patchrc   r   r   r	   r+  >  s    zAxis.reset_ticksr   c                 K   s  t jg d|d | |}|rb|dv r<|   | j| |dv rX|   | j| |   n|dv r| j| | j	D ]}|j
f i | q||dv r| j| | jD ]}|j
f i | qd|v sd|v r| j| jddp| jdd d|v r| j|d  d	| _d
S )z
        Set appearance parameters for ticks, ticklabels, and gridlines.

        For documentation of keyword arguments, see
        :meth:`matplotlib.axes.Axes.tick_params`.
        r   r'   r$   whichr   r$   r'   r$   r   r   Fr   TN)r   rj   _translate_tick_kwr)  r  updater*  r  r+  r   r   r   r  r   getZ	set_colorrv   )rY   r4  resetr[   kwtransr   r   r   r	   set_tick_paramsR  s4    




zAxis.set_tick_paramsc                 C   s\  g dt  }i }d| v r&| d|d< d| v r<| d|d< d| v rR| d|d< d| v rh| d|d	< d
| v r~| d
|d	< d| v r| d|d< d| v r| d|d< d| v r| d|d< d| v r| d|d< d| v r| d|d< d| v r| d|d< d| v r(| d}||d< ||d< | D ] }||vr,td||f q,||  |S )N)r   r   r   r   r   r   r   r   r   r   r   r   r   length	directionleftbottomrighttop	labelleftlabelbottom
labelrightlabeltopr   r=  r   r>  r   r8   r   r?  r   r@  rA  r   rB  rC  r   rD  rE  r   rF  colorsr   r   z3keyword %s is not recognized; valid keywords are %s)r   r   
ValueErrorr8  )r[   Zkwkeysr;  ckeyr   r   r	   r7  y  sN    




zAxis._translate_tick_kwc                    s6   t  || | j| j D ]}||| qd| _d S ru   )r9   r   r   r   rv   )rY   r   r   childr^   r   r	   r     s    zAxis.set_clip_pathc                 C   s   t ddS )z3Return the ``(min, max)`` view limits of this axis.r   Nr   rc   r   r   r	   r     s    zAxis.get_view_intervalc                 C   s   t ddS )a7  
        Set the axis view limits.  This method is for internal use; Matplotlib
        users should typically use e.g. `~.Axes.set_xlim` or `~.Axes.set_ylim`.

        If *ignore* is False (the default), this method will never reduce the
        preexisting view limits, only expand them if *vmin* or *vmax* are not
        within them.  Moreover, the order of *vmin* and *vmax* does not matter;
        the orientation of the axis will not change.

        If *ignore* is True, the view limits will be set exactly to ``(vmin,
        vmax)`` in that order.
        r   Nr   rY   r%  r&  ignorer   r   r	   set_view_interval  s    zAxis.set_view_intervalc                 C   s   t ddS )z3Return the ``(min, max)`` data limits of this axis.r   Nr   rc   r   r   r	   get_data_interval  s    zAxis.get_data_intervalc                 C   s   t ddS )a  
        Set the axis data limits.  This method is for internal use.

        If *ignore* is False (the default), this method will never reduce the
        preexisting data limits, only expand them if *vmin* or *vmax* are not
        within them.  Moreover, the order of *vmin* and *vmax* does not matter;
        the orientation of the axis will not change.

        If *ignore* is True, the data limits will be set exactly to ``(vmin,
        vmax)`` in that order.
        r   Nr   rL  r   r   r	   set_data_interval  s    zAxis.set_data_intervalc                 C   s   |   \}}||k S )a.  
        Return whether this Axis is oriented in the "inverse" direction.

        The "normal" direction is increasing to the right for the x-axis and to
        the top for the y-axis; the "inverse" direction is increasing to the
        left for the x-axis and to the bottom for the y-axis.
        )r   )rY   lowhighr   r   r	   get_inverted  s    zAxis.get_invertedc                 C   s   t ddS )a+  
        Set whether this Axis is oriented in the "inverse" direction.

        The "normal" direction is increasing to the right for the x-axis and to
        the top for the y-axis; the "inverse" direction is increasing to the
        left for the x-axis and to the bottom for the y-axis.
        r   Nr   )rY   invertedr   r   r	   set_inverted  s    zAxis.set_invertedc                 C   s   dS )z{
        Set the default limits for the axis data and view interval if they
        have not been not mutated yet.
        Nr   rc   r   r   r	   set_default_intervals  s    zAxis.set_default_intervalsc                 C   s   |d u rd S | | j d S rb   r   r   r   r   r	   rW     s    zAxis._set_artist_propsc                 C   sp   |   }| ||\}}t|r.tj|}ntjdddd}t|rVtj|}ntjdddd}||fS )zX
        Get the extents of the tick labels on either side
        of the axes.
        r   )_update_ticks_get_tick_bboxeslenmtransformsBboxunionZfrom_extents)rY   r   ticks_to_drawticklabelBoxesticklabelBoxes2bboxbbox2r   r   r	   get_ticklabel_extents  s    zAxis.get_ticklabel_extentsc              	   C   sd  |   }| jj|}| t|}| jj| t|||D ](\}}}|| |	| |
| q>|  }| jj|}| t|}	| jj| t|	||D ](\}}}|| |	| |
| qg ||	}
|  \}}||kr|| }}|  ||g}g }|
D ]J}z|  | }W n tyB   Y n0 t||r|| q|S )z
        Update ticks (position and labels) using the current data interval of
        the axes.  Return the list of ticks that will be drawn.
        )get_majorticklocsr   r   Zformat_ticksr'  rY  Zset_locsziprX   r   r   get_minorticklocsr'   r(  r   r   r   r   AssertionErrorrZ  Z_interval_contains_closer   )rY   
major_locsZmajor_labelsZmajor_ticksr   rZ   rd   
minor_locsZminor_labelsZminor_ticksticksZview_lowZ	view_highZ
interval_tr]  Zloc_tr   r   r	   rW    s<    




zAxis._update_ticksc                    s$    fdd|D  fdd|D fS )z8Return lists of bboxes for ticks' label1's and label2's.c                    s"   g | ]}|j  r|j  qS r   )rT   r   get_window_extentr   r   r   r   r	   r
   =  s   z)Axis._get_tick_bboxes.<locals>.<listcomp>c                    s"   g | ]}|j  r|j  qS r   )rU   r   rj  rk  rl  r   r	   r
   ?  s   r   )rY   ri  r   r   rl  r	   rX  ;  s    

zAxis._get_tick_bboxes)for_layout_onlyc                   s*  |   sdS |  }|   | | \}}| || | j| jj	  g  fdd| jfD ||}| j
  r| j
 }|r| jdkr|jdkr|j|j d d |_|jd |_| jd	kr|jdkr|j|j d d |_|jd |_|| d
d |D }|r"tj|S dS dS )a  
        Return a bounding box that encloses the axis. It only accounts
        tick labels, axis label, and offsetText.

        If *for_layout_only* is True, then the width of the label (if this
        is an x-axis) or the height of the label (if this is a y-axis) is
        collapsed to near zero.  This allows tight/constrained_layout to ignore
        too-long labels when doing their layout.
        Nc                 3   s    | ]}|  r| V  qd S rb   )r   rj  )r   r   rl  r   r	   r   [  s   z%Axis.get_tightbbox.<locals>.<genexpr>r   r      r{   r|   r   c                 S   sH   g | ]@}d |j   k r tjk rn qd |j  k r<tjk rn q|qS r   )r   rQ   infheight)r   br   r   r	   r
   o  s   8z&Axis.get_tightbbox.<locals>.<listcomp>)r   rW  _update_label_positionrX  _update_offset_text_positionr  r   r   r   
get_offsetrd   rj  	axis_namer   x0x1rp  y0y1r   rZ  r[  r\  )rY   r   rm  r]  r^  r_  bboxesZbbr   rl  r	   get_tightbboxB  s@    



zAxis.get_tightbboxc                 C   sL   g }t | jr"|| jd   t | jr@|| jd   t|ddS )Nr   )re   )rY  r   r   rp   r   max)rY   valuesr   r   r	   rp   v  s    

zAxis.get_tick_paddingc                 O   s   |   sd S |jt|  d |  }| ||\}}|D ]}|| q:| | | j| | 	|| | j
| jj  | j
| |t d| _d S )Nr   F)r   r   rB   r   rW  rX  r   rr  rd   rs  r  r   r   r   rt  r   rv   )rY   r   r   r   r]  r^  r_  r   r   r   r	   r   ~  s     

z	Axis.drawc                 C   s   |   }tddd |D S )z6Return this Axis' grid lines as a list of `.Line2D`\s.zLine2D gridlinec                 S   s   g | ]
}|j qS r   )rL   rk  r   r   r	   r
     r   z&Axis.get_gridlines.<locals>.<listcomp>)r'  r  silent_list)rY   ri  r   r   r	   get_gridlines  s    zAxis.get_gridlinesc                 C   s   | j S )z)Return the axis label as a Text instance.)rd   rc   r   r   r	   	get_label  s    zAxis.get_labelc                 C   s   | j S )z.Return the axis offsetText as a Text instance.)r  rc   r   r   r	   get_offset_text  s    zAxis.get_offset_textc                 C   s   | j S )z0Return the depth of the axis used by the picker.r	  rc   r   r   r	   get_pickradius  s    zAxis.get_pickradiusc                 C   s,   |   }dd |D }dd |D }|| S )z@Return this Axis' major tick labels, as a list of `~.text.Text`.c                 S   s   g | ]}|j  r|j qS r   rT   r   rk  r   r   r	   r
     r   z,Axis.get_majorticklabels.<locals>.<listcomp>c                 S   s   g | ]}|j  r|j qS r   rU   r   rk  r   r   r	   r
     r   )r'  rY   ri  Zlabels1Zlabels2r   r   r	   get_majorticklabels  s    zAxis.get_majorticklabelsc                 C   s,   |   }dd |D }dd |D }|| S )z@Return this Axis' minor tick labels, as a list of `~.text.Text`.c                 S   s   g | ]}|j  r|j qS r   r  rk  r   r   r	   r
     r   z,Axis.get_minorticklabels.<locals>.<listcomp>c                 S   s   g | ]}|j  r|j qS r   r  rk  r   r   r	   r
     r   )r(  r  r   r   r	   get_minorticklabels  s    zAxis.get_minorticklabelsc                 C   sf   |durR|dkr|   S |dkr(|  S |dkr@|  |    S tjg d|d |r^|   S |  S )a2  
        Get this Axis' tick labels.

        Parameters
        ----------
        minor : bool
           Whether to return the minor or the major ticklabels.

        which : None, ('minor', 'major', 'both')
           Overrides *minor*.

           Selects which ticklabels to return

        Returns
        -------
        list of `~matplotlib.text.Text`

        Notes
        -----
        The tick label strings are not populated until a ``draw`` method has
        been called.

        See also: `~.pyplot.draw` and `~.FigureCanvasBase.draw`.
        Nr'   r   r$   r2  r3  )r  r  r   rj   )rY   r'   r4  r   r   r	   get_ticklabels  s    zAxis.get_ticklabelsc                 C   s:   g }|   }|D ]}||j ||j qtd|S )z<Return this Axis' major tick lines as a list of `.Line2D`\s.Line2D ticklines)r'  r   rJ   rK   r  r~  rY   linesri  r   r   r   r	   get_majorticklines  s    zAxis.get_majorticklinesc                 C   s:   g }|   }|D ]}||j ||j qtd|S )z<Return this Axis' minor tick lines as a list of `.Line2D`\s.r  )r(  r   rJ   rK   r  r~  r  r   r   r	   get_minorticklines  s    zAxis.get_minorticklinesc                 C   s   |r|   S |  S )z6Return this Axis' tick lines as a list of `.Line2D`\s.)r  r  rY   r'   r   r   r	   get_ticklines  s    zAxis.get_ticklinesc                 C   s
   | j  S )z;Return this Axis' major tick locations in data coordinates.r   r   rc   r   r   r	   rc    s    zAxis.get_majorticklocsc                    sx   | j  }| j }| j }||}||t||  \}}|| d  | jrt fddt	||D }|S )z;Return this Axis' minor tick locations in data coordinates.gh㈵>c                    s,   g | ]$\}}t j| d d  r|qS )r   )ZatolZrtol)rQ   iscloser   )r   rZ   Ztr_locZtolZtr_major_locsr   r	   r
     s   z*Axis.get_minorticklocs.<locals>.<listcomp>)
r   r   r'   r  r   r   sortedr   remove_overlapping_locsrd  )rY   rg  rh  r   Ztr_minor_locslohir   r  r	   re    s    




zAxis.get_minorticklocsr'   c                C   s   |r|   S |  S )z5Return this Axis' tick locations in data coordinates.)re  rc  r  r   r   r	   get_ticklocs  s    zAxis.get_ticklocsc                 C   s8   |rt dd |  D S t dd |  D S dS )a;  
        Get the tick directions as a numpy array

        Parameters
        ----------
        minor : bool, default: False
            True to return the minor tick directions,
            False to return the major tick directions.

        Returns
        -------
        numpy array of tick directions
        c                 S   s   g | ]
}|j qS r   rx   rk  r   r   r	   r
   %  r   z,Axis.get_ticks_direction.<locals>.<listcomp>c                 S   s   g | ]
}|j qS r   rx   rk  r   r   r	   r
   (  r   N)rQ   arrayr(  r'  r  r   r   r	   get_ticks_direction  s    zAxis.get_ticks_directionc                 C   s   t ddS )z!Return the default tick instance.zderived must overrideNr   r   r   r   r	   r   *  s    zAxis._get_tickc                 C   s.   | j }|dtj| d }tj|d S )z
        Return the text size of tick labels for this Axis.

        This is a convenience function to avoid having to create a `Tick` in
        `.get_tick_space`, since it is expensive.
        r   ztick.labelsize)r   )r  r9  r;   r<   rO   ZFontPropertiesZget_size_in_points)rY   ru  r   r   r   r   r	   _get_tick_label_size.  s
    zAxis._get_tick_label_sizec                 C   s^   |du s|du rdS |j |j  |j|j |j|j |j|j |j|j dS )z3Copy the properties from *src* tick to *dest* tick.N)rT   Zupdate_fromrU   rJ   rK   rL   )rY   srcdestr   r   r	   _copy_tick_props:  s    zAxis._copy_tick_propsc                 C   s
   | j  S )zGet the text of the label.)rd   get_textrc   r   r   r	   get_label_textD  s    zAxis.get_label_textc                 C   s   | j jS )z$Get the locator of the major ticker.r  rc   r   r   r	   get_major_locatorH  s    zAxis.get_major_locatorc                 C   s   | j jS )z$Get the locator of the minor ticker.)r'   r   rc   r   r   r	   get_minor_locatorL  s    zAxis.get_minor_locatorc                 C   s   | j jS )z&Get the formatter of the major ticker.)r   r   rc   r   r   r	   get_major_formatterP  s    zAxis.get_major_formatterc                 C   s   | j jS )z&Get the formatter of the minor ticker.)r'   r   rc   r   r   r	   get_minor_formatterT  s    zAxis.get_minor_formatterc                 C   s\   |du rt |  }t | j|k rN| jdd}| j| | | jd | q| jd| S )z#Return the list of major `.Tick`\s.NTr   r   )rY  rc  r   r   r   r  rY   Znumticksr   r   r   r	   r'  X  s    zAxis.get_major_ticksc                 C   s\   |du rt |  }t | j|k rN| jdd}| j| | | jd | q| jd| S )z#Return the list of minor `.Tick`\s.NFr   r   )rY  re  r   r   r   r  r  r   r   r	   r(  e  s    zAxis.get_minor_ticksrs   rq  r1   c                 K   s   |r$|du rd}n|s$t d d}| }t jg d|d dd | D }|dv r|du rl| jd	  n||d	< | jf d
di| |dv r|du r| jd	  n||d	< | jf d
di| d| _dS )a  
        Configure the grid lines.

        Parameters
        ----------
        visible : bool or None
            Whether to show the grid lines.  If any *kwargs* are supplied, it
            is assumed you want the grid on and *visible* will be set to True.

            If *visible* is *None* and there are no *kwargs*, this toggles the
            visibility of the lines.

        which : {'major', 'minor', 'both'}
            The grid lines to apply the changes on.

        **kwargs : `.Line2D` properties
            Define the line properties of the grid, e.g.::

                grid(color='r', linestyle='-', linewidth=2)
        NTz_First parameter to grid() is false, but line properties are supplied. The grid will be enabled.r2  r3  c                 S   s   i | ]}d |d  |d qS )r   r   r6   r   )r   itemr   r   r	   r.     r   zAxis.grid.<locals>.<dictcomp>r6  r   r4  r'   r5  r   )	r   warn_externallowerrj   rI   r  r<  r  rv   )rY   r1   r4  r   Zgridkwr   r   r	   r   r  s,    
z	Axis.gridc                 C   sj   t j|}|du rdS | j|k}|| _| j|| }|durT| jdu rT| | n|r`|   d| _dS )z
        Introspect *data* for units converter and update the
        axis.converter instance if necessary. Return *True*
        if *data* is registered for unit conversion.
        NFT)	munitsregistryget_converterr,  Zdefault_unitsr-  r.  _update_axisinforv   )rY   r   r,  Zneednewre   r   r   r	   update_units  s    
zAxis.update_unitsc                 C   s  | j du rdS | j | j| }|du r*dS |jdurZ| jj|jkrZ| jrZ| |j d| _|jdur| j	j|jkr| j
r| |j d| _
|jdur| jj|jkr| jr| |j d| _|jdur| j	j|jkr| jr| |j d| _|jdur| jr| |j d| _|   dS )zt
        Check the axis converter for the stored units to see if the
        axis info needs to be updated.
        NT)r,  axisinfor-  Zmajlocr   r   r  set_major_locatorZminlocr'   r  set_minor_locatorZmajfmtr   r  set_major_formatterZminfmtr  set_minor_formatterrd   r  set_label_textrV  )rY   r   r   r   r	   r    sJ    




zAxis._update_axisinfoc                 C   s   | j d up| jd uS rb   )r,  r-  rc   r   r   r	   
have_units  s    zAxis.have_unitsc              
   C   s   t |r|S | jd u r&t j|| _| jd u r4|S z| j|| j| }W n6 ty } zt d||W Y d }~n
d }~0 0 |S )Nz*Failed to convert value(s) to axis units: )	r  Z_is_natively_supportedr,  r  r  convertr-  	ExceptionZConversionError)rY   r   reter   r   r	   convert_units  s    


zAxis.convert_unitsc                    s   || j krdS | j  D ]6\ }| |u r fdd| jj  | jD } qZq| g}|D ]0}||_ |  |jd |jd d|_	q^dS )z
        Set the units for axis.

        Parameters
        ----------
        u : units tag

        Notes
        -----
        The units of any shared axis will also be updated.
        Nc                    s   g | ]}t |  d qS axisgetattrr   r   r   r   r	   r
     s   z"Axis.set_units.<locals>.<listcomp>r-  zunits finalizeT)
r-  r?   _get_axis_maprI   _shared_axesget_siblingsr  r  processrv   )rY   ur  sharedr   r  r	   r.    s    

zAxis.set_unitsc                 C   s   | j S )zReturn the units for axis.)r-  rc   r   r   r	   	get_units  s    zAxis.get_unitsc                 K   s>   d| _ | j| |dur&| j| | j| d| _| jS )z
        Set the text value of the axis label.

        Parameters
        ----------
        label : str
            Text string.
        fontdict : dict
            Text properties.
        **kwargs
            Merged into fontdict.
        FNT)r  rd   r   r8  rv   )rY   rd   fontdictr   r   r   r	   r  
  s    zAxis.set_label_textc                 C   s   |  || j dS )a  
        Set the formatter of the major ticker.

        In addition to a `~matplotlib.ticker.Formatter` instance,
        this also accepts a ``str`` or function.

        For a ``str`` a `~matplotlib.ticker.StrMethodFormatter` is used.
        The field used for the value must be labeled ``'x'`` and the field used
        for the position must be labeled ``'pos'``.
        See the  `~matplotlib.ticker.StrMethodFormatter` documentation for
        more information.

        For a function, a `~matplotlib.ticker.FuncFormatter` is used.
        The function must take two inputs (a tick value ``x`` and a
        position ``pos``), and return a string containing the corresponding
        tick label.
        See the  `~matplotlib.ticker.FuncFormatter` documentation for
        more information.

        Parameters
        ----------
        formatter : `~matplotlib.ticker.Formatter`, ``str``, or function
        N)_set_formatterr   r   r   r   r	   r    s    zAxis.set_major_formatterc                 C   s   |  || j dS )aZ  
        Set the formatter of the minor ticker.

        In addition to a `~matplotlib.ticker.Formatter` instance,
        this also accepts a ``str`` or function.
        See `.Axis.set_major_formatter` for more information.

        Parameters
        ----------
        formatter : `~matplotlib.ticker.Formatter`, ``str``, or function
        N)r  r'   r   r   r   r	   r  9  s    zAxis.set_minor_formatterc                 C   s   t |trt|}n0t|r6t |tjs6t|}ntjtj	|d t |tj
rxt|jdkrxt |jtjsxtd || jkrd| _nd| _||_||  d| _d S )N)r   r   z=FixedFormatter should only be used together with FixedLocatorFT)rg   rh   r   ZStrMethodFormattercallableZ
TickHelperFuncFormatterr   check_isinstancer   FixedFormatterrY  seqr   FixedLocatorr  r   r  r  r   set_axisrv   )rY   r   levelr   r   r	   r  G  s&    




zAxis._set_formatterc                 C   sH   t jtj|d d| _|| j_| jjr4| jj| |	|  d| _
dS )z
        Set the locator of the major ticker.

        Parameters
        ----------
        locator : `~matplotlib.ticker.Locator`
        r   FTN)r   r  r   r   r  r   r   r   _set_locatorr  rv   r   r   r   r	   r  a  s    
zAxis.set_major_locatorc                 C   sH   t jtj|d d| _|| j_| jjr4| jj| |	|  d| _
dS )z
        Set the locator of the minor ticker.

        Parameters
        ----------
        locator : `~matplotlib.ticker.Locator`
        r  FTN)r   r  r   r   r  r'   r   r   r  r  rv   r   r   r   r	   r  q  s    
zAxis.set_minor_locatorc                 C   s
   || _ dS )z
        Set the depth of the axis used by the picker.

        Parameters
        ----------
        pickradius :  float
        Nr  )rY   r	  r   r   r	   set_pickradius  s    zAxis.set_pickradiusc                 C   s   |  |dS )Nr3   )r9  )tickdr   posr   r   r	   _format_with_dict  s    zAxis._format_with_dictc                K   s  dd |D }|r|   n|  }t|tjrt|jt|krlt|dkrltdt|j dt| ddd t|j|D }t	
| j|}t|}n
t|}|r| | |  }| t|}	n | | |  }| t|}	g }
tt||	D ]~\}\}}|| |||}|j| |j| |j| |j| |j rf|
|j |j r|
|j qd	| _|
S )
a  
        Set the text values of the tick labels.

        .. admonition:: Discouraged

            The use of this method is discouraged, because of the dependency
            on tick positions. In most cases, you'll want to use
            ``set_[x/y]ticks(positions, labels)`` instead.

            If you are using this method, you should always fix the tick
            positions before, e.g. by using `.Axis.set_ticks` or by explicitly
            setting a `~.ticker.FixedLocator`. Otherwise, ticks are free to
            move and the labels may end up in unexpected positions.

        Parameters
        ----------
        ticklabels : sequence of str or of `.Text`\s
            Texts for labeling each tick location in the sequence set by
            `.Axis.set_ticks`; the number of labels must match the number of
            locations.
        minor : bool
            If True, set minor ticks instead of major ticks.
        **kwargs
            Text properties.

        Returns
        -------
        list of `.Text`\s
            For each tick, includes ``tick.label1`` if it is visible, then
            ``tick.label2`` if it is visible, in that order.
        c                 S   s"   g | ]}t |d r| n|qS )r  )hasattrr  )r   tr   r   r	   r
     s   z'Axis.set_ticklabels.<locals>.<listcomp>r   z&The number of FixedLocator locations (zN), usually from a call to set_ticks, does not match the number of ticklabels (z).c                 S   s   i | ]\}}||qS r   r   )r   rZ   Zlabr   r   r	   r.     r   z'Axis.set_ticklabels.<locals>.<dictcomp>T)r  r  rg   r   r  rY  locsrH  rd  	functoolspartialr  r  r  r  re  r(  r  rc  r'  	enumeraterX   rT   r   r8  rU   r   r   rv   )rY   Z
ticklabelsr'   r   r   r  funcr   r  ri  r  r  rZ   r   Z
tick_labelr   r   r	   set_ticklabels  sP     





zAxis.set_ticklabels)r  r'   c                K   s(   |dur| | | j|fd|i|S )a  
        Set this Axis' labels with list of string labels.

        .. warning::
            This method should only be used after fixing the tick positions
            using `.Axis.set_ticks`. Otherwise, the labels may end up in
            unexpected positions.

        Parameters
        ----------
        labels : list of str
            The label texts.

        fontdict : dict, optional
            A dictionary controlling the appearance of the ticklabels.
            The default *fontdict* is::

               {'fontsize': rcParams['axes.titlesize'],
                'fontweight': rcParams['axes.titleweight'],
                'verticalalignment': 'baseline',
                'horizontalalignment': loc}

        minor : bool, default: False
            Whether to set the minor ticklabels rather than the major ones.

        Returns
        -------
        list of `.Text`
            The labels.

        Other Parameters
        ----------------
        **kwargs : `~.text.Text` properties.
        Nr'   )r8  r  )rY   labelsr  r'   r   r   r   r	   _set_ticklabels  s    #
zAxis._set_ticklabelsc                   s   |  |}| j  D ]6\ }| |u r fdd| jj  | jD } qVq| g}|D ]N}t|dkrZ| \}}||kr|t	|t
| qZ|t
|t	| qZd| j_|r| t| | t|S | t| | t|S d S )Nc                    s   g | ]}t |  d qS r  r  r  r  r   r	   r
     s   z,Axis._set_tick_locations.<locals>.<listcomp>r6   T)r  r?   r  rI   r  r  rY  r   rN  minr|  rv   r  r   r  r(  r  r'  )rY   ri  r'   r  r  ZxleftZxrightr   r  r	   _set_tick_locations  s(    

zAxis._set_tick_locationsc                K   s0   | j ||d}|dur,| j|fd|i| |S )a  
        Set this Axis' tick locations and optionally labels.

        If necessary, the view limits of the Axis are expanded so that all
        given ticks are visible.

        Parameters
        ----------
        ticks : list of floats
            List of tick locations.
        labels : list of str, optional
            List of tick labels. If not set, the labels show the data value.
        minor : bool, default: False
            If ``False``, set the major ticks; if ``True``, the minor ticks.
        **kwargs
            `.Text` properties for the labels. These take effect only if you
            pass *labels*. In other cases, please use `~.Axes.tick_params`.

        Notes
        -----
        The mandatory expansion of the view limits is an intentional design
        choice to prevent the surprise of a non-visible tick. If you need
        other limits, you should set the limits explicitly after setting the
        ticks.
        r  Nr'   )r  r  )rY   ri  r  r'   r   resultr   r   r	   	set_ticks%  s    zAxis.set_ticksc                    s    fdd j   D }t|dkr0g g fS |\} jj| }g }g }| j D ]@}t|| d}| }	|	|	|\}
}|
|
 |
| qV||fS )z
        Get the bounding boxes for this `.axis` and its siblings
        as set by `.Figure.align_xlabels` or  `.Figure.align_ylabels`.

        By default it just gets bboxes for self.
        c                    s(   g | ] \}}| j jv r| u r|qS r   )r>   _align_label_groups)r   r   r  rc   r   r	   r
   L  s   z1Axis._get_tick_boxes_siblings.<locals>.<listcomp>r6   r  )r?   r  rI   rY  r>   r  r  r  rW  rX  extend)rY   r   Z
axis_namesru  Zgrouperrz  bboxes2r   r  r]  ZtlbZtlb2r   rc   r	   _get_tick_boxes_siblingsD  s     

zAxis._get_tick_boxes_siblingsc                 C   s   t ddS )zz
        Update the label position based on the bounding box enclosing
        all the ticklabels and axis spine.
        r   Nr   )rY   r   r   r   r	   rr  ^  s    zAxis._update_label_positionc                 C   s   t ddS )zx
        Update the offset text position based on the sequence of bounding
        boxes of all the ticklabels.
        r   Nr   )rY   rz  r  r   r   r	   rs  e  s    z!Axis._update_offset_text_positionc                 C   s@   t |trddl}|j|}| tddddddd| dS )z
        Set up axis ticks and labels to treat data along this Axis as dates.

        Parameters
        ----------
        tz : str or `datetime.tzinfo`, default: :rc:`timezone`
            The timezone used to create date labels.
        r   Ni  r6   )rg   rh   Zdateutil.tztzZgettzr  datetime)rY   r  Zdateutilr   r   r	   	axis_datel  s    
zAxis.axis_datec                 C   s
   t  dS )z>Return the estimated number of ticks that can fit on the axis.Nr   rc   r   r   r	   get_tick_space}  s    zAxis.get_tick_spacec                 C   sj   | j d }| jd }tdd ||fD r.dS tdd ||fD rHdS tdd ||fD rbdS d	S d
S )a[  
        Helper for `XAxis.get_ticks_position` and `YAxis.get_ticks_position`.

        Check the visibility of tick1line, label1, tick2line, and label2 on
        the first major and the first minor ticks, and return

        - 1 if only tick1line and label1 are visible (which corresponds to
          "bottom" for the x-axis and "left" for the y-axis);
        - 2 if only tick2line and label2 are visible (which corresponds to
          "top" for the x-axis and "right" for the y-axis);
        - "default" if only tick1line, tick2line and label1 are visible;
        - "unknown" otherwise.
        r   c                 s   s:   | ]2}|j  o0|j  o0|j o0|j  V  qd S rb   rJ   r   rK   rT   rU   rk  r   r   r	   r     s   

z+Axis._get_ticks_position.<locals>.<genexpr>r6   c                 s   s:   | ]2}|j  o0|j  o0|j o0|j  V  qd S rb   )rK   r   rJ   rU   rT   rk  r   r   r	   r     s   

rn  c                 s   s8   | ]0}|j  o.|j o.|j o.|j  V  qd S rb   r  rk  r   r   r	   r     s   
re   unknownN)r   r   all)rY   r   r'   r   r   r	   _get_ticks_position  s    

zAxis._get_ticks_positionc                 C   s   | j S )z;
        Return the label position (top or bottom)
        )label_positionrc   r   r   r	   get_label_position  s    zAxis.get_label_positionc                 C   s
   t  dS )
        Set the label position (top or bottom)

        Parameters
        ----------
        position : {'top', 'bottom'}
        Nr   rY   positionr   r   r	   set_label_position  s    zAxis.set_label_positionc                 C   s
   t  d S rb   r   rc   r   r   r	   r$    s    zAxis.get_minpos)r   )N)r   F)N)F)F)FN)F)F)N)N)Nr   )N)N)N)jrB   r   r   r   OFFSETTEXTPADr   r:   r   r  r   r  r  r  r   r   r   r  r  r  r  r   r!  r  r#  r   r)  r*  r  r   r   r/  r+  r<  staticmethodr7  r   r   rN  rO  rP  rS  rU  rV  rW   rb  rW  rX  r{  rp   r   r   r   r  r  r  r  r  r  r  r  r  r  rc  re  r  r  r   r  r  r  r  r  r  r  r'  r(  Zrename_parameterr   r  r  r  r  r.  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rr  rs  r  r  r  r  r  r$  r   r   r   r^   r	   r   Z  s   -










#

'
,

+4

&		




*"

Q'
%
r   c                    sF    fddd	 fdd	d|  d_ d|  d_ fS )
zo
    Helper to generate ``get_{data,view}_interval`` and
    ``set_{data,view}_interval`` implementations.
    c                    s   t t | j S rb   )r  r?   rc   )	attr_namelim_namer   r	   getter  s    z%_make_getset_interval.<locals>.getterFc                    s~   |rt t| j ||f nV| \}}||k rT| t|||t|||dd n | t|||t|||dd d| _d S )NT)rM  )r   r  r?   r  r|  rv   )rY   r%  r&  rM  ZoldminZoldmaxr  r  r  r   r   r	   r     s    z%_make_getset_interval.<locals>.setterget_Z	_intervalset_)F)rB   )method_namer  r  r   r  r	   _make_getset_interval  s
    r  c                       s   e Zd ZdZ dZ fddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zeddd\ZZeddd\ZZdd Zd d! Zd"d# Zd$d% Z  ZS )&XAxisZxaxisr   c              
      s~   t  j|i | | jjddddt| jjt d d| _	| j
jddddt| jjt tjd	 tjd
 d d| _d S )Nr{   r   rB  centerr   r@  r6   rA  zxtick.labelsizezxtick.colorr   r   r   r   r   r7   r   )r9   r:   rd   r   rZ  blended_transform_factoryr?   r   IdentityTransformr  r  r;   r<   offset_text_positionrY   r   r   r^   r   r	   r:     s&    zXAxis.__init__c                 C   s   |  |\}}|dur||fS |j|j }}z"| jj }|||f\}}W n tyh   di f Y S 0 | jjddg\\}	}
\}}d|  kodkn  o|
| j |  k o|
k n  p||  k o|| j k n  }|i fS )z4Test whether the mouse event occurred in the x axis.NFr   r6   r6   r   r6   	r   r   r   r?   r   rT  r   rH  r	  rY   r   r   r   r   r   r   ZxaxesZyaxeslrq  rr  Zinaxisr   r   r	   r     s    zXAxis.containsc                 C   s*   |r| j }n| j}t| jdfd|i|S Nr   r   )r  r  r   r?   rY   r   r   r   r   r	   r     s    zXAxis._get_tickc                 C   s,   | j tjddd|d || _d| _dS )r  baselinerB  )rB  r@  r  TN)rd   set_verticalalignmentr   check_getitemr  rv   r  r   r   r	   r    s    
zXAxis.set_label_positionc                 C   s0  | j s
dS | j|d\}}| j \}}| jdkrz&| jjd }| |	 
 }W n tyr   | jj}Y n0 tj||g }|j}	| j||	| j| jj d  f n|z&| jjd }| |	 
 }W n ty   | jj}Y n0 tj||g }|j}
| j||
| j| jj d  f dS )y
        Update the label position based on the bounding box enclosing
        all the ticklabels and axis spine
        Nrl  r@  r   rB  )r  r  rd   get_positionr  r?   spinesr   transform_pathrN   get_extentsKeyErrorr`  rZ  r[  r\  rx  r  r  r>   r   ry  )rY   r   rz  r  r   r   spine	spinebboxr`  r@  rB  r   r   r	   rr    s:    
zXAxis._update_label_positionc                 C   s   | j  \}}t| dsd| _| jdkrft|s<| jjj}ntj	
|}|j}|| j| jj d  }n<t|sz| jjj}ntj	
|}|j}|| j| jj d  }| j ||f dS )w
        Update the offset_text position based on the sequence of bounding
        boxes of all the ticklabels
        _tick_positionr@  r   N)r  r  r  r  rY  r?   r`  yminrZ  r[  r\  rx  r  r>   r   ymaxry  r  )rY   rz  r  r   r   r@  r`  rB  r   r   r	   rs  D  s    

z"XAxis._update_offset_text_positionc                 C   s   |  |\}}| jd  }d}|jr4||j| 7 }d}|jrL||j| 7 }|  dkrp|| j|j| 7 }n|| j|j| 7 }||fS )zz
        Return how much space should be reserved for text above and below the
        axes, as a pair of floats.
        r   rz   rB  )rb  r   r   rp  r  rd   rj  )rY   r   r`  ra  	padPixelsZaboveZbelowr   r   r	   get_text_heights\  s    zXAxis.get_text_heightsc                 C   s   t jg d|d |dkrB| jdddddd d| _| jd n|dkrr| jdddddd d| _| jd np|dkr| jdddd	 nV|d
kr| jdddd	 n<|dkr| jdddddd d| _| jd ndsJ dd| _dS )a  
        Set the ticks position.

        Parameters
        ----------
        position : {'top', 'bottom', 'both', 'default', 'none'}
            'both' sets the ticks to appear on both positions, but does not
            change the tick labels.  'default' resets the tick positions to
            the default: ticks on both positions, labels at bottom.  'none'
            can be used if you don't want any ticks. 'none' and 'both'
            affect only the ticks, not the labels.
        )rB  r@  r$   re   r/   r  rB  r$   TF)r4  rB  rF  r@  rD  r@  )r4  rB  r@  r/   re   0unhandled parameter not caught by _check_in_listN)r   rj   r<  r  r  r  rv   r  r   r   r	   set_ticks_positionr  s>    



zXAxis.set_ticks_positionc                 C   s>   d}d| j v r"| j d p | j d }| d | jd|d dS )zP
        Move ticks and ticklabels (if present) to the top of the axes.
        Tr   r   rB  r$   )r4  rF  Nr  r#  r<  rY   rd   r   r   r	   tick_top  s    


zXAxis.tick_topc                 C   s>   d}d| j v r"| j d p | j d }| d | jd|d dS )zS
        Move ticks and ticklabels (if present) to the bottom of the axes.
        Tr   r   r@  r$   )r4  rD  Nr$  r%  r   r   r	   tick_bottom  s    


zXAxis.tick_bottomc                 C   s   ddddd|    S )zW
        Return the ticks position ("top", "bottom", "default", or "unknown").
        r@  rB  re   r  r6   rn  re   r  r  rc   r   r   r	   get_ticks_position  s
    zXAxis.get_ticks_positionviewr   r   r   dataLimc                 C   s
   | j jjS rb   )r?   r,  Zminposxrc   r   r   r	   r$    s    zXAxis.get_minposc                 C   s0   |   \}}| jjt||ft|dd d d S N)reverse)rf   )r   r?   Zset_xlimr  r  rY   rT  r   rq  r   r   r	   rU    s    zXAxis.set_invertedc                 C   sd   | j j sZ| j j sZ| jd urZ| j| j| }|jd urZ| |j\}}||f| j j_	d| _
d S ru   )r?   r,  Zmutatedxr   r,  r  r-  default_limitsr  r   rv   )rY   r   ZxminZxmaxr   r   r	   rV    s    


zXAxis.set_default_intervalsc                 C   sb   t jdddd}|| jj| jj }|jd }| 	dd }|dkrZt
t|| S dS d S )Nr   r6   r   r   r   )rZ  r[  from_boundstransformedr?   r   r>   dpi_scale_transr   r  intrQ   floorrY   Zendsr=  r   r   r   r	   r    s    

zXAxis.get_tick_space)rB   r   r   ru  r:   r   r   r  rr  rs  r!  r#  r&  r'  r*  r  r   rN  rO  rP  r$  rU  rV  r  r   r   r   r^   r	   r    s.   +(r  c                       s   e Zd ZdZ dZ fddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zeddd\ZZeddd\ZZd d! Zd"d# Zd$d% Zd&d' Z  ZS )(YAxisZyaxisr   c                    s   t  j|i | | jjddddddtt | jjd d| _	| j
jddd	dt| jjt tjd
 tjd d d| _d S )Nr   r{   r@  r  Zverticalanchor)r   r   r   r   r8   Zrotation_moder   r?  r  zytick.labelsizezytick.colorr  )r9   r:   rd   r   rZ  r  r  r?   r   r  r  r;   r<   r  r  r^   r   r	   r:     s(    zYAxis.__init__c                 C   s   |  |\}}|d ur||fS |j|j }}z"| jj }|||f\}}W n tyh   di f Y S 0 | jjddg\\}	}
\}}d|  kodkn  o|	| j |  k o|	k n  p||  k o|| j k n  }|i fS )NFr   r	  r   r6   r
  r  r   r   r	   r     s    zYAxis.containsc                 C   s*   |r| j }n| j}t| jdfd|i|S r  )r  r  r   r?   r  r   r   r	   r   	  s    zYAxis._get_tickc                 C   s8   | j d | j tjddd|d || _d| _dS )z
        Set the label position (left or right)

        Parameters
        ----------
        position : {'left', 'right'}
        r9  r@  rB  r?  rA  r  TN)rd   Zset_rotation_moder  r   r  r  rv   r  r   r   r	   r  	  s    
zYAxis.set_label_positionc                 C   s0  | j s
dS | j|d\}}| j \}}| jdkrz&| jjd }| |	 
 }W n tyr   | jj}Y n0 tj||g }|j}	| j|	| j| jj d  |f n|z&| jjd }| |	 
 }W n ty   | jj}Y n0 tj||g }|j}
| j|
| j| jj d  |f dS )r  Nrl  r?  r   rA  )r  r  rd   r  r  r?   r  r   r  rN   r  r  r`  rZ  r[  r\  rv  r  r  r>   r   rw  )rY   r   rz  r  r   r   r  r  r`  r?  rA  r   r   r	   rr  &	  s:    
zYAxis._update_label_positionc                 C   s>   | j  \}}| jjj}| j ||| j| jj d  f dS )r  r   N)	r  r  r?   r`  r  r  r  r>   r   )rY   rz  r  r   r   rB  r   r   r	   rs  P	  s
    
z"YAxis._update_offset_text_positionc                 C   sH   | j  \}}tjddd|d}| j | | j ||f d| _dS )zT
        Parameters
        ----------
        position : {'left', 'right'}
        r   r6   r:  r  TN)r  r  r   r  Zset_har  rv   )rY   r  r   r   r   r   r	   set_offset_position[	  s
    zYAxis.set_offset_positionc                 C   s   |  |\}}| jd  }d}|jr4||j| 7 }d}|jrL||j| 7 }|  dkrp|| j|j| 7 }n|| j|j| 7 }||fS )Nr   rz   r?  )rb  r   r   r   r  rd   rj  )rY   r   r`  ra  r   r?  rA  r   r   r	   get_text_widthsh	  s    zYAxis.get_text_widthsc                 C   s   t jg d|d |dkr:| jdddddd | | n|dkrb| jdddddd | | n^|dkr|| jdddd	 nD|d
kr| jdddd	 n*|dkr| jdddddd ndsJ dd| _dS )a  
        Set the ticks position.

        Parameters
        ----------
        position : {'left', 'right', 'both', 'default', 'none'}
            'both' sets the ticks to appear on both positions, but does not
            change the tick labels.  'default' resets the tick positions to
            the default: ticks on both positions, labels at left.  'none'
            can be used if you don't want any ticks. 'none' and 'both'
            affect only the ticks, not the labels.
        )r?  rA  r$   re   r/   r  rA  r$   TF)r4  rA  rE  r?  rC  r?  )r4  rA  r?  r/   re   r"  N)r   rj   r<  r;  rv   r  r   r   r	   r#  z	  s6    



zYAxis.set_ticks_positionc                 C   s>   d}d| j v r"| j d p | j d }| d | jd|d dS )zR
        Move ticks and ticklabels (if present) to the right of the axes.
        Tr   r   rA  r$   )r4  rE  Nr$  r%  r   r   r	   
tick_right	  s    


zYAxis.tick_rightc                 C   s>   d}d| j v r"| j d p | j d }| d | jd|d dS )zQ
        Move ticks and ticklabels (if present) to the left of the axes.
        Tr   r   r?  r$   )r4  rC  Nr$  r%  r   r   r	   	tick_left	  s    


zYAxis.tick_leftc                 C   s   ddddd|    S )zW
        Return the ticks position ("left", "right", "default", or "unknown").
        r?  rA  re   r  r(  r)  rc   r   r   r	   r*  	  s
    zYAxis.get_ticks_positionr+  r   r   r   r,  c                 C   s
   | j jjS rb   )r?   r,  Zminposyrc   r   r   r	   r$  	  s    zYAxis.get_minposc                 C   s0   |   \}}| jjt||ft|dd d d S r-  )r   r?   Zset_ylimr  r  r/  r   r   r	   rU  	  s    zYAxis.set_invertedc                 C   sd   | j j sZ| j j sZ| jd urZ| j| j| }|jd urZ| |j\}}||f| j j_	d| _
d S ru   )r?   r,  Zmutatedyr   r,  r  r-  r0  r  r   rv   )rY   r   r  r  r   r   r	   rV  	  s    


zYAxis.set_default_intervalsc                 C   sb   t jdddd}|| jj| jj }|jd }| 	dd }|dkrZt
t|| S dS d S )Nr   r6   r   r   rn  r1  )rZ  r[  r2  r3  r?   r   r>   r4  rp  r  r5  rQ   r6  r7  r   r   r	   r  	  s    

zYAxis.get_tick_space)rB   r   r   ru  r:   r   r   r  rr  rs  r;  r<  r#  r=  r>  r*  r  r   rN  rO  rP  r$  rU  rV  r  r   r   r   r^   r	   r8    s0   *$r8  )7r   r  r  loggingZnumpyrQ   Z
matplotlibr;   r   Zmatplotlib.artistr]   r   Zmatplotlib.cbookr  Zmatplotlib.linesr  rG   Zmatplotlib.scaleZscaler"  Zmatplotlib.texttextrO   Zmatplotlib.tickerZtickerr   Zmatplotlib.transformsZ
transformsrZ  Zmatplotlib.unitsr-  r  	getLoggerrB   _logrM   ZArtistInspectorrH   Z_line_inspectorZget_settersZ_line_param_namesZaliasdr}  Z_line_param_aliasesr   ZArtistr   r   r   r   r   r   r  r  r8  r   r   r   r	   <module>   sZ   
  v==)           k  