a
    ضa\                     @   s  d dl mZ d dlZd dlZd dlZd dlmZ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 G dd dej Z!G dd	 d	ej"Z#G d
d dej Z$G dd dej%Z&G dd dZ'G dd dej(Z)G dd dej*Z+G dd dej,Z-G dd dej(Z.G dd dej/Z0G dd dej1Z2G dd dej3Z4dd Z5d d! Z6G d"d# d#ej7Z8G d$d% d%eZ9e!e9_!e#e9_#e$e9_$e&e9_&e.e9_.e)e9_)dS )&    )OrderedDictN)_apicbookrcParams)Axes)Pathc                       sR   e Zd ZdZd ZZd fdd	Zejddd	d
Z	dd Z
dd Zdd Z  ZS )PolarTransformz
    The base polar transform.  This handles projection *theta* and
    *r* into Cartesian coordinate space *x* and *y*, but does not
    perform the ultimate affine transformation into the correct
    position.
       NTc                    s    t    || _|| _|| _d S Nsuper__init___axis	_use_rmin_apply_theta_transformsselfaxisuse_rminr   	__class__ l/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/matplotlib/projections/polar.pyr      s    
zPolarTransform.__init__r   r   r   r   r   c                 C   s   t |\}}| jr:| jd ur:|| j 9 }|| j 7 }| jrb| jd urb|| j  | j  }t 	|dk|t j
}t |t | |t | gS Nr   )npZ	transposer   r   get_theta_directionget_theta_offsetr   get_rorigin	get_rsignwherenancolumn_stackcossin)r   trtrr   r   r   transform_non_affine'   s    z#PolarTransform.transform_non_affinec                 C   s  t |r|jdkr&t| |j|jS g }g }d  }}| D ]L\}}|d}|tjkr\|\\}}	||kr|	| | |
tj q|	|krt||g\}
}| jr| jd ur|	| j  | j  }	|
|krl||
 dkr2t|
|
d }|	|jdd  |	  |	|jdd   |
d7 }
qt|
|}|	|jdd  |	  |	|jdd   n|
| dkrt|
d |
}|	|jd d d dd  |	  |	|jdd   |
d8 }
qlt||
}|	|jd d d dd  |	  |	|jdd   nJtt||f|g|jdd  }|	| | |	tjgt |  n$|	| | |	|gt |  |d \}}q>t||S )N   )r	   h  r*   )lenZ_interpolation_stepsr   r(   ZverticescodesZiter_segmentsreshapeZLINETOextendappendr   rad2degr   r   r   r   arcr   Zsimple_linear_interpolationZ	row_stack)r   pathZxysr-   Zlast_tZlast_rZtrscr&   r'   Zlast_tdtdr2   r   r   r   transform_path_non_affine4   s^    




""z(PolarTransform.transform_path_non_affinec                 C   s   t | j| j| jS r
   )	PolarAxesInvertedPolarTransformr   r   r   r   r   r   r   invertedj   s    zPolarTransform.inverted)NTT)__name__
__module____qualname____doc__
input_dimsoutput_dimsr   mtransforms_make_str_method__str__r(   r6   r:   __classcell__r   r   r   r   r      s     6r   c                       s4   e Zd ZdZ fddZeddZdd Z  Z	S )PolarAffinez
    The affine part of the polar projection.  Scales the output so
    that maximum radius rests on the edge of the axes circle.
    c                    s,   t    || _|| _| || d| _dS )z
        *limits* is the view limit of the data.  The only part of
        its bounds that is used is the y limits (for the radius limits).
        The theta range is handled by the non-affine transform.
        N)r   r   _scale_transform_limitsset_children_mtx)r   Zscale_transformZlimitsr   r   r   r   u   s
    
zPolarAffine.__init__rF   rG   c                 C   sV   | j rP| j| j}|j|j }t d| 	dd}|
 | _d | _d| _ | jS )N      ?r   )_invalidrG   ZtransformedrF   ymaxyminrA   Affine2Dscale	translate
get_matrixrI   Z	_inverted)r   Zlimits_scaledZyscaleZaffiner   r   r   rQ      s    
zPolarAffine.get_matrix
r;   r<   r=   r>   r   rA   rB   rC   rQ   rD   r   r   r   r   rE   p   s   rE   c                       sJ   e Zd ZdZd ZZd fdd	Zejddd	d
Z	dd Z
dd Z  ZS )r8   zy
    The inverse of the polar transform, mapping Cartesian
    coordinate space *x* and *y* back to *theta* and *r*.
    r	   NTc                    s    t    || _|| _|| _d S r
   r   r   r   r   r   r      s    
zInvertedPolarTransform.__init__r   r   r   r   c                 C   s   |j \}}t||}t||dtj  dtj  }| jrp| jd urp|| j 8 }|| j 9 }|dtj ; }| j	r| jd ur|| j
 7 }|| j 9 }t||gS )Nr	   )Tr   hypotZarctan2pir   r   r   r   r   r   r   r"   )r   Zxyxyr'   thetar   r   r   r(      s    
 z+InvertedPolarTransform.transform_non_affinec                 C   s   t | j| j| jS r
   )r7   r   r   r   r   r9   r   r   r   r:      s    zInvertedPolarTransform.inverted)NTT)r;   r<   r=   r>   r?   r@   r   rA   rB   rC   r(   r:   rD   r   r   r   r   r8      s     r8   c                   @   s   e Zd ZdZdddZdS )ThetaFormatterz
    Used to format the *theta* tick labels.  Converts the native
    unit of radians into degrees and adds a degree symbol.
    Nc                 C   sN   | j  \}}tt|| }ttt|d  d}djt||dS )N      ?r   u   {value:0.{digits:d}f}°)valuedigits)	r   get_view_intervalr   r1   absmaxintlog10format)r   rV   posvminvmaxdr\   r   r   r   __call__   s    
zThetaFormatter.__call__)N)r;   r<   r=   r>   rg   r   r   r   r   rY      s   rY   c                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )_AxisWrapperc                 C   s
   || _ d S r
   )r   r   r   r   r   r   r      s    z_AxisWrapper.__init__c                 C   s   t | j S r
   )r   r1   r   r]   r9   r   r   r   r]      s    z_AxisWrapper.get_view_intervalc                 C   s   | j jt||f  d S r
   )r   set_view_intervalr   deg2radr   rd   re   r   r   r   rj      s    z_AxisWrapper.set_view_intervalc                 C   s   t | j S r
   )r   r1   r   
get_minposr9   r   r   r   rm      s    z_AxisWrapper.get_minposc                 C   s   t | j S r
   )r   r1   r   get_data_intervalr9   r   r   r   rn      s    z_AxisWrapper.get_data_intervalc                 C   s   | j jt||f  d S r
   )r   set_data_intervalr   rk   rl   r   r   r   ro      s    z_AxisWrapper.set_data_intervalc                 C   s
   | j  S r
   )r   get_tick_spacer9   r   r   r   rp      s    z_AxisWrapper.get_tick_spaceN)
r;   r<   r=   r   r]   rj   rm   rn   ro   rp   r   r   r   r   rh      s   rh   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )ThetaLocatorz
    Used to locate theta ticks.

    This will work the same as the base locator except in the case that the
    view spans the entire circle. In such cases, the previously used default
    locations of every 45 degrees are returned.
    c                 C   s    || _ t| j j | _| j _d S r
   )baserh   r   )r   rr   r   r   r   r      s    zThetaLocator.__init__c                 C   s   t || _| j| j d S r
   )rh   r   rr   set_axisri   r   r   r   rs      s    
zThetaLocator.set_axisc                 C   sF   | j  }t|d |d r4tdd tj d S t|  S d S )Nr   r)      r	   )r   r]   _is_full_circle_degr   ZarangerU   rk   rr   )r   Zlimr   r   r   rg      s    
zThetaLocator.__call__c                 C   s
   | j  S r
   )rr   refreshr9   r   r   r   rv      s    zThetaLocator.refreshc                 C   s&   t ||f\}}t | j||S r
   )r   r1   rk   rr   view_limitsrl   r   r   r   rw      s    zThetaLocator.view_limitsN)	r;   r<   r=   r>   r   rs   rg   rv   rw   r   r   r   r   rq      s   rq   c                       s@   e Zd ZdZ fddZ fddZdd Z fdd	Z  ZS )
	ThetaTicka  
    A theta-axis tick.

    This subclass of `.XTick` provides angular ticks with some small
    modification to their re-positioning such that ticks are rotated based on
    tick location. This results in ticks that are correctly perpendicular to
    the arc spine.

    When 'auto' rotation is enabled, labels are also rotated to be parallel to
    the spine. The label padding is also applied here since it's not possible
    to use a generic axes transform to produce tick-specific padding.
    c                    s~   t dd|jj| _t dd|jj| _t j|g|R i | | jj	d| j
 | j d | jj	d| j
 | j d d S )Nr   anchor)Zrotation_mode	transform)rA   ScaledTranslationfiguredpi_scale_trans_text1_translate_text2_translater   r   label1setget_transformlabel2)r   axesargskwargsr   r   r   r     s    

zThetaTick.__init__c                    sf   t  jf i | | j }|| js:| j|| j  | j }|| jsb| j|| j  d S r
   )	r   _apply_paramsr   r   Zcontains_branchr~   set_transformr   r   )r   kwtransr   r   r   r     s    

zThetaTick._apply_paramsc                 C   sX   |t | d }|t | d }||f| j_| j  | | f| j_| j  d S )NH   )r   r#   r$   r~   _t
invalidater   )r   padanglepadxpadyr   r   r   _update_padding*  s    
zThetaTick._update_paddingc           
         s  t  | | j}||  |  }t|d d }|tjd 8 }| j	 }|t
jdfv rvt dd|}n,|t
jkrt dd|}n
| jjj}|| jj_| j	 }|t
jdfv rt dd|}n,|t
jkrt dd|}n
| jjj}|| jj_| j\}}|dkr,|}n.|dkr@|d8 }n|d	k rR|d7 }||7 }| j| | j| | jd
 }	| |	| j|  |   d S )Nr+   Z   r	   |r)   r*   default      )r   update_positionr   r   r   r   r1   rU   	tick1line
get_markermmarkersZTICKUPrA   rN   rO   rotateZTICKDOWN_marker
_transform	tick2line_labelrotationr   set_rotationr   Z_padr   Z_loc)
r   locr   r   
text_anglemarkerr   mode
user_angler   r   r   r   r   2  sF    













zThetaTick.update_position)	r;   r<   r=   r>   r   r   r   r   rD   r   r   r   r   rx     s
   rx   c                       sf   e Zd ZdZdZ dZdd Zdd Z fdd	Zej	d
dddd Z
 fddZ fddZ  ZS )	ThetaAxisz
    A theta Axis.

    This overrides certain properties of an `.XAxis` to provide special-casing
    for an angular axis.
    Z	thetaaxisrX   c                 C   s*   |r| j }n| j}t| jdfd|i|S Nr   major)_major_tick_kw_minor_tick_kwrx   r   r   r   Ztick_kwr   r   r   	_get_tickk  s    zThetaAxis._get_tickc                 C   s.   |  t|   | t  d| _d| _d S NT)set_major_locatorrq   get_major_locatorset_major_formatterrY   isDefault_majlocZisDefault_majfmtr9   r   r   r   _wrap_locator_formatterr  s    z!ThetaAxis._wrap_locator_formatterc                    s    t    | d |   d S Nnoner   clearZset_ticks_positionr   r9   r   r   r   r   x  s    

zThetaAxis.clear3.4zThetaAxis.clear()alternativec                 C   s   |    d S r
   r   r9   r   r   r   cla}  s    zThetaAxis.clac                    sD   |dkrt dt j|fi | |  jg dd |   d S )NZlinearz(The xscale cannot be set on a polar plot)r)   rZ      g      @	   
   )Zsteps)NotImplementedErrorr   
_set_scaler   Z
set_paramsr   r   r[   r   r   r   r   r     s    zThetaAxis._set_scalec                    sb   |du s|du rdS t  || | d }|j||j  | d }|j||j  dS )z*Copy the props from src tick to dest tick.Nr   )	r   _copy_tick_propsZ_get_text1_transformr   r   r~   Z_get_text2_transformr   r   )r   srcdestr   r   r   r   r     s    zThetaAxis._copy_tick_props)r;   r<   r=   r>   	axis_namer   r   r   r   
deprecatedr   r   r   rD   r   r   r   r   r   a  s   
r   c                   @   s:   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZdS )RadialLocatorz
    Used to locate radius ticks.

    Ensures that all ticks are strictly positive.  For all other tasks, it
    delegates to the base `.Locator` (which may be different depending on the
    scale of the *r*-axis).
    Nc                 C   s   || _ || _d S r
   )rr   _axes)r   rr   r   r   r   r   r     s    zRadialLocator.__init__c                 C   s   | j | d S r
   )rr   rs   ri   r   r   r   rs     s    zRadialLocator.set_axisc                    sT   | j rLt| j jj rL| j  | j    | j   krL fdd|  D S |  S )Nc                    s   g | ]}| kr|qS r   r   ).0Ztickroriginr   r   
<listcomp>      z*RadialLocator.__call__.<locals>.<listcomp>)r   _is_full_circle_radviewLim	intervalxr   r   get_rminrr   r9   r   r   r   rg     s    zRadialLocator.__call__c                 C   s(   ||ft j t jfkrdS | j||S )Nr   r)   )r   infrr   nonsingularrl   r   r   r   r     s    zRadialLocator.nonsingularc                 C   s0   | j ||\}}||kr$td|}t||S r   )rr   rw   minrA   r   rl   r   r   r   rw     s    
zRadialLocator.view_limits)N)	r;   r<   r=   r>   r   rs   rg   r   rw   r   r   r   r   r     s   
	r   c                       s:   e Zd ZdZ fddZedddZ fddZ  Z	S )	_ThetaShifta  
    Apply a padding shift based on axes theta limits.

    This is used to create padding for radial ticks.

    Parameters
    ----------
    axes : `~matplotlib.axes.Axes`
        The owning axes; used to determine limits.
    pad : float
        The padding to apply, in points.
    mode : {'min', 'max', 'rlabel'}
        Whether to shift away from the start (``'min'``) or the end (``'max'``)
        of the axes, or using the rlabel position (``'rlabel'``).
    c                    s6   t  |||jj | |j || _|| _|| _d S r
   )	r   r   r|   r}   rH   _realViewLimr   r   r   )r   r   r   r   r   r   r   r     s
    z_ThetaShift.__init__r   r   r   c                    s   | j r| jdkr6t| j | j  | j  }n*| jdkrL| jjj	}n| jdkr`| jjj
}| jdv rt|tjd  }t|tjd  }n(t|tjd  }t|tjd  }| j| d | j| d f| _t  S )Nrlabelr   r_   )r   r   r	   r   )rK   r   r   rk   r   get_rlabel_positionr   r   r   xminxmaxr#   rU   r$   r   r   r   rQ   )r   r   r   r   r   r   r   rQ     s&    




z_ThetaShift.get_matrixrR   r   r   r   r   r     s   r   c                       s4   e Zd ZdZ fddZdd Z fddZ  ZS )
RadialTickaj  
    A radial-axis tick.

    This subclass of `.YTick` provides radial ticks with some small
    modification to their re-positioning such that ticks are rotated based on
    axes limits.  This results in ticks that are correctly perpendicular to
    the spine. Labels are also rotated to be perpendicular to the spine, when
    'auto' rotation is enabled.
    c                    s.   t  j|i | | jd | jd d S )Nry   )r   r   r   Zset_rotation_moder   r   r   r   r   r   r   r     s    zRadialTick.__init__c                 C   s,  |dkrP|r.d|  kr dkr(n ndS dS n d|  krBdkrJn ndS dS n|r|dk r`dS |dk rld	S |d
k rxdS |dk rdS |dk rdS |dk rdS |dk rdS |dk rdS dS nn|dk rdS |dk rdS |d
k rdS |dk  rdS |dk  rdS |dk rd	S |dk rdS |dk r$dS dS d S )Nautor   r   )leftcenter)rightr   g      Q)r   topg     7)r   r        6@g     P@)r   bottomg      \@)r   r   g     c@)r   r   g     Pi@g     n@)r   r   r   )r   r   r   startr   r   r   _determine_anchor  sV    




zRadialTick._determine_anchorc                    s  t  | | j}| }| }| }| }t|}t	||}|rh|
 | | d d }	d}
n6|| | d d }	|dkrt|	}
nt|	d }
|	d d d }| j\}}|dkr||7 }n|}|r| j }| j }n| ||	|dk\}}| j| | j| | j| | j }|tjkrHt |
}nR|dkrlt |
tjd  }n.|tjkrt dd	|
}n
| jjj}|| jj_|r| j !d
 | j"!d
 || | d d }	|dkrt|	}
nt|	d }
|	d d d }| j\}}|dkr(||7 }n|}| ||	|dk \}}| j #| | j $| | j | | j" }|tjkrt |
}nR|dkrt |
tjd  }n.|tjkrt dd	|
}n
| j"jj}|| j"j_d S )Nr+   r   r   r   r   _r	   r*   r)   F)%r   r   r   get_thetaminget_thetamaxr   r   r   r1   ru   r   rk   r   r   Zget_horizontalalignmentZget_verticalalignmentr   Zset_horizontalalignmentZset_verticalalignmentr   r   r   r   ZTICKLEFTrA   rN   r   rU   Z	TICKRIGHTrO   r   r   r   set_visibler   set_haset_va)r   r   r   thetaminthetamax	directionZ
offset_radoffsetfullr   Z
tick_angler   r   r   Zhavar   r   r   r   r   r   7  s    
















zRadialTick.update_position)r;   r<   r=   r>   r   r   r   rD   r   r   r   r   r     s   
6r   c                       sf   e Zd ZdZdZ dZ fddZdd Zdd	 Z fd
dZe	j
ddddd Z fddZ  ZS )
RadialAxisz~
    A radial Axis.

    This overrides certain properties of a `.YAxis` to provide special-casing
    for a radial axis.
    Z
radialaxisradiusc                    s$   t  j|i | | jjd d S r   )r   r   Zsticky_edgesrW   r0   r   r   r   r   r     s    zRadialAxis.__init__c                 C   s*   |r| j }n| j}t| jdfd|i|S r   )r   r   r   r   r   r   r   r   r     s    zRadialAxis._get_tickc                 C   s    |  t|  | j d| _d S r   )r   r   r   r   r   r9   r   r   r   r     s    z"RadialAxis._wrap_locator_formatterc                    s    t    | d |   d S r   r   r9   r   r   r   r     s    

zRadialAxis.clearr   zRadialAxis.clear()r   c                 C   s   |    d S r
   r   r9   r   r   r   r     s    zRadialAxis.clac                    s    t  j|fi | |   d S r
   )r   r   r   r   r   r   r   r     s    zRadialAxis._set_scale)r;   r<   r=   r>   r   r   r   r   r   r   r   r   r   rD   r   r   r   r   r     s   
r   c                 C   s   t t ||  d dk S )z
    Determine if a wedge (in degrees) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
         v@g-q=)r^   r   r   r   r   r   ru     s    ru   c                 C   s   t t ||  dtj  dk S )z
    Determine if a wedge (in radians) spans the full circle.

    The condition is derived from :class:`~matplotlib.patches.Wedge`.
    r	   g-5c5=)r^   r   rU   r   r   r   r   r     s    r   c                       s6   e Zd ZdZ fddZedddZdd Z  Z	S )	
_WedgeBboxav  
    Transform (theta, r) wedge Bbox into axes bounding box.

    Parameters
    ----------
    center : (float, float)
        Center of the wedge
    viewLim : `~matplotlib.transforms.Bbox`
        Bbox determining the boundaries of the wedge
    originLim : `~matplotlib.transforms.Bbox`
        Bbox determining the origin for the wedge, if different from *viewLim*
    c                    sB   t  jddgddggfi | || _|| _|| _| || d S )Nr   r)   )r   r   _center_viewLim
_originLimrH   )r   r   r   Z	originLimr   r   r   r   r     s
     z_WedgeBbox.__init__r   r   r   c           	      C   sT  | j rN| j  }|d d df  dtj 9  < |d |d krb|d d ddf |d d df< |d d df  | jj8  < d|d  }|d d df  |9  < t|d |d	  d}t	j
| j|d |d |d |d
}| |  | jd | jd  \}}t|| dd }t|| dd }|  jt| | g||gg7  _d| _ | jS )Nr   r   r   r   r)   r   r*   r)   rJ   )r)   r)   r   )widthr	   )rK   r   
get_pointscopyr   rU   r   y0r   mpatchesWedger   Zupdate_from_pathget_pathZ_pointsr_   array)	r   ZpointsZrscaler   ZwedgewhZdeltahZdeltawr   r   r   r     s(    $z_WedgeBbox.get_points)
r;   r<   r=   r>   r   rA   rB   rC   r   rD   r   r   r   r   r     s   r   c                       s  e Zd ZdZdZdddd fdd
Z fd	d
Zdd Zdd ZdiddZ	dd Z
dd ZdjddZdd Zdd Z fddZdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zdkd1d2Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Zd=d> Zd?d@ Z dAdB Z!dCdD Z"dldHdIZ#dmdEdEdJ fdKdLZ$dMdN Z%dOdP Z& fdQdRZ'dSdT Z(dUdV Z)dndWdXZ*dodYdZZ+d[d\ Z,d]d^ Z-d_d` Z.dadb Z/dcdd Z0dedf Z1dgdh Z2  Z3S )pr7   z
    A polar graph projection, where the input dimensions are *theta*, *r*.

    Theta starts pointing east and goes anti-clockwise.
    polarr   r)   r   )theta_offsettheta_directionrlabel_positionc                   sL   || _ || _t|| _t j|i | d| _| jdddd | 	  d S )NTequalZboxC)Z
adjustablery   )
_default_theta_offset_default_theta_directionr   rk   _default_rlabel_positionr   r   Zuse_sticky_edgesZ
set_aspectr   )r   r
  r  r  r   r   r   r   r   r     s    zPolarAxes.__init__c                    s   t    | jd | jdd }|r2|d | jdd }|rN|d | ddtj	  | 
td  | jdd }|r|d | d  | | j | | j d S )	Ng?r   Fend        r	   zpolaraxes.gridinner)r   r   titleZset_yspinesgetr   set_xlimr   rU   gridr   set_roriginset_theta_offsetr  set_theta_directionr  )r   r   r  r  r   r   r   r     s     




zPolarAxes.clac                 C   s    t | | _t| | _|   d S r
   )r   xaxisr   yaxisZ_update_transScaler9   r   r   r   
_init_axis$  s    

zPolarAxes._init_axisc                 C   s  t | j| _t  | jd| _t  | j	d| _
| j| j
 | _t | j| j| _t t  | _td| j| j| _t | j| _t | j| _| j| dd| _| j| j | | j| j| _| j| j | j | j| j | j  | _t t  t | j| j | _t  dddddd}|| j | _ t t | jt  | j | _!t  | j"d| _#t | j#| j | _$d S )	N      ?r  rJ   rJ   F)r   g      g      rJ   )%rA   ZLockableBboxr   _originViewLimrN   rO   r  
_directionrP   r  _theta_offsetZ
transShiftZTransformedBboxr   ZTransformWrapperZIdentityTransformZ
transScaler   ZaxesLimZBboxTransformFrom
transWedgeZBboxTransformToZbbox	transAxesr   ZtransProjectionrH   rE   ZtransProjectionAffine	transDataZblended_transform_factory_xaxis_transform_xaxis_text_transform_yaxis_transformr  _r_label_position_yaxis_text_transform)r   Zflipr_transformr   r   r   _set_lim_and_transforms.  sv    


z!PolarAxes._set_lim_and_transformsr  c                 C   s   t jg d|d | jS )Ntick1tick2r  which)r   check_in_listr(  r   r2  r   r   r   get_xaxis_transform  s    zPolarAxes.get_xaxis_transformc                 C   s   | j ddfS Nr   r)  r   r   r   r   r   get_xaxis_text1_transform  s    z#PolarAxes.get_xaxis_text1_transformc                 C   s   | j ddfS r6  r7  r8  r   r   r   get_xaxis_text2_transform  s    z#PolarAxes.get_xaxis_text2_transformc                 C   s2   |dv r| j S |dkr| jS tjg d|d d S )N)r/  r0  r  r.  r1  )r,  r*  r   r3  r4  r   r   r   get_yaxis_transform  s
    zPolarAxes.get_yaxis_transformc                 C   s`   | j j\}}t||r"| jddfS |  dkr@d}t| |d}nd}t| |d}| j| d|fS )Nr   r   r   r   r   r_   r   )r   r   r   r,  r   r   )r   r   r   r   halign	pad_shiftr   r   r   get_yaxis_text1_transform  s    
z#PolarAxes.get_yaxis_text1_transformc                 C   s>   |   dkrd}t| |d}nd}t| |d}| j| d|fS )Nr   r   r_   r   r   r   )r   r   r,  )r   r   r<  r=  r   r   r   get_yaxis_text2_transform  s    z#PolarAxes.get_yaxis_text2_transformc                    s  |    t| jj\}}||kr,|| }}| jj|   |   \}}t| j	t
jr| jd}| j	| | j	| | j	| | jd\}}||d  }	t|	||  | |	}
| j	|	 | j	|
 |	|
 }| jdd }|r||dk t|| }| jdd }| jdd }|r0|| |r@|| |rN| j}n| j| j }| j|kr| j| | j  | j| j	 t  !| d S )Nr!  r   r   r  r  r   r  )"Z_unstale_viewLimr   r1   r   r   Z	intervalyr   r   
isinstancepatchr  r  r%  rz   Z
set_centerZ
set_theta1Z
set_theta2r   Z
set_radiusZ	set_widthr  r  r   ru   r*  r+  r'  r,  r   r  Zreset_ticksZset_clip_pathr   draw)r   Zrendererr   r   rminrmaxr   Zedger   r   r   Zinner_widthr  Zvisibler   r  Zyaxis_text_transformr   r   r   rB    sH    



zPolarAxes.drawc                 C   s   t ddddS )Nr!  rJ   r  r   )r  r  r9   r   r   r   _gen_axes_patch  s    zPolarAxes._gen_axes_patchc                 C   s   t dtj| dddddfdtj| dfd	tj| d
fdtj| dddddfg}|d | j| j  |d | j| j  |d | j |d	 | j |S )Nr	  r   r!  rJ   r  r   r   r   r  r   r  r   )	r   mspinesZSpineZ	arc_spineZlinear_spiner   r%  r&  r*  )r   r  r   r   r   _gen_axes_spines  s    zPolarAxes._gen_axes_spinesc                 C   s   t || j_dS )z'Set the maximum theta limit in degrees.N)r   rk   r   x1)r   r   r   r   r   set_thetamax  s    zPolarAxes.set_thetamaxc                 C   s   t | jjS )z*Return the maximum theta limit in degrees.)r   r1   r   r   r9   r   r   r   r     s    zPolarAxes.get_thetamaxc                 C   s   t || j_dS )z'Set the minimum theta limit in degrees.N)r   rk   r   Zx0)r   r   r   r   r   set_thetamin  s    zPolarAxes.set_thetaminc                 C   s   t | jjS )z'Get the minimum theta limit in degrees.)r   r1   r   r   r9   r   r   r   r     s    zPolarAxes.get_thetaminc                 O   s   |   }d|v r$t|d|d< d|v r@t|d|d< | j|i |\}}t|| dtj kr|| | tdtt	||fS )a  
        Set the minimum and maximum theta values.

        Can take the following signatures:

        - ``set_thetalim(minval, maxval)``: Set the limits in radians.
        - ``set_thetalim(thetamin=minval, thetamax=maxval)``: Set the limits
          in degrees.

        where minval and maxval are the minimum and maximum limits. Values are
        wrapped in to the range :math:`[0, 2\pi]` (in radians), so for example
        it is possible to do ``set_thetalim(-np.pi / 2, np.pi / 2)`` to have
        an axes symmetric around 0. A ValueError is raised if the absolute
        angle difference is larger than a full circle.
        r   r   r   r   r	   z/The angle range must be less than a full circle)
Zget_xlimr   rk   popr  r^   rU   
ValueErrortupler1   )r   r   r   Zorig_limZnew_minZnew_maxr   r   r   set_thetalim  s    
zPolarAxes.set_thetalimc                 C   s    | j  }||d< | j   dS )zB
        Set the offset for the location of 0 in radians.
        r   r	   N)r$  rQ   r   )r   r   mtxr   r   r   r    s    
zPolarAxes.set_theta_offsetc                 C   s   | j  d S )zB
        Get the offset for the location of 0 in radians.
        rO  )r$  rQ   r9   r   r   r   r     s    zPolarAxes.get_theta_offsetr  c              	   C   sT   t jd t jd t jt jd t jd t jd dt jd d}| || t | S )	a  
        Set the location of theta's zero.

        This simply calls `set_theta_offset` with the correct value in radians.

        Parameters
        ----------
        loc : str
            May be one of "N", "NW", "W", "SW", "S", "SE", "E", or "NE".
        offset : float, default: 0
            An offset in degrees to apply from the specified *loc*. **Note:**
            this offset is *always* applied counter-clockwise regardless of
            the direction setting.
        rJ   g      ?g      ?rZ   g      ?r   g      ?)NZNWWZSWSZSEEZNE)r   rU   r  rk   )r   r   r   mappingr   r   r   set_theta_zero_location"  s    	z!PolarAxes.set_theta_zero_locationc                 C   sN   | j  }|dv rd|d< n$|dv r.d|d< ntjg d|d | j   dS )	z
        Set the direction in which theta increases.

        clockwise, -1:
           Theta increases in the clockwise direction

        counterclockwise, anticlockwise, 1:
           Theta increases in the counterclockwise direction
        )	clockwiser*   r*   r   )counterclockwiseanticlockwiser)   r)   )r*   r)   rW  rX  rY  )r   N)r#  rQ   r   r3  r   )r   r   rP  r   r   r   r  <  s    



zPolarAxes.set_theta_directionc                 C   s   | j  d S )z
        Get the direction in which theta increases.

        -1:
           Theta increases in the clockwise direction

        1:
           Theta increases in the counterclockwise direction
        r   )r#  rQ   r9   r   r   r   r   Q  s    
zPolarAxes.get_theta_directionc                 C   s   || j _dS )zi
        Set the outer radial limit.

        Parameters
        ----------
        rmax : float
        N)r   y1)r   rD  r   r   r   set_rmax]  s    zPolarAxes.set_rmaxc                 C   s   | j jS )zW
        Returns
        -------
        float
            Outer radial limit.
        )r   rL   r9   r   r   r   get_rmaxg  s    zPolarAxes.get_rmaxc                 C   s   || j _dS )zi
        Set the inner radial limit.

        Parameters
        ----------
        rmin : float
        N)r   r  )r   rC  r   r   r   set_rminp  s    zPolarAxes.set_rminc                 C   s   | j jS )z[
        Returns
        -------
        float
            The inner radial limit.
        )r   rM   r9   r   r   r   r   z  s    zPolarAxes.get_rminc                 C   s   || j _dS )zj
        Update the radial origin.

        Parameters
        ----------
        rorigin : float
        N)r"  Z	locked_y0)r   r   r   r   r   r    s    zPolarAxes.set_roriginc                 C   s   | j jS )z7
        Returns
        -------
        float
        )r"  r  r9   r   r   r   r     s    zPolarAxes.get_roriginc                 C   s   t | jj| jj S r
   )r   signr"  rZ  r  r9   r   r   r   r     s    zPolarAxes.get_rsignNTFc                 K   sb   d|v r$|du r| d}ntdd|v rH|du r@| d}ntd| jf ||||d|S )z3
        See `~.polar.PolarAxes.set_ylim`.
        rC  Nz?Cannot supply both positional "bottom"argument and kwarg "rmin"rD  z<Cannot supply both positional "top"argument and kwarg "rmax"r   r   emitr   )rK  rL  set_ylim)r   r   r   r`  r   r   r   r   r   set_rlim  s    zPolarAxes.set_rlim)rM   rL   c                   st   |dur|durt dn|}|dur<|dur8t dn|}|du r`t|r`|d |d  }}t j||||dS )a  
        Set the data limits for the radial axis.

        Parameters
        ----------
        bottom : float, optional
            The bottom limit (default: None, which leaves the bottom
            limit unchanged).
            The bottom and top ylims may be passed as the tuple
            (*bottom*, *top*) as the first positional argument (or as
            the *bottom* keyword argument).

        top : float, optional
            The top limit (default: None, which leaves the top limit
            unchanged).

        emit : bool, default: True
            Whether to notify observers of limit change.

        auto : bool or None, default: False
            Whether to turn on autoscaling of the y-axis. True turns on,
            False turns off, None leaves unchanged.

        ymin, ymax : float, optional
            These arguments are deprecated and will be removed in a future
            version.  They are equivalent to *bottom* and *top* respectively,
            and it is an error to pass both *ymin* and *bottom* or
            *ymax* and *top*.

        Returns
        -------
        bottom, top : (float, float)
            The new y-axis limits in data coordinates.
        Nz@Cannot supply both positional "bottom" argument and kwarg "ymin"z=Cannot supply both positional "top" argument and kwarg "ymax"r   r)   r_  )rL  r   iterabler   ra  )r   r   r   r`  r   rM   rL   r   r   r   ra    s    $

zPolarAxes.set_ylimc                 C   s   t | j d S )zw
        Returns
        -------
        float
            The theta position of the radius labels in degrees.
        rO  )r   r1   r+  rQ   r9   r   r   r   r     s    zPolarAxes.get_rlabel_positionc                 C   s   | j  t|d dS )z
        Update the theta position of the radius labels.

        Parameters
        ----------
        value : number
            The angular position of the radius labels in degrees.
        r  N)r+  r   rP   r   rk   )r   r[   r   r   r   set_rlabel_position  s    	zPolarAxes.set_rlabel_positionc                    s0   t  j|i | | j| | j |  d S r
   )r   
set_yscaler  r   r   r   r   r   r   r   re    s    zPolarAxes.set_yscalec                 O   s   t j| g|R i |S r
   )r   re  r   r   r   r   
set_rscale  s    zPolarAxes.set_rscalec                 O   s   t j| g|R i |S r
   )r   
set_yticksr   r   r   r   
set_rticks  s    zPolarAxes.set_rticksc                 K   sz   |  |}t|}| | |dur2| | n|durL| jt| | j	 D ]}|
| qV| j | j	 fS )a  
        Set the theta gridlines in a polar plot.

        Parameters
        ----------
        angles : tuple with floats, degrees
            The angles of the theta gridlines.

        labels : tuple with strings or None
            The labels to use at each theta gridline. The
            `.projections.polar.ThetaFormatter` will be used if None.

        fmt : str or None
            Format string used in `matplotlib.ticker.FormatStrFormatter`.
            For example '%f'. Note that the angle that is used is in
            radians.

        Returns
        -------
        lines : list of `.lines.Line2D`
            The theta gridlines.

        labels : list of `.text.Text`
            The tick labels.

        Other Parameters
        ----------------
        **kwargs
            *kwargs* are optional `.Text` properties for the labels.

        See Also
        --------
        .PolarAxes.set_rgrids
        .Axis.get_gridlines
        .Axis.get_ticklabels
        N)Zconvert_yunitsr   rk   Z
set_xticksZset_xticklabelsr  r   mtickerFormatStrFormatterget_ticklabelsupdateZget_ticklines)r   Zangleslabelsfmtr   r&   r   r   r   set_thetagrids  s    '


zPolarAxes.set_thetagridsc                 K   s   |  |}t|}| | |dur2| | n|durL| jt| |du r\| 	 }| 
| | j D ]}|| qp| j | j fS )a  
        Set the radial gridlines on a polar plot.

        Parameters
        ----------
        radii : tuple with floats
            The radii for the radial gridlines

        labels : tuple with strings or None
            The labels to use at each radial gridline. The
            `matplotlib.ticker.ScalarFormatter` will be used if None.

        angle : float
            The angular position of the radius labels in degrees.

        fmt : str or None
            Format string used in `matplotlib.ticker.FormatStrFormatter`.
            For example '%f'.

        Returns
        -------
        lines : list of `.lines.Line2D`
            The radial gridlines.

        labels : list of `.text.Text`
            The tick labels.

        Other Parameters
        ----------------
        **kwargs
            *kwargs* are optional `.Text` properties for the labels.

        See Also
        --------
        .PolarAxes.set_thetagrids
        .Axis.get_gridlines
        .Axis.get_ticklabels
        N)Zconvert_xunitsr   Zasarrayrg  Zset_yticklabelsr  r   ri  rj  r   rd  rk  rl  Zget_gridlines)r   Zradiirm  r   rn  r   r&   r   r   r   
set_rgrids0  s    (



zPolarAxes.set_rgridsc              	   C   s   | j ||f}|ttg dg ddj }| j  |j\}}t|| tj	 dtj	  tj	 
 }|tj	 }|d }	t|| 
 }
|dk r|dtj	 7 }|tj	 }|d }dd }d|||d	d
|||	d	d
|||
ddS )N)r*   r   r)   )r	   r*   r	   r   r   c                 S   sD   |dkr t dtt| n
t| |}| d| d| | S )Nfr   -.)r_   mathfloorra   r   Z_g_sig_digits)r[   deltaoptrn  precr   r   r   
format_sigy  s     
z*PolarAxes.format_coord.<locals>.format_sigu   θ={}π ({}°), r={} rq  #g)r'  rz   r   stackZmeshgridr.   rS   r:   r^   rU   r_   rb   )r   rX   r'   Z	screen_xyZ
screen_xystsrsZdelta_tZdelta_t_halfturnsZdelta_t_degreesZdelta_rZtheta_halfturnsZtheta_degreesry  r   r   r   format_coordg  s*    &

zPolarAxes.format_coordc                 C   s   dS )zr
        Return the aspect ratio of the data itself.  For a polar plot,
        this should always be 1.0
        r   r   r9   r   r   r   get_data_ratio  s    zPolarAxes.get_data_ratioc                 C   s   dS )z
        Return whether this axes supports the zoom box button functionality.

        Polar axes do not support zoom boxes.
        Fr   r9   r   r   r   can_zoom  s    zPolarAxes.can_zoomc                 C   s   dS )a  
        Return whether this axes supports the pan/zoom button functionality.

        For polar axes, this is slightly misleading. Both panning and
        zooming are performed by the same button. Panning is performed
        in azimuth while zooming is done along the radial.
        Tr   r9   r   r   r   can_pan  s    zPolarAxes.can_panc           	   	   C   s   t |  }d}|dkrbt jd }| j ||f\}}|| |  krX|| krnn qnd}n|dkrnd}tj| 	 | j
 | j 
 |  |||d| _d S )Nrz  r)   g     F@drag_r_labelsr   zoom)rD  r   trans_inverser_label_anglerV   rW   r   )r   rk   r   rU   r'  r:   rz   typesSimpleNamespacer\  frozen
_pan_start)	r   rV   rW   buttonr   r   epsilonr&   r'   r   r   r   	start_pan  s$    
 zPolarAxes.start_panc                 C   s   | ` d S r
   )r  r9   r   r   r   end_pan  s    zPolarAxes.end_panc                 C   s  | j }|jdkr|j|j|jf||fg\\}}\}}	t|| }
| |j	|
  | 
d\}}}| d\}}}| jj| jj D ]4}|j| |j| |j| |j| qnL|jdkr
|j|j|jf||fg\\}}\}}	|	| }| |j|  d S )Nr  r  r  )r  r   r  rz   rV   rW   r   r1   rd  r  r>  r?  r  Z
majorTicksZ
minorTicksr   r   r   r   r[  rD  )r   r  keyrV   rW   pZstarttZstartrr&   r'   dtr   Zvert1Zhoriz1Zvert2Zhoriz2rO   r   r   r   drag_pan  s(    
zPolarAxes.drag_pan)r  )r  )r  )NNTF)NNTF)NN)NNN)4r;   r<   r=   r>   namer   r   r  r-  r5  r9  r:  r;  r>  r?  rB  rE  rG  rI  r   rJ  r   rN  r  r   rV  r  r   r[  r\  r]  r   r  r   r   rb  ra  r   rd  re  rf  rh  ro  rp  r  r  r  r  r  r  r  rD   r   r   r   r   r7     sf   
R

	.

	
	

4	
2
7	
r7   ):collectionsr   rt  r  Znumpyr   Z
matplotlibr   r   r   Zmatplotlib.axesr   Zmatplotlib.axisr   ZmaxisZmatplotlib.markersmarkersr   Zmatplotlib.patchesZpatchesr  Zmatplotlib.pathr   Zmatplotlib.tickerZtickerri  Zmatplotlib.transformsZ
transformsrA   Zmatplotlib.spinesr  rF  Z	Transformr   ZAffine2DBaserE   r8   	FormatterrY   rh   Locatorrq   ZXTickrx   ZXAxisr   r   r{   r   ZYTickr   ZYAxisr   ru   r   ZBboxr   r7   r   r   r   r   <module>   sP   ^!)!]8&2 (		8     b