o
    h~                     @   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.

=================== ====== ======== ====== ========
Property            left   bottom   right  top
=================== ====== ======== ====== ========
ticklabel location  left   right    right  left
axislabel location  left   right    right  left
ticklabel 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)zz
        Return the underlying artist that actually defines some properties
        (e.g., color) of this artist.
        zget_ref_artist must overridden)RuntimeErrorself r   w/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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 ) TicksaW  
    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r'd|vrd|d< d|vr'd|vr'd|d< tj| dgdgfi | | d d S )Ncolorr   mewmarkeredgewidth        T)	_ticksizelocs_angles_labelsset_tick_out_axisr   __init__set_snap)r   ticksizetick_outr$   kwargsr   r   r   r-   v   s   

zTicks.__init__c                 C   s   | j jd jS Nr   )r,   
majorTicks	tick1liner   r   r   r   r         zTicks.get_ref_artistc                 C   s(   t |dstj|d || _d| _d S )Nr   )r%   T)r   
_str_equalmcolors_check_color_like_colorstale)r   r%   r   r   r   	set_color   s   
zTicks.set_colorc                 C   
   |  dS Nr%   r   r   r   r   r   	get_color      
zTicks.get_colorc                 C   r<   )Nmarkeredgecolorr>   r   r   r   r   get_markeredgecolor   r@   zTicks.get_markeredgecolorc                 C   r<   )Nr'   r>   r   r   r   r   get_markeredgewidth   r@   zTicks.get_markeredgewidthc                 C   
   || _ dS )z7Set whether ticks are drawn inside or outside the axes.N	_tick_out)r   br   r   r   r+         
zTicks.set_tick_outc                 C      | j S )z:Return whether ticks are drawn inside or outside the axes.rE   r   r   r   r   get_tick_out      zTicks.get_tick_outc                 C   rD   )z"Set length of the ticks in points.Nr)   )r   r/   r   r   r   set_ticksize   rH   zTicks.set_ticksizec                 C   rI   )z%Return length of the ticks in points.rL   r   r   r   r   get_ticksize   rK   zTicks.get_ticksizec                 C   
   || _ d S N)locs_angles)r   rQ   r   r   r   set_locs_angles   r@   zTicks.set_locs_anglesr(         ?c              	   C   s   |   sd S | }||   ||   || j |  }t	 
|| j}|  r5|d | jD ].\}}|t|g}| jrR| jjj|d  sRq8||| j|t	 | t||  q8|  d S )N   r   )get_visiblenew_gcset_foregroundrB   set_linewidthrC   	set_alpha_alphaget_transformr	   scalepoints_to_pixelsr)   rJ   
rotate_degrQ   transform_non_affinenparrayaxesviewLimcontainsdraw_markers_tickvert_pathr   
get_affinerestore)r   renderergc
path_transmarker_transformlocanglelocsr   r   r   draw   s,   
z
Ticks.draw)F)r   r    r!   __doc__r-   r   r;   r?   rB   rC   r+   rJ   rM   rN   rR   r   rf   rp   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 the 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-   set_rotation_mode_text_follow_ref_angle)r   argsr1   r   r   r   r-      s   

zLabelBase.__init__c                 C   s   | j r| jd S dS )NZ   r   )rw   rt   r   r   r   r   _text_ref_angle   s   
zLabelBase._text_ref_anglec                 C   rI   rP   )rt   r   r   r   r   _offset_ref_angle   rK   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 rP   )rU   r[   get_rotationr`   deg2radr{   ru   cossinset_transformr	   	translateset_rotationrz   r   rp   )r   ri   tr
angle_origthetadddxdyr   r   r   rp      s   
zLabelBase.drawNc           	         s   |d u r| j dd }|  }|  }t| j}| j}|t| |t	| }}| 
|t ||  | | j|  t | }| 
| | | |S NTroot)
get_figure_get_rendererr[   r   r`   r   r{   ru   r   r   r   r	   r   r   rz   r   get_window_extentfrozen)	r   ri   r   r   r   r   r   r   bboxr   r   r   r      s   

zLabelBase.get_window_extentrP   )r   r    r!   rq   r-   propertyrz   r{   __getitem___get_opposite_directionrp   r   r"   r   r   r   r   rr      s     


rr   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 tick labels 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_padrr   r-   set_axis_direction)r   r   r$   rx   r1   r   r   r   r-     s
   zAxisLabel.__init__c                 C   rD   )a%  
        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`).

        Parameters
        ----------
        pad : float
            The internal pad in points.
        Nr   )r   padr   r   r   set_pad#  s   
zAxisLabel.set_padc                 C   rI   )z^
        Return the internal pad in points.

        See `.set_pad` for more details.
        r   r   r   r   r   get_pad1  s   zAxisLabel.get_padc                 C   s   | j jS rP   )r,   labelr   r   r   r   r   9  s   zAxisLabel.get_ref_artistc                    s$   t   }|dkr| jj S | jS )N__from_axes__)r   get_textr,   r   _text)r   tr   r   r   r   =  s   
zAxisLabel.get_text)r~   center)r   r   r}   r|   r~   r   c                 C   s,   t j| j|d\}}| | | | dS )z
        Set the default alignment. See `set_axis_direction` for details.

        Parameters
        ----------
        d : {"left", "bottom", "right", "top"}
        dN)r   check_getitem_default_alignmentsset_vaset_ha)r   r   vahar   r   r   set_default_alignmentI  s   
zAxisLabel.set_default_alignmentrT   r   c                 C   s   |  tj| j|d dS )z
        Set the default angle. See `set_axis_direction` for details.

        Parameters
        ----------
        d : {"left", "bottom", "right", "top"}
        r   N)r   r   r   _default_anglesr   r   r   r   r   set_default_angleZ  s   zAxisLabel.set_default_anglec                 C   s   |  | | | dS )ah  
        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.

        Parameters
        ----------
        d : {"left", "bottom", "right", "top"}
        N)r   r   r   r   r   r   r   d  s   
zAxisLabel.set_axis_directionc                 C   r<   r=   r>   r   r   r   r   r?   |  r@   zAxisLabel.get_colorc                    s2   |   sd S | j||   | _t | d S rP   )rU   r   r]   r   ru   r   rp   r   ri   r   r   r   rp     s
   zAxisLabel.drawc                    sN   |d u r| j dd }|  sd S | j||   }|| _t |}|S r   )	r   r   rU   r   r]   r   ru   r   r   )r   ri   rbbr   r   r   r     s   zAxisLabel.get_window_extentrP   )r   r    r!   rq   r-   r   r   r   r   dictr   r   r   r   r   r?   rp   r   r"   r   r   r   r   r     s.    
	r   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 a single
    ticklabel alone cannot be modified.

    To change the pad between ticks and ticklabels, use `~.AxisLabel.set_pad`.
    r~   )r   c                   s&   t  jdi | | | d| _d S )Nr   r   )r   r-   r   _axislabel_pad)r   r   r1   r   r   r   r-     s   

zTickLabels.__init__c                 C   s   | j  d S r2   )r,   get_ticklabelsr   r   r   r   r     r5   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
        =====================    ========== ========= ========== ==========
        ticklabel 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.

        Parameters
        ----------
        label_direction : {"left", "bottom", "right", "top"}

        N)r   r   _axis_directionr   label_directionr   r   r   r     s   


zTickLabels.set_axis_directionc                 C   s   |  | j}| | d S rP   )r   r   r   r   r   r   r   invert_axis_direction  s   z TickLabels.invert_axis_directionc           
      C   s  |  |}|s	dS d}|  |  }}|dkr7tdd |D }|dkr+|}||fS |dkr3d| }||fS |dkrZtd	d |D }|dkrN|}||fS |dkrVd| }||fS |d
krtdd |D }|d
krq|}||fS |dkr}d| }||fS |dkrtdd |D }tdd |D }	|}||	 }||fS |dkrtdd |D }|dkr|}||fS |dkrd| }||fS |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       | ]\}}}|V  qd S rP   r   .0whr   r   r   r   	<genexpr>      z5TickLabels._get_ticklabels_offsets.<locals>.<genexpr>r   g      ?r|   c                 s   r   rP   r   r   r   r   r   r     r   r~   c                 s       | ]\}}}|V  qd S rP   r   r   r   r   r   r     r   baselinec                 s       | ]
\}}}|| V  qd S rP   r   r   r   r   r   r         c                 s       | ]\}}}|V  qd S rP   r   r   r   r   r   r     r   r   c                 s   r   rP   r   r   r   r   r   r     r   c                 s   r   rP   r   r   r   r   r   r     r   c                 s   r   rP   r   r   r   r   r   r     r   )!get_texts_widths_heights_descentsget_vaget_hamax)
r   ri   r   whd_listr   r   r   r   
max_ascentmax_descentr   r   r   _get_ticklabels_offsets  sb   
#!
z"TickLabels._get_ticklabels_offsets)r   r|   )r   r}   )r   r   r   ry   ir   rT   c           	      C   s   |   s
| j| _d S | || j\}}| j||   }|| | _| jD ]$\\}}}}|	 s1q%|| _
| | | | | | t| | q%|| | _d S rP   )rU   r   r   r   r   r]   r   ru   _locs_angles_labelsstriprt   set_xset_yset_textrr   rp   )	r   ri   r   total_widthr   xyalr   r   r   rp     s"   



zTickLabels.drawc                 C   rO   rP   )r   )r   r*   r   r   r   set_locs_angles_labels$  r@   z!TickLabels.set_locs_angles_labelsNc                 C   s   |d u r| j dd }|  s| j| _g S g }| || j\}}| j||   }|| | _	| j
D ]$\\}}}}	|| _| | | | | |	 t| |}
||
 q3|| | _|S r   )r   r   rU   r   r   r   r   r]   r   ru   r   rt   r   r   r   rr   r   append)r   ri   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   _preprocess_mathget_text_width_height_descent_fontpropertiesr   )	r   ri   r   _loc_angler   
clean_liner   whdr   r   r   r   D  s   z,TickLabels.get_texts_widths_heights_descentsrP   )r   r    r!   rq   r-   r   r   r   r   r   r   r   rp   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majorboth)whichr$   c                   s,   || _ || _t j|i | | d dS )a   
        Collection of grid lines.

        Parameters
        ----------
        which : {"major", "minor"}
            Which grid to consider.
        axis : {"both", "x", "y"}
            Which axis to consider.
        *args, **kwargs
            Passed to `.LineCollection`.
        N)_whichr,   r   r-   set_grid_helper)r   r   r$   rx   r1   r   r   r   r-   V  s   zGridlinesCollection.__init__c                 C   rD   )z}
        Select major or minor grid lines.

        Parameters
        ----------
        which : {"major", "minor"}
        N)r   )r   r   r   r   r   	set_whichh     
zGridlinesCollection.set_whichc                 C   rD   )zg
        Select axis.

        Parameters
        ----------
        axis : {"both", "x", "y"}
        N)r,   )r   r$   r   r   r   set_axisr  r   zGridlinesCollection.set_axisc                 C   rD   )zz
        Set grid helper.

        Parameters
        ----------
        grid_helper : `.GridHelperBase` subclass
        N)_grid_helper)r   grid_helperr   r   r   r   |  r   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   )r`   	transpose)r   r   r   r   r   
<listcomp>  s    z,GridlinesCollection.draw.<locals>.<listcomp>)	r   
update_limrb   get_gridlinesr   r,   set_segmentsr   rp   )r   ri   glr   r   r   rp     s
   
zGridlinesCollection.draw)	r   r    r!   r-   r   r   r   rp   r"   r   r   r   r   r   U  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d@d"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d@d9d:Z e!j"d;d< Z#dAd=d>Z$  Z%S )B
AxisArtistz
    An artist which draws axis (a line along which the n-th axes coord
    is constant) line, ticks, tick labels, and axis label.
    g      @c                 C   s
   | j  S rP   )r   r   r   r   r   r   LABELPAD  rH   zAxisArtist.LABELPADc                 C      | j | d S rP   )r   r   )r   vr   r   r   r        Nr~   c                    s   t  jdi | || _|| _|du rd}tg |t d| jjddj R  | _	|dv r4|j
| _n|j| _d| _|| _|   | jdi | | | |   d| _d| _| | dS )	z
        Parameters
        ----------
        axes : `mpl_toolkits.axisartist.axislines.Axes`
        helper : `~mpl_toolkits.axisartist.axislines.AxisArtistHelper`
        Nr   gqq?Fr   )r}   r|   r(   r   )r   r-   rb   _axis_artist_helperr   r	   r\   r   dpi_scale_transoffset_transformyaxisr$   xaxis_axisline_styler   
_init_line_init_ticks_init_offsetText_init_label_ticklabel_add_angle_axislabel_add_angler   )r   rb   helperoffsetr   r1   r   r   r   r-     s0   



zAxisArtist.__init__c                 C   sV   | j | | j| || _|dv r| d | d dS | d | d dS )a  
        Adjust the direction, text angle, and text alignment of tick labels
        and axis 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
        =====================    ========== ========= ========== ==========
        ticklabel direction      "-"        "+"       "+"        "-"
        axislabel direction      "-"        "+"       "+"        "-"
        ticklabel 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.

        Parameters
        ----------
        axis_direction : {"left", "bottom", "right", "top"}
        )r}   r   -+N)major_ticklabelsr   r   r   set_ticklabel_directionset_axislabel_direction)r   r   r   r   r   r     s   

zAxisArtist.set_axis_directionc                 C      t jddd|d| _dS )z
        Adjust the direction of the tick labels.

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

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

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

        Parameters
        ----------
        label_direction : {"+", "-"}
        r   rT   r  )r   N)r   r   r  r   r   r   r   r    r  z"AxisArtist.set_axislabel_directionc                 C   s   | j j| j S rP   )rb   	transAxesr  r   r   r   r   r[     s   zAxisArtist.get_transformc                 C   rI   )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   pprint_styles
isinstance_Baser  r  )r   axisline_styler1   r   r   r   set_axisline_style  s   zAxisArtist.set_axisline_stylec                 C   rI   )z"Return the current axisline style.)r  r   r   r   r   get_axisline_style?  rK   zAxisArtist.get_axisline_stylec              	   C   st   | j | j| j }|  }|du r1t| j | jtjd dtjd tjd tjd |d| _	dS || |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%   fill	linewidthcapstyle	joinstyle	transform)r'  )
r  get_line_transformrb   r  r"  r   get_linemplrcParamsline)r   tranr   r   r   r   r  C  s   	zAxisArtist._init_linec                 C   sD   | j | j| j |  d ur| j | j  | j 	| d S rP   )
r,  set_pathr  r)  rb   r"  set_line_mutation_scaler  get_sizerp   r   r   r   r   
_draw_lineW  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d|||d	tj	| d
 d| _t| j | j| jjdd|||dtj	| d d| _d S )Nmajor_tick_sizeztick.major.size)r$   r'  minor_tick_sizeztick.minor.sizeztick.labelsizeFr   major_tick_padztick.major.pad)r$   r   figurer'  fontsizer   minor_tick_padztick.minor.pad)r$   	axis_namer  get_tick_transformrb   r  r#   getr*  r+  major_ticksminor_ticksr   r   r   r  r  )r   r1   r8  transsizer   r   r   r  ]  sN   	zAxisArtist._init_ticksc                 C   s~   g }g }| j }|D ]1\}}}}|d | }	d|	| d   kr#dkr'n 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.
        ry   r  i  rT   )r  r   )r   	tick_iterticks_loc_angleticklabels_loc_angle_labelticklabel_add_anglerm   angle_normalangle_tangentr   angle_label
angle_tickr   r   r   _get_tick_info  s    zAxisArtist._get_tick_infoc                 C   s   |d u r| j dd }|d}| j r*| j r*| jj| }|| j_|| j	_nd| j_d| j	_| j
| j\}}| |\}}| j| | j| | |\}}| j| | j	| d S )NTr   rS   r   )r   r   r]   r;  rU   rJ   r)   r  r   r  r  get_tick_iteratorsrb   rG  rR   r   r<  )r   ri   dpi_corticklabel_padmajortick_iterminortick_itertick_loc_angleticklabel_loc_angle_labelr   r   r   _update_ticks  s&   

zAxisArtist._update_ticksc                 C   s`   |  | | j| | j| | j| | j| | j s'| j r.| | d S d S rP   )rO  r;  rp   r  r<  r  rU   _draw_offsetTextr   r   r   r   _draw_ticks  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)xyxycoordsxytext
textcoordsr%   horizontalalignmentverticalalignment)
_offsetText_posmtext
Annotationr*  r+  
offsetTextr   r   rb   _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   	formatter
get_offsetset_sizer  r0  r   xyann)r   r  r   r   r   _update_offsetText  s   zAxisArtist._update_offsetTextc                 C   s   |    | j| d S rP   )rd  r\  rp   r   r   r   r   rP    s   zAxisArtist._draw_offsetTextc                 K   sz   | j | j| j }tdddd|dtjd tjd | j|| j	d	| _
| j
| jjdd	 |d
d}| j
| d S )Nr   r   r   	labelsizezaxes.labelsizezaxes.labelweight)r%   r6  
fontweightr$   r'  r   Fr   labelpadr   )r  get_axislabel_transformrb   r  r   r:  r*  r+  r$   r   r   
set_figurer   r   )r   r1   r   rg  r   r   r   r
    s   	zAxisArtist._init_labelc                 C   s   | j  sd S | j| jkr)| j r| j r!| j r&| j s&| jj}nd}n	t| j	j
| jj
}|| j _| j| j\}}|d u rEd S |d }|\}}|| j | j _| j j||d d S )Nr   ry   )r   r   )r   rU   r  r  r;  rJ   r<  r)   r   r  r   r  r   r  get_axislabel_pos_anglerb   rt   set)r   ri   axislabel_padrS  rD  rE  r   r   r   r   r   _update_label  s0   


zAxisArtist._update_labelc                 C   s   |  | | j| d S rP   )rm  r   rp   r   r   r   r   _draw_label	  s   
zAxisArtist._draw_labelc                 C   r   rP   )r   r   )r   sr   r   r   	set_label  r   zAxisArtist.set_labelc                 C   s   |   sd S | j| j | | | | | j| j| j | 	 d ur1| j
| j  g | j|| j|| j|| j|| j|}dd |D }|rat|}|S d S )Nc                 S   s(   g | ]}|r|j d ks|jd kr|qS )r   )widthheight)r   rG   r   r   r   r   #  s   ( z,AxisArtist.get_tightbbox.<locals>.<listcomp>)rU   r  r   rb   rO  rm  r,  r.  r)  r"  r/  r  r0  r   r  r   r   r\  r
   union)r   ri   r   _bboxr   r   r   get_tightbbox  s0   







zAxisArtist.get_tightbboxc                 C   sX   |   sd S |jt|  d | j| j | | | | | 	| |
t d S )N)gid)rU   
open_groupr   get_gidr  r   rb   rQ  r1  rn  close_groupr   r   r   r   rp   *  s   


zAxisArtist.drawc                 C   s   |rd\}}}n|durd\}}}nd\}}}|dur|}|dur#|}|dur)|}|dur9| j | | j| |durI| j| | j| |durU| j| dS 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;  set_visibler<  r  r  r   )r   allticks
ticklabelsr   _ticks_ticklabels_labelr   r   r   toggle6  s(   
zAxisArtist.toggle)Nr~   rP   )NNNN)&r   r    r!   rq   zorderr   r   setterr-   r   r  r  r  r[   r  r!  r"  r  r1  r  rG  rO  rQ  r   rY  r	  rd  rP  r
  rm  rn  rp  ru  martistallow_rasterizationrp   r  r"   r   r   r   r   r     sP    

.(
!%



r   )*rq   operatorr   numpyr`   
matplotlibr*  r   r   matplotlib.artistartistr  matplotlib.colorscolorsr7   matplotlib.texttextrZ  matplotlib.collectionsr   matplotlib.linesr   matplotlib.patchesr   matplotlib.pathr   matplotlib.transformsr	   r
   r   r   r   r   r   r#   Textrr   r   r   r   Artistr   r   r   r   r   <module>   s.    I`H  @9