a
    r=ici                     @   s"  d Z ddlmZ ddlZddlZddlmZmZ ddl	m
Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZmZmZmZ d
dlm Z  G dd dZ!G dd de!eZ"G dd dej#Z$G dd de!e$Z%G dd de%Z&G dd deZ'G dd dej(Z)dS )aG
  
The :mod:`.axis_artist` module implements custom artists to draw axis elements
(axis lines and labels, tick lines and labels, grid lines).

Axis lines and labels and tick lines and labels are managed by the `AxisArtist`
class; grid lines are managed by the `GridlinesCollection` class.

There is one `AxisArtist` per Axis; it can be accessed through
the ``axis`` dictionary of the parent Axes (which should be a
`mpl_toolkits.axislines.Axes`), e.g. ``ax.axis["bottom"]``.

Children of the AxisArtist are accessed as attributes: ``.line`` and ``.label``
for the axis line and label, ``.major_ticks``, ``.major_ticklabels``,
``.minor_ticks``, ``.minor_ticklabels`` for the tick lines and labels (e.g.
``ax.axis["bottom"].line``).

Children properties (colors, fonts, line widths, etc.) can be set using
setters, e.g. ::

  # Make the major ticks of the bottom axis red.
  ax.axis["bottom"].major_ticks.set_color("red")

However, things like the locations of ticks, and their ticklabels need to be
changed from the side of the grid_helper.

axis_direction
--------------

`AxisArtist`, `AxisLabel`, `TickLabels` have an *axis_direction* attribute,
which adjusts the location, angle, etc. The *axis_direction* must be one of
"left", "right", "bottom", "top", and follows the Matplotlib convention for
rectangular axis.

For example, for the *bottom* axis (the left and right is relative to the
direction of the increasing coordinate),

* ticklabels and axislabel are on the right
* ticklabels and axislabel have text angle of 0
* ticklabels are baseline, center-aligned
* axislabel is top, center-aligned

The text angles are actually relative to (90 + angle of the direction to the
ticklabel), which gives 0 for bottom axis.

=================== ====== ======== ====== ========
Parameter           left   bottom   right  top
=================== ====== ======== ====== ========
ticklabels location left   right    right  left
axislabel location  left   right    right  left
ticklabels angle    90     0        -90    180
axislabel angle     180    0        0      180
ticklabel va        center baseline center baseline
axislabel va        center top      center bottom
ticklabel ha        right  center   right  center
axislabel ha        right  center   right  center
=================== ====== ======== ====== ========

Ticks are by default direct opposite side of the ticklabels. To make ticks to
the same side of the ticklabels, ::

  ax.axis["bottom"].major_ticks.set_tick_out(True)

The following attributes can be customized (use the ``set_xxx`` methods):

* `Ticks`: ticksize, tick_out
* `TickLabels`: pad
* `AxisLabel`: pad
    )methodcallerN)_apicbook)LineCollection)Line2D)	PathPatch)Path)Affine2DBboxIdentityTransformScaledTranslation   )AxislineStylec                       s$   e Zd Zdd Z fddZ  ZS )AttributeCopierc                 C   s   t ddS )zz
        Return the underlying artist that actually defines some properties
        (e.g., color) of this artist.
        zget_ref_artist must overriddenN)RuntimeErrorself r   t/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/mpl_toolkits/axisartist/axis_artist.pyget_ref_artist^   s    zAttributeCopier.get_ref_artistc                    s.   t d| }|t }|dkr*||  S |S )Nget_auto)r   superr   )r   	attr_namegetterprop	__class__r   r   get_attribute_from_ref_artiste   s    
z-AttributeCopier.get_attribute_from_ref_artist)__name__
__module____qualname__r   r   __classcell__r   r   r   r   r   ]   s   r   c                   @   s   e Zd ZdZddd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gddggZdd ZdS ) TicksaO  
    Ticks are derived from Line2D, and note that ticks themselves
    are markers. Thus, you should use set_mec, set_mew, etc.

    To change the tick size (length), you need to use
    set_ticksize. To change the direction of the ticks (ticks are
    in opposite direction of ticklabels by default), use
    set_tick_out(False).
    FN)axisc                K   sv   || _ g | _| | || _| jd urNd|vr6d|d< d|vrNd|vrNd|d< tj| dgdgfi | | d d S )Ncolorr   Zmewmarkeredgewidth        T)	_ticksizelocs_angles_labelsset_tick_out_axisr   __init__Zset_snap)r   ticksizeZtick_outr$   kwargsr   r   r   r,   v   s    

zTicks.__init__c                 C   s   | j jd jS Nr   )r+   Z
majorTicksZ	tick1liner   r   r   r   r      s    zTicks.get_ref_artistc                 C   s(   t |dstj|d || _d| _d S )Nr   )r%   T)r   Z
_str_equalmcolorsZ_check_color_like_colorstale)r   r%   r   r   r   	set_color   s    zTicks.set_colorc                 C   s
   |  dS Nr%   r   r   r   r   r   	get_color   s    zTicks.get_colorc                 C   s
   |  dS )NZmarkeredgecolorr5   r   r   r   r   get_markeredgecolor   s    zTicks.get_markeredgecolorc                 C   s
   |  dS )Nr&   r5   r   r   r   r   get_markeredgewidth   s    zTicks.get_markeredgewidthc                 C   s
   || _ dS )z7Set whether ticks are drawn inside or outside the axes.NZ	_tick_out)r   br   r   r   r*      s    zTicks.set_tick_outc                 C   s   | j S )z:Return whether ticks are drawn inside or outside the axes.r9   r   r   r   r   get_tick_out   s    zTicks.get_tick_outc                 C   s
   || _ dS )z"Set length of the ticks in points.Nr(   )r   r-   r   r   r   set_ticksize   s    zTicks.set_ticksizec                 C   s   | j S )z%Return length of the ticks in points.r<   r   r   r   r   get_ticksize   s    zTicks.get_ticksizec                 C   s
   || _ d S N)locs_angles)r   r@   r   r   r   set_locs_angles   s    zTicks.set_locs_anglesr'         ?c              	   C   s   |   sd S | }||   ||   || j |  }t	 
|| j}|  rj|d | jD ]\\}}|t|g}| jr| jjj|d  sqp||| j|t	 | t||  qp|  d S )N   r   )get_visibleZnew_gcZset_foregroundr7   Zset_linewidthr8   Z	set_alphaZ_alphaget_transformr	   scalepoints_to_pixelsr(   r;   Z
rotate_degr@   Ztransform_non_affinenparrayaxesZviewLimcontainsZdraw_markers_tickvert_pathr   Z
get_affinerestore)r   renderergcZ
path_transZmarker_transformlocZanglelocsr   r   r   draw   s,    

z
Ticks.draw)F)r   r    r!   __doc__r,   r   r3   r6   r7   r8   r*   r;   r=   r>   rA   r   rL   rR   r   r   r   r   r#   k   s   
r#   c                       sb   e Zd ZdZ fddZedd Zedd Zdd	d
ddjZ	 fddZ
d fdd	Z  ZS )	LabelBasez
    A base class for AxisLabel and TickLabels. The position and angle
    of the text are calculated by to offset_ref_angle,
    text_ref_angle, and offset_radius attributes.
    c                    s8   g | _ d| _d| _t j|i | | d d| _d S )Nr   r'   anchorT)r)   
_ref_angle_offset_radiusr   r,   Zset_rotation_mode_text_follow_ref_angle)r   argsr.   r   r   r   r,      s    
zLabelBase.__init__c                 C   s   | j r| jd S dS d S )NZ   r   )rX   rV   r   r   r   r   _text_ref_angle   s    
zLabelBase._text_ref_anglec                 C   s   | j S r?   )rV   r   r   r   r   _offset_ref_angle   s    zLabelBase._offset_ref_anglerightleftbottomtop)r^   r]   r`   r_   c                    s   |   sd S |  }|  }t| j}| j}|t| |t|  }}| 	|t
 ||  | | j|  t | | 	| | | d S r?   )rD   rE   get_rotationrH   deg2radr\   rW   cossinset_transformr	   	translateset_rotationr[   r   rR   )r   rN   tr
angle_origthetadddxdyr   r   r   rR      s    
zLabelBase.drawNc           	         s   |d u r| j  }|  }|  }t| j}| j}|t| |t	|  }}| 
|t ||  | | j|  t | }| 
| | | |S r?   )figure_get_rendererrE   ra   rH   rb   r\   rW   rc   rd   re   r	   rf   rg   r[   r   get_window_extentfrozen)	r   rN   rh   ri   rj   rk   rl   rm   Zbboxr   r   r   rp      s    


zLabelBase.get_window_extent)N)r   r    r!   rS   r,   propertyr[   r\   __getitem___get_opposite_directionrR   rp   r"   r   r   r   r   rT      s   


rT   c                       s   e Zd ZdZdddddZdd Zd	d
 Zdd Z fddZe	dddddZ
dd Ze	dddddZdd Zdd Zdd Z fddZd  fdd	Z  ZS )!	AxisLabela  
    Axis Label. Derived from Text. The position of the text is updated
    in the fly, so changing text position has no effect. Otherwise, the
    properties can be changed as a normal Text.

    To change the pad between ticklabels and axis label, use set_pad.
    r_   N)axis_directionr$   c                O   s8   || _ d| _d| _tj| g|R i | | | d S )N   r   )r+   _pad_external_padrT   r,   set_axis_direction)r   rv   r$   rY   r.   r   r   r   r,     s
    zAxisLabel.__init__c                 C   s
   || _ dS )z
        Set the internal pad in points.

        The actual pad will be the sum of the internal pad and the
        external pad (the latter is set automatically by the AxisArtist).
        Nrx   )r   padr   r   r   set_pad#  s    zAxisLabel.set_padc                 C   s   | j S )z^
        Return the internal pad in points.

        See `.set_pad` for more details.
        r{   r   r   r   r   get_pad,  s    zAxisLabel.get_padc                 C   s
   | j  S r?   )r+   	get_labelr   r   r   r   r   4  s    zAxisLabel.get_ref_artistc                    s&   t   }|dkr | j  S | jS )N__from_axes__)r   get_textr+   r   _text)r   tr   r   r   r   8  s    
zAxisLabel.get_text)r_   center)r`   r   r^   r]   r_   r`   c                 C   s,   t j| j|d\}}| | | | d S N)d)r   check_getitem_default_alignmentsZset_vaZset_ha)r   r   vahar   r   r   set_default_alignmentC  s    
zAxisLabel.set_default_alignmentrC   r   c                 C   s   |  tj| j|d d S r   )rg   r   r   _default_anglesr   r   r   r   r   set_default_angleM  s    zAxisLabel.set_default_anglec                 C   s   |  | | | dS )a  
        Adjust the text angle and text alignment of axis label
        according to the matplotlib convention.

        =====================    ========== ========= ========== ==========
        property                 left       bottom    right      top
        =====================    ========== ========= ========== ==========
        axislabel angle          180        0         0          180
        axislabel va             center     top       center     bottom
        axislabel ha             right      center    right      center
        =====================    ========== ========= ========== ==========

        Note that the text angles are actually relative to (90 + angle
        of the direction to the ticklabel), which gives 0 for bottom
        axis.
        N)r   r   r   r   r   r   rz   P  s    
zAxisLabel.set_axis_directionc                 C   s
   |  dS r4   r5   r   r   r   r   r6   d  s    zAxisLabel.get_colorc                    s2   |   sd S | j||   | _t | d S r?   )rD   ry   rG   r~   rW   r   rR   r   rN   r   r   r   rR   g  s
    zAxisLabel.drawc                    sH   |d u r| j  }|  sd S | j||   }|| _t |}|S r?   )	rn   ro   rD   ry   rG   r~   rW   r   rp   )r   rN   rbbr   r   r   rp   p  s    
zAxisLabel.get_window_extent)N)r   r    r!   rS   r,   r}   r~   r   r   dictr   r   r   r   rz   r6   rR   rp   r"   r   r   r   r   ru     s,   		ru   c                       s   e Zd ZdZdd fdd
Zdd Zdd	 Zd
d Zdd Ze	dddddZ
e	dddddZdd Zdd ZdddZdd Z  ZS ) 
TickLabelsa  
    Tick Labels. While derived from Text, this single artist draws all
    ticklabels. As in AxisLabel, the position of the text is updated
    in the fly, so changing text position has no effect. Otherwise,
    the properties can be changed as a normal Text. Unlike the
    ticklabels of the mainline matplotlib, properties of single
    ticklabel alone cannot modified.

    To change the pad between ticks and ticklabels, use set_pad.
    r_   )rv   c                   s&   t  jf i | | | d| _d S r/   )r   r,   rz   _axislabel_pad)r   rv   r.   r   r   r   r,     s    
zTickLabels.__init__c                 C   s   | j  d S r/   )r+   Zget_ticklabelsr   r   r   r   r     s    zTickLabels.get_ref_artistc                 C   s   |  | | | || _dS )a^  
        Adjust the text angle and text alignment of ticklabels
        according to the matplotlib convention.

        The *label_direction* must be one of [left, right, bottom, top].

        =====================    ========== ========= ========== ==========
        property                 left       bottom    right      top
        =====================    ========== ========= ========== ==========
        ticklabels angle         90         0         -90        180
        ticklabel va             center     baseline  center     baseline
        ticklabel ha             right      center    right      center
        =====================    ========== ========= ========== ==========

        Note that the text angles are actually relative to (90 + angle
        of the direction to the ticklabel), which gives 0 for bottom
        axis.
        N)r   r   _axis_directionr   label_directionr   r   r   rz     s    

zTickLabels.set_axis_directionc                 C   s   |  | j}| | d S r?   )rt   r   rz   r   r   r   r   invert_axis_direction  s    z TickLabels.invert_axis_directionc           
      C   s  |  |}|sdS d}|  |   }}|dkrdtdd |D }|dkrP|}n|dkr`d| }n,|dkrtd	d |D }|dkr|}n|dkrd| }n|d
krtdd |D }|d
kr|}nL|dkrd| }n:|dkrtdd |D }tdd |D }	|}||	 }nz|dkrtdd |D }|dkrB|}nN|dkrVd| }n:|dkrtdd |D }tdd |D }	|	}||	 }||fS )a@  
        Calculate the ticklabel offsets from the tick and their total heights.

        The offset only takes account the offset due to the vertical alignment
        of the ticklabels: if axis direction is bottom and va is 'top', it will
        return 0; if va is 'baseline', it will return (height-descent).
        r   r   r   r^   c                 s   s   | ]\}}}|V  qd S r?   r   .0whr   r   r   r   	<genexpr>      z5TickLabels._get_ticklabels_offsets.<locals>.<genexpr>r   g      ?r]   c                 s   s   | ]\}}}|V  qd S r?   r   r   r   r   r   r     r   r_   c                 s   s   | ]\}}}|V  qd S r?   r   r   r   r   r   r     r   baselinec                 s   s   | ]\}}}|| V  qd S r?   r   r   r   r   r   r     r   c                 s   s   | ]\}}}|V  qd S r?   r   r   r   r   r   r     r   r`   c                 s   s   | ]\}}}|V  qd S r?   r   r   r   r   r   r     r   c                 s   s   | ]\}}}|| V  qd S r?   r   r   r   r   r   r     r   c                 s   s   | ]\}}}|V  qd S r?   r   r   r   r   r   r     r   )!get_texts_widths_heights_descentsZget_vaZget_hamax)
r   rN   r   whd_listr   r   r   r|   Z
max_ascentZmax_descentr   r   r   _get_ticklabels_offsets  sP    










z"TickLabels._get_ticklabels_offsets)r   r]   )r   r^   )r   r   r   rZ   ir   rC   c           	      C   s   |   s| j| _d S | || j\}}| j||   }|| | _| jD ]H\\}}}}|	 sbqJ|| _
| | | | | | t| | qJ|| | _d S r?   )rD   ry   r   r   r   rG   r~   rW   _locs_angles_labelsstriprV   set_xset_yset_textrT   rR   )	r   rN   r   total_widthr|   xyalr   r   r   rR     s"    



zTickLabels.drawc                 C   s
   || _ d S r?   )r   )r   r)   r   r   r   set_locs_angles_labels  s    z!TickLabels.set_locs_angles_labelsNc                 C   s   |d u r| j  }|  s&| j| _g S g }| || j\}}| j||   }|| | _	| j
D ]H\\}}}}	|| _| | | | | |	 t| |}
||
 q`|| | _|S r?   )rn   ro   rD   ry   r   r   r   rG   r~   rW   r   rV   r   r   r   rT   rp   append)r   rN   Zbboxesr   r   r|   r   r   r   r   r   r   r   r   get_window_extents
  s(    





zTickLabels.get_window_extentsc           	      C   sN   g }| j D ]>\}}}| sq
| |\}}|j|| j|d}|| q
|S )zz
        Return a list of ``(width, height, descent)`` tuples for ticklabels.

        Empty labels are left out.
        )ismath)r   r   Z_preprocess_mathZget_text_width_height_descentZ_fontpropertiesr   )	r   rN   r   Z_locZ_anglelabelZ
clean_liner   Zwhdr   r   r   r   '  s    z,TickLabels.get_texts_widths_heights_descents)N)r   r    r!   rS   r,   r   rz   r   r   r   r   r   rR   r   r   r   r"   r   r   r   r   r   ~  s(   8
r   c                       sH   e Zd Zddd fdd
Zdd Zdd	 Zd
d Z fddZ  ZS )GridlinesCollectionmajorZboth)whichr$   c                   s,   || _ || _t j|i | | d dS )zt
        Parameters
        ----------
        which : {"major", "minor"}
        axis : {"both", "x", "y"}
        N)_whichr+   r   r,   set_grid_helper)r   r   r$   rY   r.   r   r   r   r,   9  s    zGridlinesCollection.__init__c                 C   s
   || _ d S r?   )r   )r   r   r   r   r   	set_whichE  s    zGridlinesCollection.set_whichc                 C   s
   || _ d S r?   )r+   )r   r$   r   r   r   set_axisH  s    zGridlinesCollection.set_axisc                 C   s
   || _ d S r?   )_grid_helper)r   Zgrid_helperr   r   r   r   K  s    z#GridlinesCollection.set_grid_helperc                    sN   | j d ur>| j | j | j | j| j}| dd |D  t | d S )Nc                 S   s   g | ]}t |qS r   )rH   Z	transpose)r   r   r   r   r   
<listcomp>R  r   z,GridlinesCollection.draw.<locals>.<listcomp>)	r   
update_limrJ   Zget_gridlinesr   r+   Zset_segmentsr   rR   )r   rN   glr   r   r   rR   N  s
    
zGridlinesCollection.draw)	r   r    r!   r,   r   r   r   rR   r"   r   r   r   r   r   8  s
   r   c                       s  e Zd ZdZdZedd Zej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d@ddZdd Zdd Zdd Zdd Zd d! ZdAd"d#Zd$d% Zed&d'd(d)d*Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 ZdBd9d:Z e!j"d;d< Z#dCd=d>Z$  Z%S )D
AxisArtistz
    An artist which draws axis (a line along which the n-th axes coord
    is constant) line, ticks, ticklabels, and axis label.
    g      @c                 C   s
   | j  S r?   )r   r~   r   r   r   r   LABELPAD^  s    zAxisArtist.LABELPADc                 C   s   | j | d S r?   )r   r}   )r   vr   r   r   r   b  s    Nr_   c                    s   t  jf i | || _|| _|du r*d}tg |t d| jjj R  | _	|dv rb|j
| _n|j| _d| _|| _|   | jf i | | | |   d| _d| _| | dS )z
        Parameters
        ----------
        axes : `mpl_toolkits.axisartist.axislines.Axes`
        helper : `~mpl_toolkits.axisartist.axislines.AxisArtistHelper`
        Nr   gqq?)r^   r]   r'   )r   r,   rJ   _axis_artist_helperr   r	   rF   rn   Zdpi_scale_transoffset_transformZyaxisr$   Zxaxis_axisline_styler   
_init_line_init_ticks_init_offsetText_init_label_ticklabel_add_angle_axislabel_add_anglerz   )r   rJ   helperoffsetrv   r.   r   r   r   r,   f  s0    



zAxisArtist.__init__c                 C   sT   | j | | j| || _|dv r<| d | d n| d | d dS )aL  
        Adjust the direction, text angle, text alignment of
        ticklabels, labels following the matplotlib convention for
        the rectangle axes.

        The *axis_direction* must be one of [left, right, bottom, top].

        =====================    ========== ========= ========== ==========
        property                 left       bottom    right      top
        =====================    ========== ========= ========== ==========
        ticklabels location      "-"        "+"       "+"        "-"
        axislabel location       "-"        "+"       "+"        "-"
        ticklabels angle         90         0         -90        180
        ticklabel va             center     baseline  center     baseline
        ticklabel ha             right      center    right      center
        axislabel angle          180        0         0          180
        axislabel va             center     top       center     bottom
        axislabel ha             right      center    right      center
        =====================    ========== ========= ========== ==========

        Note that the direction "+" and "-" are relative to the direction of
        the increasing coordinate. Also, the text angles are actually
        relative to (90 + angle of the direction to the ticklabel),
        which gives 0 for bottom axis.
        )r^   r`   -+N)major_ticklabelsrz   r   r   set_ticklabel_directionset_axislabel_direction)r   rv   r   r   r   rz     s    

zAxisArtist.set_axis_directionc                 C   s   t jddd|d| _dS )z
        Adjust the direction of the ticklabel.

        Note that the *label_direction*\s '+' and '-' are relative to the
        direction of the increasing coordinate.

        Parameters
        ----------
        tick_direction : {"+", "-"}
        r   rC   r   r   )tick_directionN)r   r   r   )r   r   r   r   r   r     s    
z"AxisArtist.set_ticklabel_directionc                 C   s(   | j d d | _ | j  | j  d S )NrC   h  )r   r   r   minor_ticklabelsr   r   r   r   invert_ticklabel_direction  s    
z%AxisArtist.invert_ticklabel_directionc                 C   s   t jddd|d| _dS )z
        Adjust the direction of the axislabel.

        Note that the *label_direction*\s '+' and '-' are relative to the
        direction of the increasing coordinate.

        Parameters
        ----------
        label_direction : {"+", "-"}
        r   rC   r   )r   N)r   r   r   r   r   r   r   r     s    
z"AxisArtist.set_axislabel_directionc                 C   s   | j j| j S r?   )rJ   Z	transAxesr   r   r   r   r   rE     s    zAxisArtist.get_transformc                 C   s   | j S )z5
        Return axis artist helper instance.
        )r   r   r   r   r   
get_helper  s    zAxisArtist.get_helperc                 K   sB   |du rt  S t|t jr$|| _nt |fi || _|   dS )a  
        Set the axisline style.

        The new style is completely defined by the passed attributes. Existing
        style attributes are forgotten.

        Parameters
        ----------
        axisline_style : str or None
            The line style, e.g. '->', optionally followed by a comma-separated
            list of attributes. Alternatively, the attributes can be provided
            as keywords.

            If *None* this returns a string containing the available styles.

        Examples
        --------
        The following two commands are equal:
        >>> set_axisline_style("->,size=1.5")
        >>> set_axisline_style("->", size=1.5)
        N)r   Zpprint_styles
isinstanceZ_Baser   r   )r   axisline_styler.   r   r   r   set_axisline_style  s    zAxisArtist.set_axisline_stylec                 C   s   | j S )z"Return the current axisline style.)r   r   r   r   r   get_axisline_style  s    zAxisArtist.get_axisline_stylec              	   C   sr   | j | j| j }|  }|du r`t| j | jtjd dtjd tjd tjd |d| _	n|| |d| _	dS )	zY
        Initialize the *line* artist that is responsible to draw the axis line.
        Nzaxes.edgecolorFzaxes.linewidthzlines.solid_capstylezlines.solid_joinstyle)r%   fillZ	linewidthZcapstyleZ	joinstyle	transform)r   )
r   Zget_line_transformrJ   r   r   r   get_linemplrcParamsline)r   Ztranr   r   r   r   r     s    
	zAxisArtist._init_linec                 C   sD   | j | j| j |  d ur4| j | j  | j 	| d S r?   )
r   Zset_pathr   r   rJ   r   Zset_line_mutation_scaler   get_sizerR   r   r   r   r   
_draw_line  s    zAxisArtist._draw_linec                 K   s   | j j}| j| j| j }t|dtj	| d | j |d| _
t|dtj	| d | j |d| _tj	| d }t| j | j| jj|||dtj	| d d	| _t| j | j| jj|||d
tj	| d d	| _d S )NZmajor_tick_sizeztick.major.size)r$   r   Zminor_tick_sizeztick.minor.sizeztick.labelsizeZmajor_tick_padztick.major.pad)r$   rv   rn   r   fontsizer|   Zminor_tick_padztick.minor.pad)r$   	axis_namer   Zget_tick_transformrJ   r   r#   getr   r   major_ticksminor_ticksr   r   rn   r   r   )r   r.   r   Ztranssizer   r   r   r      sN    	zAxisArtist._init_ticksc                 C   s~   g }g }| j }|D ]b\}}}}|d | }	d|	| d   krFdkrNn n|n|d }
|||
g |||	|g q||fS )z
        Return a pair of:

        - list of locs and angles for ticks
        - list of locs, angles and labels for ticklabels.
        rZ   r   i  rC   )r   r   )r   Z	tick_iterZticks_loc_angleZticklabels_loc_angle_labelZticklabel_add_anglerP   Zangle_normalangle_tangentr   angle_labelZ
angle_tickr   r   r   _get_tick_infoE  s    zAxisArtist._get_tick_infoc                 C   s   |d u r| j  }|d}| j rN| j rN| jj| }|| j_|| j	_nd| j_d| j	_| j
| j\}}| |\}}| j| | j| | |\}}| j| | j	| d S )NrB   r   )rn   ro   rG   r   rD   r;   r(   r   ry   r   r   Zget_tick_iteratorsrJ   r   rA   r   r   )r   rN   Zdpi_corZticklabel_padZmajortick_iterZminortick_iterZtick_loc_angleZticklabel_loc_angle_labelr   r   r   _update_ticks[  s&    


zAxisArtist._update_ticksc                 C   s\   |  | | j| | j| | j| | j| | j sN| j rX| | d S r?   )r   r   rR   r   r   r   rD   _draw_offsetTextr   r   r   r   _draw_ticksx  s    

zAxisArtist._draw_ticks)r   r   r_   r]   )r   r   r_   r^   )r   r   r`   r]   )r   r   r_   r]   r   c              
   C   sX   | j | \}}}}tjd||fdddtjd ||d| _| jt  | j	| j d S )N zaxes fractionr   zoffset pointszxtick.color)xyZxycoordsZxytextZ
textcoordsr%   ZhorizontalalignmentZverticalalignment)
_offsetText_posmtextZ
Annotationr   r   
offsetTextre   r   rJ   Z_set_artist_props)r   	directionr   r   r   r   r   r   r   r     s    zAxisArtist._init_offsetTextc                 C   sP   | j | jjj  | j | j  | j	 | j  d }d|f| j _
d S )N   r   )r   r   r$   r   	formatterZ
get_offsetZset_sizer   r   r~   Zxyann)r   r   r   r   r   _update_offsetText  s    zAxisArtist._update_offsetTextc                 C   s   |    | j| d S r?   )r   r   rR   r   r   r   r   r     s    zAxisArtist._draw_offsetTextc                 K   st   | j | j| j }tdddd|dtjd tjd | j|| j	d	| _
| j
| jj |dd	}| j
| d S )
Nr   r   r   Z	labelsizezaxes.labelsizezaxes.labelweight)r%   r   Z
fontweightr$   r   rv   labelpadrw   )r   Zget_axislabel_transformrJ   r   ru   r   r   r   r$   r   r   Z
set_figurern   r}   )r   r.   rh   r   r   r   r   r     s    	zAxisArtist._init_labelc                 C   s   | j  sd S | j| jkrR| j r.| j rB| j rL| j sL| jj}qdd}nt| j	j
| jj
}|| j _| j| j\}}|d u rd S |d }|\}}|| j | j _| j j||d d S )Nr   rZ   )r   r   )r   rD   r   r   r   r;   r   r(   r   r   r   r   ry   r   Zget_axislabel_pos_anglerJ   rV   set)r   rN   Zaxislabel_padr   r   r   r   r   r   r   r   _update_label  s0    


zAxisArtist._update_labelc                 C   s   |  | | j| d S r?   )r   r   rR   r   r   r   r   _draw_label  s    
zAxisArtist._draw_labelc                 C   s   | j | d S r?   )r   r   )r   sr   r   r   	set_label  s    zAxisArtist.set_labelc                 C   s   |   sd S | j| j | | | | g | j|| j|| j	
|| j
|}dd |D }|rt|}|S d S d S )Nc                 S   s(   g | ] }|r|j d ks |jd kr|qS )r   )widthheight)r   r:   r   r   r   r     r   z,AxisArtist.get_tightbbox.<locals>.<listcomp>)rD   r   r   rJ   r   r   r   r   r   r   rp   r   r
   union)r   rN   r   Z_bboxr   r   r   get_tightbbox  s&    






zAxisArtist.get_tightbboxc                 C   sX   |   sd S |jt|  d | j| j | | | | | 	| |
t d S )N)gid)rD   Z
open_groupr   Zget_gidr   r   rJ   r   r   r   Zclose_groupr   r   r   r   rR     s    


zAxisArtist.drawc                 C   s   |rd\}}}n|dur$d\}}}n
d\}}}|dur:|}|durF|}|durR|}|durr| j | | j| |dur| j| | j| |dur| j| dS )a@  
        Toggle visibility of ticks, ticklabels, and (axis) label.
        To turn all off, ::

          axis.toggle(all=False)

        To turn all off but ticks on ::

          axis.toggle(all=False, ticks=True)

        To turn all on but (axis) label off ::

          axis.toggle(all=True, label=False))

        )TTTN)FFF)NNN)r   Zset_visibler   r   r   r   )r   allZticksZ
ticklabelsr   Z_ticksZ_ticklabelsZ_labelr   r   r   toggle  s&    
zAxisArtist.toggle)Nr_   )N)N)N)NNNN)&r   r    r!   rS   Zzorderrr   r   setterr,   rz   r   r   r   rE   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  martistZallow_rasterizationrR   r  r"   r   r   r   r   r   V  sN   

  .$
 %



r   )*rS   operatorr   numpyrH   Z
matplotlibr   r   r   Zmatplotlib.artistZartistr  Zmatplotlib.colorscolorsr0   Zmatplotlib.texttextr   Zmatplotlib.collectionsr   Zmatplotlib.linesr   Zmatplotlib.patchesr   Zmatplotlib.pathr   Zmatplotlib.transformsr	   r
   r   r   r   r   r   r#   TextrT   ru   r   r   ZArtistr   r   r   r   r   <module>   s*   I`Hk ;