ó
 m[c           @` s  d  Z  d d l m Z m Z m Z m Z d d l Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z m Z d d	 l m Z d d
 l m Z m Z d d l Z d d l m Z d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   u/   
An experimental support for curvilinear grid.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   zip(   t   chaini   (   t
   GridFinder(   t   AxisArtistHelpert   GridHelperBase(   t
   AxisArtist(   t   Affine2Dt   IdentityTransform(   t   Patht   FixedAxisArtistHelperc           B` sA   e  Z d  Z d d „ Z d „  Z d d „ Z d „  Z d „  Z RS(   u(   
    Helper class for a fixed axis.
    c         C` sY   t  t |  ƒ j d | ƒ | |  _ | d k r: |  j } n  | |  _ | |  _ t |  _	 d S(   u}   
        nth_coord = along which coordinate value varies.
         nth_coord = 0 ->  x axis, nth_coord = 1 -> y axis
        t   locN(
   t   superR   t   __init__t   grid_helpert   Nonet	   nth_coordt   nth_coord_tickst   sidet   Falset   _limits_inverted(   t   selfR   R   R   (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyR      s    			c         C` sk   |  j  j | ƒ |  j d k r4 | j ƒ  \ } } n | j ƒ  \ } } | | k r^ t |  _ n	 t |  _ d  S(   Ni    (   R   t
   update_limR   t   get_ylimt   get_xlimt   TrueR   R   (   R   t   axest   xy1t   xy2(    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyR   )   s    c         C` sG   | d  k r d |  j |  _ n$ | d k r7 | |  _ n t d ƒ ‚ d  S(   Ni   i    u   wrong coord number(   i    i   (   R   R   t	   Exception(   R   t   coord_number(    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   change_tick_coord7   s
    c         C` s   | j  S(   N(   t	   transData(   R   R   (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   get_tick_transform@   s    c         C` s”   |  j  } |  j r> i d d 6d d 6d d 6d d 6|  j } n	 |  j } | j |  j | ƒ } | j d |  j | d t ƒ} t | | ƒ t g  ƒ f S(   u    tick_loc, tick_angle, tick_labelu   rightu   leftu   bottomu   topi   t   minor(   R   R   R   t   get_tick_iteratorR   R   R   t   iter(   R   R   t   gR   t   ti1t   ti2(    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   get_tick_iteratorsC   s    			N(	   t   __name__t
   __module__t   __doc__R   R   R   R"   R$   R+   (    (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyR      s   			t   FloatingAxisArtistHelperc           B` s\   e  Z d	 d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(
   c         C` sJ   t  t |  ƒ j | | ƒ | |  _ | |  _ d |  _ d |  _ d |  _ d S(   u}   
        nth_coord = along which coordinate value varies.
         nth_coord = 0 ->  x axis, nth_coord = 1 -> y axis
        id   N(   NN(	   R   R/   R   t   valueR   R   t	   _extremest   _get_line_patht   _line_num_points(   R   R   R   R0   t   axis_direction(    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyR   Y   s    				c         C` s   | | f |  _  d  S(   N(   R1   (   R   t   e1t   e2(    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   set_extremesi   s    c         C` sá  |  j  j | ƒ | j ƒ  \ } } | j ƒ  \ } } |  j  j } | j | j | | | | ƒ } t | ƒ } |  j \ } }	 |  j	 d k r× | d  k	 r® t | | d ƒ | d <n  |	 d  k	 r5t |	 | d ƒ | d <q5n^ |  j	 d k r5| d  k	 rt | | d ƒ | d <n  |	 d  k	 r5t |	 | d ƒ | d <q5n  t ƒ  }
 | \ } } } } | j | | ƒ \ } } } | j | | ƒ \ } } } | |
 d <| | | f |
 d <| | | f |
 d <| j d | | ƒ |
 d	 <| j d | | ƒ |
 d
 <|  j  j } |  j	 d k r\t j |  j |  j |  j ƒ } t j | d | d |  j ƒ } | j | | ƒ \ } } nh |  j	 d k rÄt j | d | d |  j ƒ } t j |  j |  j |  j ƒ } | j | | ƒ \ } } n  | | f |
 d <|
 |  _ d  S(   Ni    i   i   i   u   extremesu   lon_infou   lat_infou   bottomu
   lon_labelsu
   lat_labelsu   line_xy(   R   R   R   R   t   grid_findert   extreme_findert   inv_transform_xyt   listR1   R   R   t   maxt   mint   dictt   grid_locator1t   grid_locator2t   tick_formatter1t   tick_formatter2t   npt   linspaceR0   R3   t   transform_xyt	   grid_info(   R   R   t   x1t   x2t   y1t   y2R8   t   extremesR5   R6   RF   t   lon_mint   lon_maxt   lat_mint   lat_maxt   lon_levst   lon_nt
   lon_factort   lat_levst   lat_nt
   lat_factort   xx0t   yy0t   xxt   yy(    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyR   l   sT    	
		  c         C` s   t  ƒ  S(   N(   R
   (   R   R   (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   get_axislabel_transform¤   s    c         C` sû  |  j  d } |  j d k ra |  j } | d | d d } d t | d | d ƒ d } } nT |  j d k rµ | d | d d } |  j } t | d | d ƒ d d } } n  |  j j } | j | g | g ƒ \ } }	 | j | j j	 ƒ  }
 |
 j
 | d |	 d g ƒ } d | d k o-d	 k n ród | d k oMd	 k n ró| j j
 | d |	 d g ƒ \ } } | j | | g | | g ƒ \ } } | j j
 | d | d g ƒ \ } } | | f t j | | | | ƒ t j d
 f Sd Sd  S(   Nu   extremesi    i   i   g       @g        g     @@i   g      ð?g     €f@(   NN(   RF   R   R0   t   absR   R8   RE   R#   t	   transAxest   invertedt   transform_pointRC   t   arctan2t   piR   (   R   R   RK   RV   RW   t   dxxt   dyyR8   t   xx1t   yy1t   trans_passingthrough_pointt   pt   xx1ct   yy1ct   xx2t   yy2t   xx2ct   yy2c(    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   get_axislabel_pos_angle§   s&    	&	&@&&&/c         C` s   t  ƒ  S(   N(   R   (   R   R   (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyR$   Ç   s    c         ` sÝ  ˆ j  j ‰ ˆ j d \ } } } t j | ƒ } | d
 k	 rT | | } d | } n | } d } ˆ j d \ } } }	 t j | ƒ } |	 d
 k	 r¨ | |	 }
 d |	 } n | }
 d } d
 ˆ j k rÕ ˆ j \ } } n t ˆ j ƒ \ } } | d
 k rt j } n  | d
 k rt j } n  ˆ j	 d k rM| | k | | k @} | | } n2 ˆ j	 d k r| |
 k |
 | k @} |
 | }
 n  ‡  ‡ f d †  } ˆ j	 d k r”t j
 | ƒ }
 |
 j ˆ j ƒ | |
 | ƒ \ ‰ ‰	 |
 j ƒ  } | |
 | | k c | 8<| | | ƒ \ ‰ ‰
 | | | | ƒ \ ‰ ‰ | |
 | ƒ \ ‰ ‰ | |
 | | ƒ \ ‰ ‰ ˆ j d ‰ g  t ˆ | ƒ D] \ } } | rs| ^ qs‰ nˆ j	 d k r—t j
 |
 ƒ } | j ˆ j ƒ | |
 | ƒ \ ‰ ‰	 | |
 | ƒ \ ‰ ‰
 | |
 | | ƒ \ ‰ ‰ |
 j ƒ  } | |
 | | k c | 8<| | | ƒ \ ‰ ‰ | | | | ƒ \ ‰ ‰ ˆ j d ‰ g  t ˆ | ƒ D] \ } } | rv| ^ qv‰ n  ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡	 ‡
 ‡ ‡ ‡ f d	 †  } | ƒ  t g  ƒ f S(   u9   tick_loc, tick_angle, tick_label, (optionally) tick_labelu   lat_infog{®Gáz„?u   lon_infoi    i   c         ` s[   ˆ j  |  | ƒ \ } } ˆ  j j t j | | g ƒ j ƒ  ƒ } | j ƒ  \ } } | | f S(   N(   RE   R#   t	   transformRC   t   arrayt	   transpose(   t   xt   yRG   RI   t   x2y2RH   RJ   (   R   R8   (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyRE   ó   s    'u
   lat_labelsu
   lon_labelsc          3` sd  t  j ˆ
 ˆ	 ˆ ˆ ƒ }  t  j ˆ ˆ ˆ ˆ ƒ } ˆ
 ˆ	 d k ˆ ˆ d k @} | | t  j d |  | <ˆ j ˆ  ƒ } | ˆ  j j ƒ  } xÐ t ˆ ˆ |  | ˆ ƒ D]¶ \ } } } } }	 | j | | f ƒ }
 d } d | |
 d k où d | k n r¦ d | |
 d k o!d | k n r¦ | d d } | d d } | | g | | |	 f Vq¦ q¦ Wd  S(	   Ng        i   gñhãˆµøä>i    g      ð?i   gn†ðù!	@g     €f@(   RC   R_   R`   R$   R\   R]   R   R^   (   t   ddt   dd2t   mmt
   trans_tickt   tr2axRq   Rr   t   dt   d2t   labt   c2t   deltat   d1(   R   t   labelsR   Rc   t   xx1at   xx1bt   xx2at   xx2bRd   t   yy1at   yy1bt   yy2at   yy2b(    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   f1  s    	.((N(   R   R8   RF   RC   t   asarrayR   R1   t   sortedt   infR   t
   empty_liket   fillR0   t   copyR   R'   (   R   R   RS   RT   RU   RW   t   dyRP   RQ   RR   RV   t   dxt   e0R5   t   maskRE   t   xx00t   lt   mRˆ   (    (   R   R8   R   R   Rc   R€   R   R‚   Rƒ   Rd   R„   R…   R†   R‡   sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyR+   Ê   sn    

113c         C` s   | j  S(   N(   R#   (   R   R   (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   get_line_transform7  s    c         C` s_   |  j  | ƒ |  j d \ } } |  j d  k rH t t j | | g ƒ ƒ S|  j | | | ƒ Sd  S(   Nu   line_xy(   R   RF   R2   R   R   RC   t   column_stack(   R   R   Rq   Rr   (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   get_line:  s
    N(   R,   R-   R   R   R7   R   RZ   Rm   R$   R+   R–   R˜   (    (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyR/   W   s   		8		 		m	t   GridHelperCurveLinearc           B` s}   e  Z d d d d d d  „ Z d d „ Z d „  Z d d d d d „ Z d d d „ Z d „  Z d d d	 „ Z	 e
 d
 „ Z RS(   c         C` sP   t  t |  ƒ j ƒ  d |  _ d |  _ | |  _ t | | | | | | ƒ |  _ d S(   uÇ  
        aux_trans : a transform from the source (curved) coordinate to
        target (rectilinear) coordinate. An instance of MPL's Transform
        (inverse transform should be defined) or a tuple of two callable
        objects which defines the transform and its inverse. The callables
        need take two arguments of array of source coordinates and
        should return two target coordinates.

        e.g., ``x2, y2 = trans(x1, y1)``
        N(	   R   R™   R   R   RF   t   _old_valuest
   _aux_transR   R8   (   R   t	   aux_transR9   R?   R@   RA   RB   (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyR   H  s    			c         K` s=   | d  k	 r |  j j | ƒ n  |  j j |   |  j ƒ  d  S(   N(   R   R8   t   update_transformt   updatet
   invalidate(   R   Rœ   t   kw(    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   update_grid_finderg  s    c         C` sc   |  j  ƒ  r+ |  j | | | | f k r+ d S|  j | | | | ƒ | | | | f |  _ t |  _ d S(   u!   bbox in 0-based image coordinatesN(   t   validRš   t   _update_gridR   t   _force_update(   R   RG   RH   RI   RJ   (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   _updatep  s
    'c         C` s[   | d  k r |  j } n  | d  k r- | } n  t |  | d | ƒ} t | | d | ƒ} | S(   NR   R4   (   R   R   R   R	   (   R   R   R   R4   t   offsetR   t   _helpert   axisline(    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   new_fixed_axis~  s    		u   bottomc         C` sf   | d  k r |  j } n  t |  | | | ƒ } t | | ƒ } | j j t ƒ | j j | j j ƒ | S(   N(	   R   R   R/   R	   t   linet   set_clip_onR   t   set_clip_boxt   bbox(   R   R   R0   R   R4   R§   R¨   (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   new_floating_axis”  s    	c         C` s"   |  j  j | | | | ƒ |  _ d  S(   N(   R8   t   get_grid_infoRF   (   R   RG   RI   RH   RJ   (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyR£   ´  s    u   majoru   bothc         C` sz   g  } | d k r> x) |  j  d d D] } | j | ƒ q$ Wn  | d k rv x) |  j  d d D] } | j | ƒ q\ Wn  | S(	   Nu   bothu   xu   lonu   linesu   yu   lat(   u   bothu   x(   u   bothu   y(   RF   t   extend(   R   t   whicht   axist
   grid_linest   gl(    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   get_gridlines¹  s    c      	   ` su   t  d d d d d d d d ƒ ˆ ‰  d d g | ‰ | sV ‡  ‡ ‡ ‡ f d	 †  } n ‡  ‡ ‡ ‡ f d
 †  } | ƒ  S(   Nt   leftiZ   t   rightt   bottomi    t   topu   lonu   latc          3` s_   xX t  ˆ j ˆ d ˆ ˆ j ˆ d ˆ ƒ D]) \ \ }  } } | } |  | ˆ  | f Vq. Wd  S(   Nu	   tick_locsu   tick_labels(   R   RF   (   t   xyt   aR”   t   angle_normal(   t   angle_tangentt	   axis_sidet
   lon_or_latR   (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   fÍ  s    (c          3` s_   xX t  ˆ j ˆ d ˆ ˆ j ˆ d ˆ ƒ D]) \ \ }  } } | } |  | ˆ  d f Vq. Wd  S(   Nu	   tick_locsu   tick_labelsu    (   R   RF   (   Rº   R»   R”   R¼   (   R½   R¾   R¿   R   (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyRÀ   Ó  s    ((   R>   (   R   R   R¾   R%   RÀ   (    (   R½   R¾   R¿   R   sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyR&   Æ  s    %N(   R,   R-   R   R   R¡   R¥   R©   R®   R£   Rµ   R   R&   (    (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyR™   F  s    			(   R.   t
   __future__R    R   R   R   t   sixt	   six.movesR   t	   itertoolsR   R8   R   t	   axislinesR   R   t   axis_artistR	   t   matplotlib.transformsR
   R   t   numpyRC   t   matplotlib.pathR   t   FixedR   t   FloatingR/   R™   (    (    (    sN   lib/python2.7/site-packages/mpl_toolkits/axisartist/grid_helper_curvelinear.pyt   <module>   s   "Cï