ó
 m[c           @` sX  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	 Z	 d d l
 m Z d d l m Z m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e e d e e e d e e d d e d d „ Z e j j d e j e ƒ ƒ d S(   uG  
Place a table below the x-axis at location loc.

The table consists of a grid of cells.

The grid need not be rectangular and can have holes.

Cells are added by specifying their row and column.

For the purposes of positioning the cell at (0, 0) is
assumed to be at the top left and the cell at (max_row, max_col)
is assumed to be at bottom right.

You can add additional cells outside this range to have convenient
ways of positioning more interesting grids.

Author    : John Gill <jng@europe.renre.com>
Copyright : 2004 John Gill and John Hunter
License   : matplotlib license

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   xrangei   (   t   artist(   t   Artistt   allow_rasterization(   t	   Rectangle(   t	   docstring(   t   Text(   t   Bbox(   t   Patht   Cellc           B` s˜   e  Z d  Z d Z d d e d d d d „ Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z RS(   u;   
    A cell is a Rectangle with some associated text.

    gš™™™™™¹?u   ku   wu    c
   
      C` s“   t  j |  | d | d | d | d | ƒ|  j t ƒ | d  k rJ d } n  | |  _ t d | d d | d	 d
 | d |	 ƒ |  _ |  j j t ƒ d  S(   Nt   widtht   heightt	   edgecolort	   facecoloru   rightt   xi    t   yi   t   textt   fontproperties(   R   t   __init__t   set_clip_ont   Falset   Nonet   _locR
   t   _text(
   t   selft   xyR   R   R   R   t   fillR   t   locR   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR   .   s    			 c         C` s   t  j |  | ƒ t |  _ d  S(   N(   R   t   set_transformt   Truet   stale(   R   t   trans(    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR    C   s    c         C` s$   t  j |  | ƒ |  j j | ƒ d  S(   N(   R   t
   set_figureR   (   R   t   fig(    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR$   H   s    c         C` s   |  j  S(   u   Return the cell Text intance(   R   (   R   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   get_textL   s    c         C` s   |  j  j | ƒ t |  _ d  S(   N(   R   t   set_fontsizeR!   R"   (   R   t   size(    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR'   P   s    c         C` s   |  j  j ƒ  S(   u   Return the cell fontsize(   R   t   get_fontsize(   R   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR)   T   s    c         C` sj   |  j  ƒ  } |  j | ƒ } xH | d k re | |  j ƒ  k re | d 8} |  j | ƒ |  j | ƒ } q W| S(   u#    Shrink font size until text fits. i   (   R)   t   get_required_widtht	   get_widthR'   (   R   t   renderert   fontsizet   required(    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   auto_set_font_sizeX   s    !
c         C` sJ   |  j  ƒ  s d  St j |  | ƒ |  j | ƒ |  j j | ƒ t |  _ d  S(   N(   t   get_visibleR   t   drawt   _set_text_positionR   R   R"   (   R   R,   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR1   c   s    c   	      C` sä   |  j  | ƒ } | j \ } } } } |  j j d ƒ | | d } |  j d k rr |  j j d ƒ | | d } nX |  j d k r¥ |  j j d ƒ | | |  j } n% |  j j d ƒ | | d |  j } |  j j | | f ƒ d S(   um    Set text up so it draws in the right place.

        Currently support 'left', 'center' and 'right'
        u   centerg       @u   leftu   rightg      ð?N(   t   get_window_extentt   boundsR   t   set_verticalalignmentR   t   set_horizontalalignmentt   PADt   set_position(	   R   R,   t   bboxt   lt   bt   wt   hR   R   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR2   o   s    c         C` s.   |  j  j | ƒ } | j |  j ƒ  ƒ } | j S(   u'    Get text bounds in axes co-ordinates. (   R   R3   t   inverse_transformedt   get_data_transformR4   (   R   R,   R9   t   bboxa(    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   get_text_boundsˆ   s    c         C` s.   |  j  | ƒ \ } } } } | d d |  j S(   u#    Get width required for this cell. g      ð?g       @(   RA   R7   (   R   R,   R:   R;   R<   R=   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR*   Ž   s    c         K` s   |  j  j | ƒ t |  _ d S(   u&   update the text properties with kwargsN(   R   t   updateR!   R"   (   R   t   kwargs(    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   set_text_props“   s    N(   t   __name__t
   __module__t   __doc__R7   R!   R   R   R    R$   R&   R'   R)   R/   R   R1   R2   RA   R*   RD   (    (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR   '   s$   									t
   CustomCellc           B` si   e  Z d  Z d Z i d d 6e d 6d d 6d d 6Z d	 „  Z e d
 „  ƒ Z e j d „  ƒ Z d „  Z	 RS(   uE   
    A subclass of Cell where the sides may be visibly toggled.

    u   BRTLu    u   openu   closedu   BTu
   horizontalu   RLu   verticalc         O` s/   | j  d ƒ } t j |  | | Ž | |  _ d  S(   Nu   visible_edges(   t   popR   R   t   visible_edges(   R   t   argsRC   RJ   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR   ¦   s    c         C` s   |  j  S(   N(   t   _visible_edges(   R   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyRJ   «   s    c         C` s©   | d  k r |  j |  _ n | |  j k r= |  j | |  _ n_ xS | D]K } | |  j k rD t d j | d j |  j ƒ d j |  j ƒ ƒ ƒ ‚ qD qD W| |  _ t |  _ d  S(   Nu=   Invalid edge param {}, must only be one of {} or string of {}u   , (	   R   t   _edgesRL   t   _edge_aliasest
   ValueErrort   formatt   joinR!   R"   (   R   t   valuet   edge(    (    s/   lib/python2.7/site-packages/matplotlib/table.pyRJ   ¯   s    		c         C` sµ   t  j g } xC |  j D]8 } | |  j k r> | j t  j ƒ q | j t  j ƒ q Wt  j | d k ru t  j | d <n  t  d d g d d g d d g d d g d d g g | d t ƒS(   uC   Return a path where the edges specified by _visible_edges are drawni   iÿÿÿÿg        g      ð?t   readonly(   R   t   MOVETORM   RL   t   appendt   LINETOt	   CLOSEPOLYR!   (   R   t   codesRS   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   get_pathÀ   s    0(
   RE   RF   RG   RM   RN   R   t   propertyRJ   t   setterRZ   (    (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyRH   ™   s   

	t   Tablec           B` sˆ  e  Z d  Z i d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d! d" 6d# d$ 6Z d Z d% Z d< d< d& „ Z d' „  Z d( „  Z	 d) „  Z
 e d* „  ƒ Z e j d+ „  ƒ Z d, „  Z e d- „  ƒ Z d. „  Z d/ „  Z d0 „  Z e Z d1 „  Z d2 „  Z d3 „  Z d4 „  Z e d5 „ Z d6 „  Z d7 „  Z d8 „  Z d9 „  Z d: „  Z d; „  Z  RS(=   u5  
    Create a table of cells.

    Table can have (optional) row and column headers.

    Each entry in the table can be either text or patches.

    Column widths and row heights for the table can be specified.

    Return value is a sequence of text, line and patch instances that make
    up the table
    i    u   besti   u   upper righti   u
   upper lefti   u
   lower lefti   u   lower righti   u   center lefti   u   center righti   u   lower centeri   u   upper centeri	   u   centeri
   u	   top righti   u   top lefti   u   bottom lefti   u   bottom righti   u   righti   u   lefti   u   topi   u   bottomg{®Gáz”?c         K` s  t  j |  ƒ t | t j ƒ rZ | |  j k rZ t j d | d j |  j ƒ f ƒ d } n  t | t j ƒ r„ |  j j	 | d ƒ } n  |  j
 | j ƒ | |  _ | |  _ | |  _ |  j | j ƒ g  |  _ i  |  _ d  |  _ g  |  _ g  |  _ t |  _ |  j | ƒ |  j t ƒ d  S(   NuI   Unrecognized location %s. Falling back on bottom; valid locations are
%s	u   
	u   bottomi   (   R   R   t
   isinstancet   sixt   string_typesRY   t   warningst   warnRQ   t   getR$   t   figuret   _axesR   t   _bboxR    t	   transAxest   _textst   _cellsR   RM   t	   _autoRowst   _autoColumnsR!   t   _autoFontsizeRB   R   R   (   R   t   axR   R9   RC   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR   ù   s(    !											c         O` s5   d } t  | d |  j | | Ž} | |  | | f <| S(   u÷   
        Add a cell to the table.

        Parameters
        ----------
        row : int
            Row index
        col : int
            Column index

        Returns
        -------
        `CustomCell`: Automatically created cell

        i    RJ   (   i    i    (   RH   t   edges(   R   t   rowt   colRK   RC   R   t   cell(    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   add_cell  s    c         C` s§   t  | t ƒ s t d ƒ ‚ n  y | d | d } } Wn t k
 rV t d ƒ ‚ n X| j |  j ƒ | j |  j ƒ  ƒ | j	 t
 ƒ | |  j | | f <t |  _ d S(   u6   
        Set a customcell in a given position
        u   Table only accepts CustomCelli    i   u0   Only tuples length 2 are accepted as coordinatesN(   R^   RH   t	   TypeErrort	   Exceptiont   KeyErrorR$   Rd   R    t   get_transformR   R   Ri   R!   R"   (   R   t   positionRq   Ro   Rp   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   __setitem__+  s    c         C` sJ   y | d | d } } Wn t  k
 r8 t d ƒ ‚ n X|  j | | f S(   u>   
        Retreive a custom cell from a given position
        i    i   u0   Only tuples length 2 are accepted as coordinates(   Rt   Ru   Ri   (   R   Rw   Ro   Rp   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   __getitem__;  s
    c         C` s   |  j  S(   N(   RM   (   R   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyRn   E  s    c         C` s   | |  _  t |  _ d  S(   N(   RM   R!   R"   (   R   RR   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyRn   I  s    	c         C` s&   |  j  d |  j j |  j j j d S(   Ng      R@g333333ó?(   t   FONTSIZERd   t   dpiRe   R9   R   (   R   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   _approx_text_heightN  s    c         C` s¨   | d  k r |  j j } n  | d  k r6 t d ƒ ‚ n  |  j ƒ  sF d  S| j d ƒ |  j | ƒ x+ t |  j ƒ D] } |  j | j	 | ƒ qp W| j
 d ƒ t |  _ d  S(   Nu   No renderer definedu   table(   R   Rd   t   _cachedRenderert   RuntimeErrorR0   t
   open_groupt   _update_positionst   sortedRi   R1   t   close_groupR   R"   (   R   R,   t   key(    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR1   R  s    c         C` st   g  t  j |  j ƒ D]9 \ \ } } } | d k r | d k r | j | ƒ ^ q } t j | ƒ } | j |  j ƒ  ƒ S(   ur   Get a bbox, in axes co-ordinates for the cells.

        Only include those in the range (0,0) to (maxRow, maxCol)i    (   R_   t	   iteritemsRi   R3   R   t   unionR>   Rv   (   R   R,   Ro   Rp   Rq   t   boxesR9   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   _get_grid_bboxf  s
    "-c         C` sÂ   t  |  j ƒ r |  j |  | ƒ S|  j j } | d k	 r´ g  t j |  j ƒ D]9 \ \ } } } | d k rJ | d k rJ | j | ƒ ^ qJ } t	 j
 | ƒ } | j | j | j ƒ i  f St i  f Sd S(   uU   Test whether the mouse event occurred in the table.

        Returns T/F, {}
        i    N(   t   callablet	   _containsRd   R}   R   R_   R„   Ri   R3   R   R…   t   containsR   R   R   (   R   t
   mouseeventR,   Ro   Rp   Rq   R†   R9   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyRŠ   p  s    "-c         C` s   t  t j |  j ƒ ƒ S(   u)   Return the Artists contained by the table(   t   listR_   t
   itervaluesRi   (   R   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   get_children„  s    c         C` s;   g  t  j |  j ƒ D] } | j | ƒ ^ q } t j | ƒ S(   u5   Return the bounding box of the table in window coords(   R_   R   Ri   R3   R   R…   (   R   R,   Rq   R†   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR3   ‰  s    +c         C` sV  i  } i  } x| t  j |  j ƒ D]h \ \ } } } | j | d ƒ } t | | j ƒ  ƒ | | <| j | d ƒ } t | | j ƒ  ƒ | | <q Wd } i  }	 x, t | ƒ D] } | |	 | <| | | 7} q¤ Wd }
 i  } x2 t | d t ƒD] } |
 | | <|
 | | 7}
 qå WxH t  j |  j ƒ D]4 \ \ } } } | j	 |	 | ƒ | j
 | | ƒ qWd S(   uW    Calculate row heights and column widths.

        Position cells accordingly.
        g        i    t   reverseN(   R_   R„   Ri   t
   setdefaultt   maxt
   get_heightR+   R   R!   t   set_xt   set_y(   R   t   widthst   heightsRo   Rp   Rq   R   R   t   xpost   leftst   ypost   bottoms(    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   _do_cell_alignment  s(    %

%c         C` sf   y t  | ƒ Wn' t t f k
 r7 |  j j | ƒ n" Xx | D] } |  j j | ƒ q? Wt |  _ d S(   uÕ   Given column indexs in either List, Tuple or int. Will be able to
        automatically set the columns into optimal sizes.

        Here is the example of the input, which triger automatic adjustment on
        columns to optimal size by given index numbers.
        -1: the row labling
        0: the 1st column
        1: the 2nd column

        Args:
            col(List): list of indexs
            >>>table.auto_set_column_width([-1,0,1])

            col(Tuple): tuple of indexs
            >>>table.auto_set_column_width((-1,0,1))

            col(int): index integer
            >>>table.auto_set_column_width(-1)
            >>>table.auto_set_column_width(0)
            >>>table.auto_set_column_width(1)
        N(   t   iterRs   t   AttributeErrorRk   RV   R!   R"   (   R   Rp   Rq   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   auto_set_column_width¯  s    c         C` s‘   g  |  j  D] } | d | k r
 | ^ q
 } d } x3 | D]+ } |  j  | } t | j | ƒ | ƒ } q9 Wx" | D] } |  j  | j | ƒ qo Wd S(   u-    Automagically set width for column.
        i   i    N(   Ri   R‘   R*   t	   set_width(   R   Rp   R,   Rƒ   t   cellsR   Rq   t   c(    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   _auto_set_column_widthÐ  s    ,c         C` s   | |  _  t |  _ d S(   u    Automatically set font size. N(   Rl   R!   R"   (   R   RR   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR/   ß  s    	c         C` sÖ   t  |  j ƒ d k r d  St t j |  j ƒ ƒ d j ƒ  } g  } xd t j |  j ƒ D]P \ } } | d |  j k ry qT n  | j | ƒ } t	 | | ƒ } | j
 | ƒ qT Wx' t j |  j ƒ D] } | j | ƒ q» Wd  S(   Ni    i   (   t   lenRi   RŒ   R_   R   R)   R„   Rk   R/   t   minRV   R'   (   R   R,   R-   R    Rƒ   Rq   R(   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   _auto_set_font_sizeä  s    "c         C` sO   xH t  j |  j ƒ D]4 } | j | j ƒ  | ƒ | j | j ƒ  | ƒ q Wd S(   u:    Scale column widths by xscale and row heights by yscale. N(   R_   R   Ri   RŸ   R+   t
   set_heightR’   (   R   t   xscalet   yscaleR¡   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   scaleö  s    c         C` s7   x' t  j |  j ƒ D] } | j | ƒ q Wt |  _ d S(   uW   
        Set the fontsize of the cell text

        ACCEPTS: a float in points
        N(   R_   R   Ri   R'   R!   R"   (   R   R(   Rq   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR'   ü  s    c         C` s\   xU t  j |  j ƒ D]A } | j ƒ  | j ƒ  } } | j | | ƒ | j | | ƒ q Wd S(   u+   Move all the artists by ox,oy (axes coords)N(   R_   R   Ri   t   get_xt   get_yR“   R”   (   R   t   oxt   oyR¡   R   R   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   _offset  s    c          C` sô  x! |  j  D] } |  j | | ƒ q
 W|  j r= |  j | ƒ n  |  j ƒ  |  j | ƒ } | j \ } } } } |  j d  k	 rÈ |  j \ } }	 }
 } |  j	 |
 | | | ƒ | | } |	 | } |  j ƒ  nt
 t |  j ƒ ƒ \ } } } } } } } } } } } } } } } } } } d | d | } d | d | } |  j | | | f k r_|  j | } n  |  j | | | | | f k r•d | | |  j } n  |  j | | | | f k rÈd | | |  j } n  |  j | | | f k rð|  j | } n  |  j | | | f k rd | d | } n  |  j | | | f k rJd | d | } n  |  j | | | f k rp| | } n  |  j | | | f k r•d | } n  |  j | | | f k rºd | } n  |  j | | | f k rà| | } n  |  j | | ƒ d  S(   Ng      à?i   i   g      ð?(   Rk   R¢   Rl   R¥   R›   R‡   R4   Rf   R   R©   R   R£   RY   R   t   AXESPADR®   (    R   R,   Rp   R9   R:   R;   R<   R=   t   rlt   rbt   rwt   rhR¬   R­   t   BESTt   URt   ULt   LLt   LRt   CLt   CRt   LCt   UCt   Ct   TRt   TLt   BLt   BRt   Rt   Lt   Tt   B(    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR€     sJ    	


Kc         C` s   |  j  S(   u#   return a dict of cells in the table(   Ri   (   R   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt	   get_celldF  s    N(!   RE   RF   RG   RY   Rz   R¯   R   R   Rr   Rx   Ry   R[   Rn   R\   R|   R   R1   R‡   RŠ   RŽ   t   get_child_artistsR3   R›   Rž   R¢   R!   R/   R¥   R©   R'   R®   R€   RÆ   (    (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR]   Õ   sX   

			
		
				 	!						7u   rightu   leftu   centeru   bottomu   closedc         K` sð  | d k r' | d k r' t d ƒ ‚ n  | d k rf t | ƒ } t | d ƒ } d g | g | } n  t | ƒ } t | d ƒ } x8 | D]0 } t | ƒ | k r‰ t d j | ƒ ƒ ‚ q‰ q‰ W| d k	 r1t | ƒ | k ró t d j | ƒ ƒ ‚ n  xL | D]0 } t | ƒ | k rú t d j | ƒ ƒ ‚ qú qú Wn d | g | } | d k rbd | g | } n  d } | d k r| d k	 r¶d g | } | d } q¶n | d k r¶d | } n  | d k	 rït | ƒ | k rït d	 j | ƒ ƒ ‚ qïn  d
 } | d k r&|	 d k	 rd g | } q?d } n |	 d k r?d | }	 n  | d k r_d | g | } n  t |  | | |  } | | _ | j ƒ  } xq t | ƒ D]c } xZ t | ƒ D]L } | j | | | d | | d | d | | | d | | | d | ƒq©Wq–W| d k	 r]xQ t | ƒ D]@ } | j d | d | | d | d | | d |	 | d |
 ƒqWn  | d k	 rßxT t | ƒ D]F } | j | | d d | p˜d d | d | | d | | d | ƒqvW| d k rß| j	 d ƒ qßn  |  j
 | ƒ | S(   ut  
    TABLE(cellText=None, cellColours=None,
          cellLoc='right', colWidths=None,
          rowLabels=None, rowColours=None, rowLoc='left',
          colLabels=None, colColours=None, colLoc='center',
          loc='bottom', bbox=None, edges='closed')

    Factory function to generate a Table instance.

    Thanks to John Gill for providing the class and table.
    uZ   At least one argument from "cellColours" or "cellText" must be provided to create a table.i    u    u+   Each row in 'cellText' must have {} columnsu   'cellColours' must have {} rowsu.   Each row in 'cellColours' must have {} columnsu   wg      ð?u!   'rowLabels' must be of length {0}i   R   R   R   R   R   iÿÿÿÿgVçž¯Ò<N(   R   RO   R£   RP   R]   Rn   R|   R   Rr   Rž   t	   add_table(   Rm   t   cellTextt   cellColourst   cellLoct	   colWidthst	   rowLabelst
   rowColourst   rowLoct	   colLabelst
   colColourst   colLocR   R9   Rn   RC   t   rowst   colsRo   t   rowLabelWidtht   offsett   tableR   Rp   (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyR×   K  s†    				(    RG   t
   __future__R    R   R   R   R_   t	   six.movesR   Ra   t    R   R   R   t   patchesR   t
   matplotlibR	   R   R
   t
   transformsR   t   matplotlib.pathR   R   RH   R]   R   R×   t   interpdRB   t   kwdoc(    (    (    s/   lib/python2.7/site-packages/matplotlib/table.pyt   <module>   s*   "r<ÿ x		n