3
#ßL]‚¬  ã               @   s:  d Z ddlZddlmZmZ ddljZddl	j
Zddlj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mZ d	d
lmZ G dd„ deƒZejdƒG dd„ deƒƒZ G dd„ de!ƒ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&e"ƒZ'G dd„ deƒZ(G dd„ dejƒZ)dS )ar  
axis_artist.py module provides axis-related artists. They are

* axis line
* tick lines
* tick labels
* axis label
* grid lines

The main artist classes are `AxisArtist` and `GridlinesCollection`. While
`GridlinesCollection` is responsible for drawing grid lines, `AxisArtist`
is responsible for all other artists. `AxisArtist` has attributes that are
associated with each type of artists:

* line: axis line
* major_ticks: major tick lines
* major_ticklabels: major tick labels
* minor_ticks: minor tick lines
* minor_ticklabels: minor tick labels
* label: axis label

Typically, the `AxisArtist` associated with an axes will be accessed with the
*axis* dictionary of the axes, i.e., the `AxisArtist` for the bottom axis is ::

  ax.axis["bottom"]

where *ax* is an instance of `mpl_toolkits.axislines.Axes`.  Thus,
``ax.axis["bottom"].line`` is an artist associated with the axis line, and
``ax.axis["bottom"].major_ticks`` is an artist associated with the major tick
lines.

You can change the colors, fonts, line widths, etc. of these artists
by calling suitable set method. For example, to change the color of the major
ticks of the bottom axis to red, use ::

  ax.axis["bottom"].major_ticks.set_color("r")

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_ticks_out(True)

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

* `Ticks`: ticksize, tick_out
* `TickLabels`: pad
* `AxisLabel`: pad
é    N)ÚcbookÚrcParams)ÚArtist)ÚLineCollection)ÚLine2D)ÚPath)ÚAffine2DÚBboxÚIdentityTransformÚScaledTranslationÚTransformedPathé   )ÚAxislineStylec               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú
BezierPathc             O   s&   t j| g g f|ž|Ž || _d| _d S )NF)r   Ú__init__Ú_pathÚ_invalid)ÚselfÚpathÚargsÚkwargs© r   úK/tmp/pip-install-edjban26/matplotlib/mpl_toolkits/axisartist/axis_artist.pyr   l   s    zBezierPath.__init__c             C   s   t | j| jƒ ƒ| _d| _d S )NF)r   r   Úget_transformÚ_transformed_pathr   )r   r   r   r   Úrecacheq   s    zBezierPath.recachec             C   s   || _ d| _d S )NT)r   r   )r   r   r   r   r   Úset_pathv   s    zBezierPath.set_pathc             C   sð   | j r| jƒ  | jsd S |jdƒ |jƒ }| j|ƒ |j| jƒ |j| j	ƒ |j
| jƒ |j| jƒ | jƒ rz| j}| j}n| j}| j}|j|ƒ |j|ƒ |j| j| jƒ | j| j dkrÚ| jjƒ \}}|j|||jƒ ƒ |jƒ  |jdƒ d S )NZline2dZ_draw_nothing) r   r   Z_visibleÚ
open_groupÚnew_gcZ_set_gc_clipÚset_foregroundZ_colorZset_antialiasedZ_antialiasedÚset_linewidthZ
_linewidthÚ	set_alphaÚ_alphaZ	is_dashedZ_dashcapstyleZ_dashjoinstyleZ_solidcapstyleZ_solidjoinstyleZset_joinstyleZset_capstyleZ
set_dashesZ_dashOffsetZ_dashSeqZ_lineStylesZ
_linestyler   Zget_transformed_path_and_affineZ	draw_pathÚfrozenÚrestoreÚclose_group)r   ÚrendererÚgcÚcapÚjoinZtpathZaffiner   r   r   Údrawz   s0    



zBezierPath.drawN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r*   r   r   r   r   r   j   s   r   z3.1c               @   s   e Zd ZdS )ÚUnimplementedExceptionN)r+   r,   r-   r   r   r   r   r.   œ   s   r.   c                   s8   e Zd Zef‡ fdd„	Zdd„ Zdd„ Zdd„ Z‡  ZS )	ÚAttributeCopierc                s   || _ || _tƒ jƒ  d S )N)Ú_klassÚ_ref_artistÚsuperr   )r   Ú
ref_artistÚklass)Ú	__class__r   r   r   ¢   s    zAttributeCopier.__init__c             C   s
   || _ d S )N)r1   )r   Úartistr   r   r   Úset_ref_artist§   s    zAttributeCopier.set_ref_artistc             C   s   t dƒ‚d S )Nzget_ref_artist must overridden)ÚRuntimeError)r   r   r   r   Úget_ref_artistª   s    zAttributeCopier.get_ref_artistc             C   sD   d| }t | j|ƒ| ƒ}|dkr@| jƒ }|r<t ||ƒƒ }|S |S |S )NÚget_Úauto)Úgetattrr0   r9   )r   Ú	attr_nameÚdefault_valueZget_attr_method_nameÚcr3   Úattrr   r   r   Úget_attribute_from_ref_artist®   s    z-AttributeCopier.get_attribute_from_ref_artist)	r+   r,   r-   r   r   r7   r9   rA   Ú__classcell__r   r   )r5   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   s„   || _ g | _| j|ƒ || _| jd k	rNd|kr6d|d< d|krNd|krNd|d< tj| dgdgf|Ž tj| | jtd� | jdƒ d S )NÚcolorr;   ZmewÚmarkeredgewidthg        )r4   T)Ú	_ticksizeÚlocs_angles_labelsÚset_tick_outÚ_axisr   r   r/   Zset_snap)r   ÚticksizeZtick_outrD   r   r   r   r   r   È   s    

zTicks.__init__c             C   s   | j jd jS )Nr   )r1   Z
majorTicksZ	tick1line)r   r   r   r   r9   Ù   s    zTicks.get_ref_artistc             C   s   | j ddƒS )NrE   Úk)rA   )r   r   r   r   Ú	get_colorÜ   s    zTicks.get_colorc             C   s   | j dkr| jƒ S | j S d S )Nr;   )Z_markeredgecolorrM   )r   r   r   r   Úget_markeredgecolorß   s    
zTicks.get_markeredgecolorc             C   s   | j ddƒS )NrF   g      à?)rA   )r   r   r   r   Úget_markeredgewidthå   s    zTicks.get_markeredgewidthc             C   s
   || _ dS )zD
        set True if tick need to be rotated by 180 degree.
        N)Ú	_tick_out)r   Úbr   r   r   rI   è   s    zTicks.set_tick_outc             C   s   | j S )zH
        Return True if the tick will be rotated by 180 degree.
        )rP   )r   r   r   r   Úget_tick_outî   s    zTicks.get_tick_outc             C   s
   || _ dS )z4
        set length of the ticks in points.
        N)rG   )r   rK   r   r   r   Úset_ticksizeô   s    zTicks.set_ticksizec             C   s   | j S )z7
        Return length of the ticks in points.
        )rG   )r   r   r   r   Úget_ticksizeú   s    zTicks.get_ticksizec             C   s
   || _ d S )N)Úlocs_angles)r   rU   r   r   r   Úset_locs_angles   s    zTicks.set_locs_anglesc             C   s   d S )Nr   )r   r&   r   r   r   Ú_update  s    zTicks._updateg        g      ð?c             C   s  | j ƒ sd S | j|ƒ | j}| jƒ }|jƒ }|j| jƒ ƒ |j| jƒ ƒ |j	| j
ƒ |j|ƒ}tƒ j||ƒ}| jƒ rzd}nd}tƒ }|| }	xn| jD ]d\}
}|jƒ j|| ƒ |jtj|
gƒƒ}| jrÜ| jjj|d Ž  rÜq”|j|| j|	t|ƒ|jƒ ƒ q”W |jƒ  d S )Né´   r   )Úget_visiblerW   rG   r   r   r   rN   r    rO   r!   r"   Úpoints_to_pixelsr   ÚscalerR   rU   ÚclearZ
rotate_degZtransform_non_affineÚnpÚarrayÚaxesZviewLimÚcontainsZdraw_markersÚ_tickvert_pathr   Z
get_affiner$   )r   r&   ÚsizeZ
path_transr'   ÚoffsetZmarker_scaleZ	add_angleZmarker_rotationZmarker_transformÚlocZangleZlocsr   r   r   r*     s0    

z
Ticks.draw)F)r+   r,   r-   Ú__doc__r   r9   rM   rN   rO   rI   rR   rS   rT   rV   rW   r   ra   r*   r   r   r   r   rC   ½   s   	rC   c                   s€   e 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dddœjZdd„ Z‡ fdd„Z‡ 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                s4   g | _ d| _d| _tƒ j||Ž | jdƒ d| _d S )Nr   g        ÚanchorT)rH   Ú
_ref_angleÚ_offset_radiusr2   r   Zset_rotation_modeÚ_text_follow_ref_angle)r   r   r   )r5   r   r   r   3  s    
zLabelBase.__init__c             C   s
   || _ d S )N)rh   )r   Úar   r   r   Ú_set_ref_angle=  s    zLabelBase._set_ref_anglec             C   s   | j S )N)rh   )r   r   r   r   Ú_get_ref_angle@  s    zLabelBase._get_ref_anglec             C   s   | j r| jƒ d S dS d S )NéZ   r   )rj   rm   )r   r   r   r   Ú_get_text_ref_angleC  s    zLabelBase._get_text_ref_anglec             C   s   | j ƒ S )N)rm   )r   r   r   r   Ú_get_offset_ref_angleI  s    zLabelBase._get_offset_ref_anglec             C   s
   || _ d S )N)ri   )r   Zoffset_radiusr   r   r   Ú_set_offset_radiusL  s    zLabelBase._set_offset_radiusc             C   s   | j S )N)ri   )r   r   r   r   Ú_get_offset_radiusO  s    zLabelBase._get_offset_radiusÚrightÚleftÚbottomÚtop)rt   rs   rv   ru   c             C   s   d S )Nr   )r   r&   r   r   r   rW   W  s    zLabelBase._updatec                sÄ   | j ƒ sd S | j|ƒ | jƒ }| jƒ }tƒ }| j|| ƒ | jƒ }| jƒ }|d tj	 }| j
ƒ }|tj|ƒ |tj|ƒ  }	}
|j|	|
ƒ | j|| ƒ tƒ j|ƒ |jƒ  | j|ƒ | j|ƒ d S )Ng     €f@)rY   rW   r   Úget_rotationr   Úset_transformro   rp   r]   Úpirr   ÚcosÚsinÚ	translateÚset_rotationr2   r*   r\   )r   r&   ÚtrÚ
angle_origÚ	offset_trÚtext_ref_angleÚoffset_ref_angleÚthetaÚddÚdxÚdy)r5   r   r   r*   Z  s$    

zLabelBase.drawc                s¼   | j |ƒ | jƒ }| jƒ }tƒ }| j|| ƒ | jƒ }| jƒ }|d tj }| j	ƒ }|tj
|ƒ |tj|ƒ  }	}
|j|	|
ƒ | j|| ƒ tƒ j|ƒjƒ }|jƒ  | j|ƒ | j|ƒ |S )Ng     €f@)rW   r   rw   r   rx   ro   rp   r]   ry   rr   rz   r{   r|   r}   r2   Úget_window_extentr#   r\   )r   r&   r~   r   r€   r�   r‚   rƒ   r„   r…   r†   Zbbox)r5   r   r   r‡   v  s"    


zLabelBase.get_window_extent)r+   r,   r-   re   r   rl   rm   ro   rp   rq   rr   Ú__getitem__Ú_get_opposite_directionrW   r*   r‡   rB   r   r   )r5   r   rf   ,  s   

rf   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	‡ 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‡ 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.
    ru   N)Úaxis_directionrD   c            O   sD   || _ tj| f|ž|Ž tj| | j td� | j|ƒ d| _d| _d S )N)r4   é   r   )rJ   rf   r   r/   Úset_axis_directionÚ_padÚ
_extra_pad)r   r‹   rD   r   r   r   r   r   r   �  s    
zAxisLabel.__init__c             C   s
   || _ dS )zã
        Set the pad in points. Note that the actual pad will be the
        sum of the internal pad and the external pad (that are set
        automatically by the AxisArtist), and it only set the internal
        pad
        N)rŽ   )r   Úpadr   r   r   Úset_pad§  s    zAxisLabel.set_padc             C   s   | j S )zE
        return pad in points. See set_pad for more details.
        )rŽ   )r   r   r   r   Úget_pad°  s    zAxisLabel.get_padc             C   s
   || _ dS )zq
        Set external pad IN PIXELS. This is intended to be set by the
        AxisArtist, bot by user..
        N)r�   )r   Úpr   r   r   Ú_set_external_pad¶  s    zAxisLabel._set_external_padc             C   s   | j S )z#
        Get external pad.
        )r�   )r   r   r   r   Ú_get_external_pad½  s    zAxisLabel._get_external_padc             C   s
   | j jƒ S )N)rJ   Ú	get_label)r   r   r   r   r9   Ã  s    zAxisLabel.get_ref_artistc                s&   t ƒ jƒ }|dkr | jjƒ jƒ S | jS )NÚ__from_axes__)r2   Úget_textrJ   r–   Z_text)r   Út)r5   r   r   r˜   Æ  s    
zAxisLabel.get_textÚcenterrv   )rt   rs   ru   rv   c             C   s<   t jddddg|d� | j| \}}| j|ƒ | j|ƒ d S )Nrt   rs   rv   ru   )Úd)r   Ú_check_in_listÚ_default_alignmentsZset_vaZset_ha)r   r›   ÚvaÚhar   r   r   Úset_default_alignmentÑ  s    
zAxisLabel.set_default_alignmentrX   r   c             C   s*   t jddddg|d� | j| j| ƒ d S )Nrt   rs   rv   ru   )r›   )r   rœ   r}   Ú_default_angles)r   r›   r   r   r   Úset_default_angleÜ  s    zAxisLabel.set_default_anglec             C   s.   t jddddg|d� | j|ƒ | j|ƒ 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.

        rt   rs   rv   ru   )r›   N)r   rœ   r    r¢   )r   r›   r   r   r   r�   à  s    
zAxisLabel.set_axis_directionc             C   s   | j ddƒS )NrE   rL   )rA   )r   r   r   r   rM   ÷  s    zAxisLabel.get_colorc                s@   | j ƒ sd S |j| jƒ ƒ}| jƒ | }| j|ƒ tƒ j|ƒ d S )N)rY   rZ   r’   r•   rq   r2   r*   )r   r&   r�   Úr)r5   r   r   r*   ú  s    
zAxisLabel.drawc                s@   | j ƒ sd S |j| jƒ ƒ}| jƒ | }| j|ƒ tƒ j|ƒ}|S )N)rY   rZ   r’   r•   rq   r2   r‡   )r   r&   r�   r£   Úbb)r5   r   r   r‡     s    
zAxisLabel.get_window_extent)ru   rš   )rv   rš   )rv   rš   )ru   rš   )r+   r,   r-   re   r   r‘   r’   r”   r•   r9   r˜   Údictr�   r    r¡   r¢   r�   rM   r*   r‡   rB   r   r   )r5   r   rŠ   ”  s,   
	
rŠ   c               @   s~   e Zd ZdZddœ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„ Zdd„ Zd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.
    ru   )r‹   c            K   s"   t j| f|Ž | j|ƒ d| _d S )Nr   )rŠ   r   r�   Ú_axislabel_pad)r   r‹   r   r   r   r   r     s    
zTickLabels.__init__c             C   s   | j jƒ d S )Nr   )rJ   Zget_ticklabels)r   r   r   r   r9   #  s    zTickLabels.get_ref_artistc             C   s4   t jddddg|d� || _| j|ƒ | j|ƒ 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.
        rt   rs   rv   ru   )Úlabel_directionN)r   rœ   Ú_axis_directionr    r¢   )r   r¨   r   r   r   r�   &  s
    
zTickLabels.set_axis_directionc             C   s   | j | jƒ}| j|ƒ d S )N)r‰   r©   r�   )r   r¨   r   r   r   Úinvert_axis_direction?  s    z TickLabels.invert_axis_directionc       
      C   s˜  | j |ƒ}|sdS d}| jƒ | jƒ  }}|dkrdtdd„ |D ƒƒ}|dkrP|}n|dkr`d| }�n,|dkržtdd„ |D ƒƒ}|dkrŒ|}n|dkrœd| }nò|d	k�rtd
d„ |D ƒƒ}|d	krÈ|}nL|dkrÚd| }n:|dk�r�tdd„ |D ƒƒ}tdd„ |D ƒƒ}	|}||	 }nz|dk�r�tdd„ |D ƒƒ}|dk�rB|}nN|dk�rVd| }n:|dk�r�tdd„ |D ƒƒ}tdd„ |D ƒƒ}	|	}||	 }||fS )aA  
        Calculates 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   rt   c             s   s   | ]\}}}|V  qd S )Nr   )Ú.0ÚwÚhr›   r   r   r   ú	<genexpr>T  s    z5TickLabels._get_ticklabels_offsets.<locals>.<genexpr>rš   g      à?rs   c             s   s   | ]\}}}|V  qd S )Nr   )r«   r¬   r­   r›   r   r   r   r®   Z  s    ru   c             s   s   | ]\}}}|V  qd S )Nr   )r«   r¬   r­   r›   r   r   r   r®   `  s    Úbaselinec             s   s   | ]\}}}|| V  qd S )Nr   )r«   r¬   r­   r›   r   r   r   r®   f  s    c             s   s   | ]\}}}|V  qd S )Nr   )r«   r¬   r­   r›   r   r   r   r®   g  s    rv   c             s   s   | ]\}}}|V  qd S )Nr   )r«   r¬   r­   r›   r   r   r   r®   k  s    c             s   s   | ]\}}}|| V  qd S )Nr   )r«   r¬   r­   r›   r   r   r   r®   q  s    c             s   s   | ]\}}}|V  qd S )Nr   )r«   r¬   r­   r›   r   r   r   r®   r  s    )r   r   )Ú!get_texts_widths_heights_descentsZget_vaZget_haÚmax)
r   r&   r¨   Úwhd_listr£   rž   rŸ   r�   Z
max_ascentZmax_descentr   r   r   Ú_get_ticklabels_offsetsC  sP    










z"TickLabels._get_ticklabels_offsetsrš   rs   rt   r¯   )rt   rs   ru   rv   rn   r   rX   c       	      C   s²   | j ƒ s| jƒ | _d S | j|| jƒ\}}| jƒ |j| jƒ ƒ }| j|| ƒ xV| jD ]L\\}}}}|j	ƒ slqT| j
|ƒ | j|ƒ | j|ƒ | j|ƒ tj| |ƒ qTW || | _d S )N)rY   r•   r§   r³   r©   rZ   r’   rq   Ú_locs_angles_labelsÚstriprl   Úset_xÚset_yÚset_textrf   r*   )	r   r&   r£   Útotal_widthr�   ÚxÚyrk   Úlr   r   r   r*   …  s"    




zTickLabels.drawc             C   s
   || _ d S )N)r´   )r   rH   r   r   r   Úset_locs_angles_labels�  s    z!TickLabels.set_locs_angles_labelsc             C   s¶   | j ƒ s| jƒ | _g S g }| j|| jƒ\}}| jƒ |j| jƒ ƒ }| j|| ƒ xV| jD ]L\\}}}}	| j	|ƒ | j
|ƒ | j|ƒ | j|	ƒ tj| |ƒ}
|j|
ƒ qXW || | _|S )N)rY   r•   r§   r³   r©   rZ   r’   rq   r´   rl   r¶   r·   r¸   rf   r‡   Úappend)r   r&   Zbboxesr£   r¹   r�   rº   r»   rk   r¼   r¤   r   r   r   Úget_window_extents   s$    





zTickLabels.get_window_extentsc       
      C   sV   g }xL| j D ]B\\}}}}|jƒ s$q| j|ƒ\}}|j|| j|d�}	|j|	ƒ qW |S )zI
        return a list of width, height, descent for ticklabels.
        )Úismath)r´   rµ   Z_preprocess_mathZget_text_width_height_descentZ_fontpropertiesr¾   )
r   r&   r²   rº   r»   rk   r¼   Z
clean_linerÀ   Zwhdr   r   r   r°   ¼  s    z,TickLabels.get_texts_widths_heights_descentsN)rš   rs   )rš   rt   )r¯   rš   )r¯   rš   i¦ÿÿÿ)r+   r,   r-   re   r   r9   r�   rª   r³   r¥   r�   r¡   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)ÚwhichrD   c               s(   || _ || _tƒ j||Ž | jdƒ dS )zR
        *which* : "major" or "minor"
        *axis* : "both", "x" or "y"
        N)Ú_whichrJ   r2   r   Úset_grid_helper)r   rÃ   rD   r   r   )r5   r   r   r   Ì  s    zGridlinesCollection.__init__c             C   s
   || _ d S )N)rÄ   )r   rÃ   r   r   r   Ú	set_whichÖ  s    zGridlinesCollection.set_whichc             C   s
   || _ d S )N)rJ   )r   rD   r   r   r   Úset_axisÙ  s    zGridlinesCollection.set_axisc             C   s
   || _ d S )N)Ú_grid_helper)r   Zgrid_helperr   r   r   rÅ   Ü  s    z#GridlinesCollection.set_grid_helperc                s^   | j d k	rN| j j| jƒ | j j| j| jƒ}|rD| jdd„ |D ƒƒ n
| jg ƒ tƒ j|ƒ d S )Nc             S   s   g | ]}t j|ƒ‘qS r   )r]   Z	transpose)r«   r¼   r   r   r   ú
<listcomp>ä  s    z,GridlinesCollection.draw.<locals>.<listcomp>)	rÈ   Ú
update_limr_   Zget_gridlinesrÄ   rJ   Zset_segmentsr2   r*   )r   r&   Úgl)r5   r   r   r*   ß  s    

zGridlinesCollection.draw)	r+   r,   r-   r   rÆ   rÇ   rÅ   r*   rB   r   r   )r5   r   rÁ   Ë  s
   
rÁ   c                   s*  e Zd ZdZdZedd„ ƒZejdd„ ƒZdD‡ fdd	„	Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdEd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dFdGdHdId-�Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Z d<d=„ Z!d>d?„ Z"e#j$d@dA„ ƒZ%dJdBdC„Z&‡  Z'S )KÚ
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 jƒ S )N)Úlabelr’   )r   r   r   r   ÚLABELPADò  s    zAxisArtist.LABELPADc             C   s   | j j|ƒS )N)rÍ   r‘   )r   Úvr   r   r   rÎ   ö  s    Nru   c                sì   t ƒ jf |Ž || _|| _|dkr&d}tƒ | _t|d |d | jƒ| _d| _d| _	d| _
d| _d| _|dkrzd}|j| _nd}|j| _d| _|| _| jƒ  | j|f|Ž | j|ƒ | jƒ  | j| jƒ d	| _d
| _d| _d| _| j|ƒ dS )zP
        *axes* : axes
        *helper* : an AxisArtistHelper instance.
        Nr   r   Trt   rs   ZytickZxtickFg     €f@g        )r   r   )rt   rs   )r2   r   r_   Ú_axis_artist_helperr   Údpi_transformr   Úoffset_transformZ_label_visibleZ_majortick_visibleZ_majorticklabel_visibleZ_minortick_visibleZ_minorticklabel_visibleZyaxisrD   ÚxaxisÚ_axisline_styler©   Ú
_init_lineÚ_init_ticksÚ_init_offsetTextÚ_init_labelZ
set_zorderÚZORDERZ_rotate_label_along_lineZ_tick_add_angleÚ_ticklabel_add_angleÚ_axislabel_add_angler�   )r   r_   Úhelperrc   r‹   r   Ú	axis_name)r5   r   r   r   ú  s<    


zAxisArtist.__init__c             C   sj   t jddddg|d� || _|d	kr:| jdƒ | jdƒ n| jdƒ | jdƒ | jj|ƒ | jj|ƒ 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.
        rt   rs   rv   ru   )r‹   ú-ú+N)rt   rv   )r   rœ   r©   Úset_ticklabel_directionÚset_axislabel_directionÚmajor_ticklabelsr�   rÍ   )r   r‹   r   r   r   r�   2  s    


zAxisArtist.set_axis_directionc             C   s&   t jddg|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ß   rÞ   )Útick_directionr   rX   )rß   rÞ   N)r   rœ   rÚ   )r   rã   r   r   r   rà   X  s    z"AxisArtist.set_ticklabel_directionc             C   s(   | j d d | _ | jjƒ  | jjƒ  d S )NrX   ih  )rÚ   râ   rª   Úminor_ticklabels)r   r   r   r   Úinvert_ticklabel_directionf  s    
z%AxisArtist.invert_ticklabel_directionc             C   s&   t jddg|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
        ----------
        tick_direction : {"+", "-"}
        rß   rÞ   )r¨   r   rX   )rß   rÞ   N)r   rœ   rÛ   )r   r¨   r   r   r   rá   k  s    z"AxisArtist.set_axislabel_directionc             C   s   | j j| j S )N)r_   Z	transAxesrÒ   )r   r   r   r   r   y  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   s>   |dkrt jƒ S t|t jƒr$|| _nt |f|Ž| _| jƒ  dS )aÊ  
        Set the axisline style.

        *axisline_style* can be a string with axisline style name with optional
         comma-separated attributes. Alternatively, the attrs can
         be provided as keywords.

         set_axisline_style("->,size=1.5")
         set_axisline_style("->", size=1.5)

        Old attrs simply are forgotten.

        Without argument (or with arrowstyle=None), return
        available styles as a list of strings.
        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 )z4
        return the current axisline style.
        )rÔ   )r   r   r   r   Úget_axisline_style�  s    zAxisArtist.get_axisline_stylec             C   s\   | j j| jƒ| j }| jƒ }|dkrJt| j j| jƒtd td |d�| _n|| |d�| _dS )zY
        Initialize the *line* artist that is responsible to draw the axis line.
        Nzaxes.edgecolorzaxes.linewidth)rE   Z	linewidthÚ	transform)rë   )	rÐ   Zget_line_transformr_   rÒ   rê   r   Úget_liner   Úline)r   Ztranrè   r   r   r   rÕ   £  s    zAxisArtist._init_linec             C   sD   | j j| jj| jƒƒ | jƒ d k	r4| j j| jjƒ ƒ | j j	|ƒ d S )N)
rí   r   rÐ   rì   r_   rê   Zset_line_mutation_scalerâ   Úget_sizer*   )r   r&   r   r   r   Ú
_draw_line´  s    zAxisArtist._draw_linec       
      K   s&  | j j| jƒ| j }|jdt|› d� ƒ}|jdt|› d� ƒ}|jdt|› d� ƒ}|jdt|› d� ƒ}t|| j|d	�| _t|| j|d	�| _	|d
kr¢td }ntd }t
j|d�}	t|| j| jd�| _t|| j| jd�| _| jj| jj||	d� | jj|ƒ | jj| jj||	d� | jj|ƒ d S )NÚmajor_tick_sizez.major.sizeÚmajor_tick_padz
.major.padÚminor_tick_sizez.minor.sizeÚminor_tick_padz
.minor.pad)rD   rë   rÓ   zxtick.labelsizezytick.labelsize)rb   )rb   rD   r‹   )Úfigurerë   Úfontproperties)rÐ   Zget_tick_transformr_   rÒ   Úgetr   rC   rD   Úmajor_ticksÚminor_ticksÚfont_managerÚFontPropertiesr¦   r©   râ   rä   Úsetrô   r‘   )
r   rÝ   r   Ztransrð   rñ   rò   ró   rb   Ú	fontpropsr   r   r   rÖ   º  s@    


zAxisArtist._init_ticksc             C   s‚   g }g }| j }xj|D ]b\}}}}|d | }	d|	| d   koFdkn  rP|n|d }
|j||
gƒ |j||	|gƒ qW ||fS )z‹
        Returns a pair of:

        - list of locs and angles for ticks
        - list of locs, angles and labels for ticklabels.
        rn   ih  i  rX   )rÚ   r¾   )r   Z	tick_iterZticks_loc_angleZticklabels_loc_angle_labelZticklabel_add_anglerd   Zangle_normalÚangle_tangentrÍ   Úangle_labelZ
angle_tickr   r   r   Ú_get_tick_infoå  s    $zAxisArtist._get_tick_infoc             C   sÊ   |j dƒ}| jjƒ rH| jjƒ rH| jj| jj| ƒ | jj| jj| ƒ n| jjdƒ | jjdƒ | jj	| j
ƒ\}}| j|ƒ\}}| jj|ƒ | jj|ƒ | j|ƒ\}}| jj|ƒ | jj|ƒ | jj|ƒS )Ng      ð?r   )rZ   r÷   rY   rR   râ   r”   rG   rä   rÐ   Úget_tick_iteratorsr_   rÿ   rV   r½   rø   r¿   )r   r&   Údpi_corÚ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|ƒ | jj|ƒ | jj|ƒ | jjƒ sN| jjƒ rX| j|ƒ |S )N)r  r÷   r*   râ   rø   rä   rY   Ú_draw_offsetText)r   r&   Zextentsr   r   r   Ú_draw_ticks  s    



zAxisArtist._draw_ticksc             C   s  |j dƒ}| jjƒ rH| jjƒ rH| jj| jj| ƒ | jj| jj| ƒ n| jjdƒ | jjdƒ | jj	| j
ƒ\}}| j|ƒ\}}| jj|ƒ | jj|ƒ | jj|ƒ | jj|ƒ | j|ƒ\}}| jj|ƒ | jj|ƒ | jj|ƒ | jj|ƒ | jjƒ �s| jjƒ �r| j|ƒ | jj|ƒS )Ng      ð?r   )rZ   r÷   rY   rR   râ   r”   rG   rä   rÐ   r   r_   rÿ   rV   r½   r*   rø   r  r¿   )r   r&   r  r  r  r  r  r   r   r   Ú_draw_ticks2+  s.    

zAxisArtist._draw_ticks2r   r   rs   rt   rv   )rt   rs   ru   rv   c          
   C   sV   | j | \}}}}tjd||fdddtd ||d�| _| jjtƒ ƒ | jj| jƒ d S )NÚ zaxes fractionr   zoffset pointszxtick.color)ÚxyZxycoordsZxytextZ
textcoordsrE   ZhorizontalalignmentZverticalalignment)r   r   )	Ú_offsetText_posÚmtextZ
Annotationr   Ú
offsetTextrx   r
   r_   Z_set_artist_props)r   Ú	directionrº   r»   rž   rŸ   r   r   r   r×   Z  s    zAxisArtist._init_offsetTextc             C   sP   | j j| jjjjƒ ƒ | j j| jjƒ ƒ | jj	ƒ | jjƒ  d }d|f| j _
d S )Né   r   )r  r¸   rD   rÂ   Ú	formatterZ
get_offsetZset_sizerâ   rî   r’   Zxyann)r   rc   r   r   r   Ú_update_offsetTextf  s    zAxisArtist._update_offsetTextc             C   s   | j ƒ  | jj|ƒ d S )N)r  r  r*   )r   r&   r   r   r   r  n  s    zAxisArtist._draw_offsetTextc          
   K   s€   |j dtd ƒ}tj|td d�}| jj| jƒ| j }tdddd|| j	|| j
d�| _| jj| jjƒ |j d	d
ƒ}| jj|ƒ d S )NÚ	labelsizezaxes.labelsizezaxes.labelweight)rb   Úweightr   r—   r;   )rE   rõ   rD   rë   r‹   ÚlabelpadrŒ   )rö   r   rù   rú   rÐ   Zget_axislabel_transformr_   rÒ   rŠ   rD   r©   rÍ   Z
set_figurerô   r‘   )r   r   r  rü   r~   r  r   r   r   rØ   r  s    zAxisArtist._init_labelc             C   sÈ   | j jƒ sd S | j| jkrV| jjƒ r0| jjƒ  sF| jjƒ rP| jjƒ  rP| jj}qhd}nt| j	j
| jj
ƒ}| j j|ƒ | jj| jƒ\}}|d kr’d S |d }|\}}| j j|| j ƒ | j j||d� d S )Nr   rn   )rº   r»   )rÍ   rY   rÚ   rÛ   r÷   rR   rø   rG   r±   râ   r§   rä   r”   rÐ   Úget_axislabel_pos_angler_   rl   rû   )r   r&   Úaxislabel_padr  rý   rþ   rº   r»   r   r   r   Ú_update_labelˆ  s&    




zAxisArtist._update_labelc             C   s   | j |ƒ | jj|ƒ d S )N)r  rÍ   r*   )r   r&   r   r   r   Ú_draw_label¥  s    
zAxisArtist._draw_labelc       	      C   sê   | j jƒ sd S tjtd td d�}| j| jkrl| jjƒ rF| jjƒ  s\| j	jƒ rf| jjƒ  rf| jj
}q~d}nt| jj| jjƒ}| j j|ƒ | jj| jƒ\}}|d kr¨d S |d }|\}}| j j|| j ƒ | j j||d� | j j|ƒ d S )Nzaxes.labelsizezaxes.labelweight)rb   r  r   rn   )rº   r»   )rÍ   rY   rù   rú   r   rÚ   rÛ   r÷   rR   rø   rG   r±   râ   r§   rä   r”   rÐ   r  r_   rl   rû   r*   )	r   r&   rü   r  r  rý   rþ   rº   r»   r   r   r   Ú_draw_label2©  s.    




zAxisArtist._draw_label2c             C   s   | j j|ƒ d S )N)rÍ   r¸   )r   Úsr   r   r   Ú	set_labelË  s    zAxisArtist.set_labelc             C   s¾   | j ƒ sd S | jj| jƒ |jdƒ}| jjƒ j||ƒ g }| j|ƒ |j	| j
j|ƒƒ |j	| jj|ƒƒ | j|ƒ |j| jj|ƒƒ |j| jj|ƒƒ dd„ |D ƒ}|r¶tj|ƒ}|S d S d S )Ng      ð?c             S   s(   g | ] }|r|j d ks |jd kr|‘qS )r   )ÚwidthÚheight)r«   rQ   r   r   r   rÉ   ã  s    z,AxisArtist.get_tightbbox.<locals>.<listcomp>)rY   rÐ   rÊ   r_   rZ   rÑ   r\   r[   r  Úextendrâ   r¿   rä   r  r¾   rÍ   r‡   r  r	   Úunion)r   r&   r  r¤   Z_bboxr   r   r   Úget_tightbboxÎ  s"    



zAxisArtist.get_tightbboxc             C   sl   | j ƒ sdS |jtƒ | jj| jƒ |jdƒ}| jjƒ j	||ƒ | j
|ƒ | j|ƒ | j|ƒ |jtƒ dS )z*Draw the axis lines, tick lines and labelsNg      ð?)rY   r   r+   rÐ   rÊ   r_   rZ   rÑ   r\   r[   r  rï   r  r%   )r   r&   r  r   r   r   r*   ê  s    




zAxisArtist.drawc             C   sª   |rd\}}}n|dk	r$d\}}}n
d\}}}|dk	r:|}|dk	rF|}|dk	rR|}|dk	rr| j j|ƒ | jj|ƒ |dk	r’| jj|ƒ | jj|ƒ |dk	r¦| j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))

        TNF)TTT)FFF)NNN)r÷   Zset_visiblerø   râ   rä   rÍ   )r   ÚallZticksZ
ticklabelsrÍ   Z_ticksZ_ticklabelsZ_labelr   r   r   Útoggleþ  s&    
zAxisArtist.toggle)Nru   )N)r   r   ru   rs   )r   r   ru   rt   )r   r   rv   rs   )r   r   ru   rs   )NNNN)(r+   r,   r-   re   rÙ   ÚpropertyrÎ   Úsetterr   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!  ÚmartistZallow_rasterizationr*   r#  rB   r   r   )r5   r   rÌ   ê  sH    5&
+ *"rÌ   )*re   Znumpyr]   Z
matplotlibr   r   Zmatplotlib.artistr6   r&  Zmatplotlib.textÚtextr  Zmatplotlib.font_managerrù   r   Zmatplotlib.collectionsr   Zmatplotlib.linesr   Zmatplotlib.pathr   Zmatplotlib.transformsr   r	   r
   r   r   rè   r   r   Ú
deprecatedÚ	Exceptionr.   Úobjectr/   rC   ÚTextrf   rŠ   r¦   rÁ   rÌ   r   r   r   r   Ú<module>S   s,   


2oh} ;