
 m[c           @` s  d  d l  m Z m Z m Z m Z d  d l m Z d  d l Z d  d l m Z d  d l	 m
 Z
 d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l 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 m Z m Z 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( m) Z) d  d l* m+ Z+ d  d l, m- Z- d  d l m. Z. d  d l/ m0 Z0 m1 Z1 d  d l m2 Z2 e j3 e4  Z5 e Z6 d   Z7 e j8 d  Z9 d   Z: d   Z; d   Z< d e= f d     YZ> g  d  Z? i  d  Z@ i d d 6d d 6d d 6ZA d e f d      YZB d! e f d"     YZC d# e f d$     YZD d% ZE e jF d& e f d'     Y ZG d S((   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   OrderedDictN(   t   unichr(   t   xrange(   t   cbookt   __version__t   rcParams(   t   _Backendt   FigureCanvasBaset   FigureManagerBaset   RendererBase(   t   MixedModeRenderer(   t   is_writable_file_liket   maxdict(   t   rgb2hex(   t   findfontt   get_font(   t   LOAD_NO_HINTING(   t   MathTextParser(   t   Path(   t   _path(   t   Affine2Dt   Affine2DBase(   t   _pngc         C` s:   |  j  d d  }  |  j  d d  }  |  j  d d  }  |  S(   Nu   &u   &amp;u   <u   &lt;u   >u   &gt;(   t   replace(   t   s(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   escape_cdataL   s    u   -(?=-)c         C` s   t  |   }  t j d |   S(   Nu   - (   R   t   _escape_xml_commentt   sub(   R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   escape_commentS   s    c         C` s^   |  j  d d  }  |  j  d d  }  |  j  d d  }  |  j  d d  }  |  j  d	 d
  }  |  S(   Nu   &u   &amp;u   'u   &apos;u   "u   &quot;u   <u   &lt;u   >u   &gt;(   R   (   R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   escape_attribW   s    c         C` s   d j  |   j d  j d  S(   u   
    Create a short string representation of a float, which is %f
    formatting with trailing zeros and the decimal point removed.
    u   {0:f}u   0u   .(   t   formatt   rstrip(   t   x(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   short_float_fmt_   s    t	   XMLWriterc           B` sk   e  Z d    Z e d  Z i  d  Z d   Z d   Z d	 e d  Z	 d   Z
 d	 i  d  Z d   Z RS(
   c         C` sV   | j  |  _ t | d  r* | j |  _ n  d |  _ g  |  _ g  |  _ d d |  _ d  S(   Nu   flushi    u    i@   (   t   writet   _XMLWriter__writet   hasattrt   flusht   _XMLWriter__opent   _XMLWriter__tagst   _XMLWriter__datat   _XMLWriter__indentation(   t   selft   file(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   __init__m   s    			c         C` sv   |  j  r8 | r |  j d  n |  j d  d |  _  n  |  j rr d j |  j  } |  j t |   g  |  _ n  d  S(   Nu   >
u   >i    u    (   R+   R(   R-   t   joinR   (   R/   t   indentt   data(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   __flushv   s    		c         K` s  |  j    t |  } g  |  _ |  j j |  |  j |  j t |  j  d   |  j d |  | sm | r | j   } | j	 |  t
 t j |   } xU | D]J \ } } | d k s t |  } t |  } |  j d | | f  q q Wn  d |  _ t |  j  d S(   Ni   u   <%su    u    %s="%s"(   t   _XMLWriter__flushR   R-   R,   t   appendR(   R.   t   lent   copyt   updatet   sortedt   sixt	   iteritemsR!   R+   (   R/   t   tagt   attribt   extrat   kt   v(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   start   s"    
	!!	c         C` sB   |  j    |  j |  j t |  j    |  j d t |   d  S(   Nu   <!-- %s -->
(   R6   R(   R.   R8   R,   R    (   R/   t   comment(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyRD      s    
c         C` s   |  j  j |  d  S(   N(   R-   R7   (   R/   t   text(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR4      s    c         C` s   | rX |  j  s t d |   t |  |  j  d k sm t d |  j  d | f   n |  j  sm t d   |  j  j   } |  j r |  j |  n# |  j r d |  _ |  j d  d  S| r |  j |  j t	 |  j     n  |  j d |  d  S(   Nu   unbalanced end(%s)iu   expected end(%s), got %su   unbalanced end()i    u   />
u   </%s>
(
   R,   t   AssertionErrorR   t   popR-   R6   R+   R(   R.   R8   (   R/   R>   R3   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   end   s    			 c         C` s*   x# t  |  j  | k r% |  j   q Wd  S(   N(   R8   R,   RH   (   R/   t   id(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   close   s    c         K` s@   |  j  | | f |   | r, |  j |  n  |  j d t  d  S(   NR3   (   RC   R4   RH   t   False(   R/   R>   RE   R?   R@   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   element   s    c         C` s   d  S(   N(    (   R/   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR*      s    N(   t   __name__t
   __module__R1   t   TrueR6   RC   RD   R4   t   NoneRH   RJ   RL   R*   (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR&   l   s   			
	
			c         C` s   t  |   r t j   } x |  D] \ } } | d k rU | d k s | d k rU q n  | d k rs | d k rs q n  | d k r | d k r q n  | d k r t | t  r | j   } n  | j d | d j d	   | D  f  q W| j   Sd
 S(   Nu   scaleg      ?u	   translateg        u   rotateu   matrixu   %s(%s)u    c         s` s   |  ] } t  |  Vq d  S(   N(   R%   (   t   .0R$   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pys	   <genexpr>   s    u    (   g      ?(   g      ?g      ?(   g        g        (   g        (	   R8   t   iot   StringIOt
   isinstanceR   t	   to_valuesR'   R2   t   getvalue(   t   transform_listt   outputt   typet   value(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   generate_transform   s    $	%
c         C` s{   |  rw t  j   } t t j |    }  xC |  D]; \ } } t |  } t |  } | j d | | f  q. W| j   Sd S(   Nu   %s:%s;u    (   RR   RS   R;   R<   R=   R!   R'   RV   (   R?   RX   RA   RB   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   generate_css   s    
u   squareu
   projectingu   buttu   roundt   RendererSVGc           B` ss  e  Z d  Z e d  Z d% d d  Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d% d  Z d   Z d   Z d% d% d% d% d  Z d% d  Z d% d  Z d   Z d   Z d   Z d   Z d   Z d% d  Z d   Z d% d  Z  d% d  Z! d d% d   Z" e# d% d!  Z$ d"   Z% d#   Z& d$   Z' RS(&   g      Y@i2   iH   c         C` sk  | |  _  | |  _ t |  |  _ | |  _ i  |  _ t d sd | d  k	 sO t  | |  _	 i  |  _
 n  t   |  _ i  |  _ i  |  _ d |  _ i  |  _
 t   |  _ t |  _ d |  _ t   |  _ t d  |  _ t j |   t   |  _ t |  } t |  } | j t  |  j j d d d | d d | d d	 | | f d
 d d d d i d d 6|  _ |  j    d  S(   Nu   svg.image_inlinei    u   SVGu   svgt   widthu   %sptt   heightt   viewBoxu	   0 0 %s %st   xmlnsu   http://www.w3.org/2000/svgt   versionu   1.1R?   u   http://www.w3.org/1999/xlinku   xmlns:xlink(!   R^   R_   R&   t   writert	   image_dpit   _groupdR	   RP   RF   t   basenamet   _imagedR   t   _clipdt
   _char_defst   _markerst   _path_collection_idt   _hatchdRK   t   _has_gouraudt   _n_gradientst   _fontsR   t   mathtext_parserR   R1   t   dictt
   _glyph_mapR%   R'   t	   svgPrologRC   t	   _start_idt   _write_default_style(   R/   R^   R_   t	   svgwriterRf   Rd   t
   str_heightt	   str_width(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR1   
  sB    				
								

c         C` sB   |  j    |  j   |  j   |  j j |  j  |  j j   d  S(   N(   t   _write_clipst   _write_hatchest   _write_svgfontsRc   RJ   Rt   R*   (   R/   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   finalize/  s
    


c         C` sr   |  j  } t i d d 6d d 6 } | j d  | j d d d | j d	 |  | j d  | j d  d  S(
   Nu   roundu   stroke-linejoinu   buttu   stroke-linecapu   defsu   styleRY   u   text/cssu   *{%s}
(   Rc   R\   RC   R4   RH   (   R/   Rc   t   default_style(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyRu   6  s    	c         C` s   t  |  } t d d  k r1 t  t j    } n
 t d } t j re | j d  } | j d  } n  t j	   } | j
 |  | j
 |  d | | j   d  f S(   Nu   svg.hashsaltu   utf8u   %s%si
   (   t   strR	   RP   t   uuidt   uuid4R<   t   PY3t   encodet   hashlibt   md5R:   t	   hexdigest(   R/   RY   t   contentt   saltt   m(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   _make_idA  s    
	c         C` s&   | t    j d d  j d |  j  S(   Ng      ?g      g        (   R   t   scalet	   translateR_   (   R/   t	   transform(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   _make_flip_transformO  s    	c         C` sB   t  |  } t |  } | j   | j   } | j | d  | S(   Ng      R@(   R   R   t   cleart   get_size_in_pointst   set_size(   R/   t   propt   fnamet   fontt   size(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt	   _get_fontU  s    
c         C` s   | d k	 r t |  } n  | j   } | d k	 rB t |  } n  | j   | | f } |  j j |  } | d k r |  j d |  } | j   | | f | f |  j | <n | \ } } | S(   u,   
        Create a new hatch pattern
        u   hN(   RP   t   tuplet   get_hatch_colort	   get_hatchRl   t   getR   t   get_hatch_path(   R/   t   gct   rgbFacet   edget   dictkeyt   oidt   _(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt
   _get_hatch]  s    %c   	      C` s  t  |  j  s d  Sd } |  j } | j d  xvt j |  j  D]b\ \ } } } } | j d d | d d d d d	 d d
 t j |  d t j |  |  j | t   j	 |  j	 d d  j
 d |  d t } | d  k r d } n t |  } | j d d d d	 d d
 t j | d  d t j | d  d | | j d d | d t i t |  d 6t |  d 6t j t d  d 6d d 6d d 6 | j d  qB W| j d  d  S(   NiH   u   defsu   patternRI   t   patternUnitsu   userSpaceOnUseR$   u   0t   yR^   R_   g      ?g      i    t   simplifyu   noneu   recti   t   fillu   patht   dt   styleu   fillu   strokeu   hatch.linewidthu   stroke-widthu   buttu   stroke-linecapu   miteru   stroke-linejoin(   R8   Rl   Rc   RC   R<   t
   itervaluest	   text_typet   _convert_pathR   R   R   RK   RP   R   RL   R\   R	   RH   (	   R/   t
   HATCH_SIZERc   t   patht   facet   strokeR   t	   path_dataR   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyRz   o  sF    	(*		c   
      C` ss  i  } | j    } | j   d k	 r d |  j | |  | d <| d k	 rt |  d k r| d d k r| rt | d  | d <qn | d k r d | d <ni t | d   d k r t |  | d <n  t |  d k r| d d k r| rt | d  | d <n  | r@| j   d k r@t | j    | d	 <n  | j	   \ } } | d k	 rd
 j
 g  | D] } t |  ^ qk | d <t t |   | d <n  | j   } | ro| j   }	 t |	  | d <| r|	 d d k rt |	 d  | d <n  | d k rt |  | d <n  | j   d k rC| j   | d <n  | j   d k rot | j   | d <qon  | S(   uk   
        return the style string.  style is generated from the
        GraphicsContext and rgbFace
        u   url(#%s)u   filli   i   g      ?u   fill-opacityu   nonei    u   opacityu   ,u   stroke-dasharrayu   stroke-dashoffsetu   strokeu   stroke-opacityu   stroke-widthu   roundu   stroke-linejoinu   buttu   stroke-linecapN(   i    i    i    (   t   get_forced_alphaR   RP   R   R8   R%   R   R   t	   get_alphat
   get_dashesR2   t   floatt   get_linewidtht   get_rgbt   get_joinstylet   get_capstylet   _capstyle_d(
   R/   R   R   R?   t   forced_alphat   offsett   seqt   valt	   linewidtht   rgb(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   _get_style_dict  s>    5),c         C` s   t  |  j | |   S(   N(   R\   R   (   R/   R   R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt
   _get_style  s    c         C` s  | j    } | j   \ } } | d  k	 rT |  j |  } t |  t |  f } nK | d  k	 r | j \ } } } }	 |  j | |	 } | | | |	 f } n d  S|  j j	 |  }
 |
 d  k r|  j
 d |  } | d  k	 r | | f | f |  j | <q| | f |  j | <n |
 \ }
 } | S(   Nu   p(   t   get_clip_rectanglet   get_clip_pathRP   R   RI   R~   t   boundsR_   Rh   R   R   (   R/   R   t   cliprectt   clippatht   clippath_transR   R$   R   t   wt   ht   clipR   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt	   _get_clip  s$    c         C` s  t  |  j  s d  S|  j } | j d  x t j |  j  D] \ } } | j d d | t  |  d k r | \ } } |  j | | d t } | j d d | nO | \ } } }	 }
 | j d d	 t	 |  d
 t	 |  d t	 |	  d t	 |
  | j
 d  q< W| j
 d  d  S(   Nu   defsu   clipPathRI   i   R   u   pathR   u   rectR$   R   R^   R_   (   R8   Rh   Rc   RC   R<   R   R   RK   RL   R%   RH   (   R/   Rc   R   R   R   R   R   R$   R   R   R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyRy     s&    	c         C` s  t  d d k s d  S|  j } | j d  xVt j |  j  D]B\ } } t |  } | j d d  | j   } | j d d | d j	 d
  | j
 d d i | j d 6| j j   d 6d d 6d j d   | j D  d 6x | D] } | j | d t } | j   \ } }	 t | |	  }
 |  j |
  } | j
 d d | d i t |  d 6t | j d  d 6q W| j d  q= W| j d  d  S(   Nu   svg.fonttypeu   svgfontu   defsiH   u   fontRI   i   i    i   u	   mac_romanu	   font-faceR?   u   font-familyu
   font-styleu   72u   units-per-emu    c         s` s   |  ] } t  | d   Vq d S(   g      P@N(   R%   (   RQ   R$   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pys	   <genexpr>  s    u   bboxt   flagsu   glyphR   u   unicodeg      @u   horiz-adv-x(   i   i    i    i   (   R	   Rc   RC   R<   R=   Ro   R   R   t   get_sfntt   decodeRL   t   family_namet
   style_namet   lowerR2   t   bboxt	   load_charR   t   get_pathR   R   R   R%   t   linearHoriAdvanceRH   (   R/   Rc   t
   font_fnamet   charsR   t   sfntt   chart   glypht   vertst   codesR   R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR{     s<    	 
c         C` sj   | r |  j  j d d | nG |  j j | d  d |  j | <|  j  j d d d | |  j | f d S(   uv   
        Open a grouping element with label *s*. If *gid* is given, use
        *gid* as the id of the group.
        u   gRI   i    i   u   %s_%dN(   Rc   RC   Re   R   (   R/   R   t   gid(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt
   open_group  s     c         C` s   |  j  j d  d  S(   Nu   g(   Rc   RH   (   R/   R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   close_group$  s    c         C` s	   t  d S(   ul   
        return whether to generate a composite image from multiple images on
        a set of axes
        u   image.composite_image(   R	   (   R/   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   option_image_nocomposite'  s    c         C` sa   | r! d d |  j  |  j f } n d  } t j | | | | | d d d d d d g t  j d  S(	   Ng        i   t   Mt   Lt   Qt   Ct   zu   ascii(   R^   R_   RP   R   t   convert_to_stringRK   R   (   R/   R   R   R   R   t   sketch(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR   .  s    c      	   C` s(  |  j  |  } | d  k o* | j   d  k } | j o9 | } |  j | | d | d | d | j   } i  }	 |  j | |  |	 d <|  j |  }
 |
 d  k	 r d |
 |	 d <n  | j   d  k	 r |  j	 j
 d i | j   d 6 n  |  j	 j d	 d
 | d |	 | j   d  k	 r$|  j	 j d  n  d  S(   NR   R   R   u   styleu   url(#%s)u	   clip-pathu   au
   xlink:hrefu   pathR   R?   (   R   RP   R   t   should_simplifyR   t   get_sketch_paramsR   R   t   get_urlRc   RC   RL   RH   (   R/   R   R   R   R   t   trans_and_flipR   R   R   R?   t   clipid(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt	   draw_path8  s     #c         C` s-  t  | j  s d  S|  j } |  j | | t   j d d  d t } |  j | |  }	 | t |	  f }
 |  j	 j
 |
  } t d   t j |	  D  }	 | d  k r|  j d |
  } | j d  | j d d | d	 | d
 |	 | j d  | |  j	 |
 <n  i  } |  j |  } | d  k	 r5d | | d <n  | j d d | |  j |  } i d | d 6} d d |  j d |  j d f } x | j | d | d t D]t \ } } t  |  r| d \ } } t |  | d <t |  | d <|  j | |  | d <| j d d | qqW| j d  d  S(   Ng      ?g      R   c         S` s.   i  |  ]$ \ } } | j  d   r | |  q S(   u   stroke(   t
   startswith(   RQ   RA   RB   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pys
   <dictcomp>Y  s   	 	u   mu   defsu   pathRI   R   R   u   url(#%s)u	   clip-pathu   gR?   u   #%su
   xlink:hrefi    iH   R   iu   xu   yu   styleu   use(   R8   t   verticesRc   R   R   R   RK   R   R\   Rj   R   R<   R=   RP   R   RC   RL   RH   R   R   R^   R_   t   iter_segmentsR%   R   (   R/   R   t   marker_patht   marker_transR   t   transR   Rc   R   R   R   R   R?   R   R   R   R   t   codeR$   R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   draw_markersM  sD    		 	c          C` s  t  |  d k r% t  | d j  n d } |  j | | | | |  } | d | d | d | k  } | s t j |  | | | | | | | | |	 |
 | | |  S|  j } g  } | j d  x t |  j | | |   D] \ } \ } } t	 | j
    j d d  } |  j | | d t } d	 |  j | |  j d
 |  f } | j d d | d | | j |  q W| j d  xK|  j | | | | | | | | |	 |
 | | |  D]\ } } } } } |  j |  } | j   } | d  k	 r| j d d i | d 6n  | d  k	 r3| j d d i d | d 6n  i d | d 6t |  d 6t |  j |  d 6|  j | |  d 6} | j d d | | d  k	 r| j d  n  | d  k	 r| j d  qqW|  j d 7_ d  S(   Ni    i	   i   i   u   defsg      ?g      R   u	   C%x_%x_%su    u   pathRI   R   u   aR?   u
   xlink:hrefu   gu   url(#%s)u	   clip-pathu   #%su   xu   yu   styleu   usei   (   R8   R   t   _iter_collection_uses_per_pathR   t   draw_path_collectionRc   RC   t	   enumeratet   _iter_collection_raw_pathsR   t
   get_matrixR   R   RK   Rk   R   RL   R7   RH   t   _iter_collectionR   R   RP   R%   R_   R   (    R/   R   t   master_transformt   pathst   all_transformst   offsetst   offsetTranst
   facecolorst
   edgecolorst
   linewidthst
   linestylest   antialiasedst   urlst   offset_positiont   len_patht   uses_per_patht   should_do_optimizationRc   t
   path_codest   iR   R   R   R   t   xot   yot   path_idt   gc0R   R   t   urlR?   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR   v  sV    	+ 	"	"!c         C` s  |  j  } |  j sp t |  _ | j d d d | j d d i d d 6d d	 d
 d d d d d | j d  n  t j | d  d   d  d   f d d d } | d d k r d  S|  j |  } | j	 |  } | j d  xt
 d  D]}	 | |	 \ }
 } | |	 d d \ } } | |	 d d \ } } | |	 } | | k rW| } | } nu | | k rr|
 } | } nZ | | | | } | | | } d | } | | |
 } | | | | } | | | } | j d d d |  j |	 f d t |
  d t |  d t |  d t |  | j d d  d! d" t i t |  d# 6t | d  d$ 6 | j d d  d d" t i t |  d# 6d! d$ 6 | j d  q W| j d% d d& |  j d' d( j g  |
 | | | | | f D] } t |  ^ q | j d  t j | d  d   d  d   f d d d } d) |  j } | j d* d i | d+ 6t |  d, 6t | d  d- 6xP t
 d  D]B }	 | j d* d i | d+ 6d. |  j |	 f d, 6d d- 6d/ d 6qW|  j d 7_ d  S(0   Nu   filterRI   u   colorAddu   feCompositeR?   u   SourceGraphicu   int   in2u   BackgroundImaget   operatoru
   arithmetict   k2u   1t   k3t   axisi    g      @ig        u   defsi   i   i   g      ?u   linearGradientu   GR%x_%dt   x1t   y1t   x2t   y2u   stopR   u   0R   u
   stop-coloru   stop-opacityu   polygonu   GT%xt   pointsu    u   #GT%xu   useu
   xlink:hrefu   fillu   fill-opacityu   url(#GR%x_%d)u   url(#colorAdd)(   Rc   Rm   RO   RC   RL   RH   t   npt   sumR   R   t   rangeRn   R%   R\   R   R2   (   R/   R   R  t   colorsR   Rc   t	   avg_colorR   t   tpointsR  R  R  R  R  t   x3t   y3t   ct   xbt   ybt   m1t   b1t   m2t   b2R$   t   href(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   draw_gouraud_triangle  s    			/			2/

c   	      C` s   i  } |  j  |  } | d  k	 r2 d | | d <n  |  j j d d | | j   } x3 t | |  D]" \ } } |  j | | | |  qd W|  j j d  d  S(   Nu   url(#%s)u	   clip-pathu   gR?   (   R   RP   Rc   RC   t   frozent   zipR+  RH   (	   R/   R   t   triangles_arrayt   colors_arrayR   R?   R   t   trit   col(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   draw_gouraud_triangles  s    c         C` s   t  S(   N(   RO   (   R/   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   option_scale_image  s    c         C` s   |  j  d S(   Ng      R@(   Rd   (   R/   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   get_image_magnification"  s    c         C` si  | j  d  \ } } | d k s+ | d k r/ d  Si  } |  j |  }	 |	 d  k	 rt |  j j d d i d |	 d 6n  | j   }
 | j   } | d  k	 r |  j j d d i | d 6n  t d	 r%t j	   } t
 j | |  |
 p |  j d
 | j    }
 d t j | j    j d  | d <n |  j j |  j d  d |  j |  j <d |  j |  j |  j f } t j d |  t
 j | |  |
 pd |  j d
 |  }
 | | d <|
 | d <| d  k r`d | |  j } d | |  j } |  j j d
 d t d d! f d d | f f g  d t |  d t |  j | |  d t |  d t |  d | n | j   } | d k rt |  | d <n  t   j d | d |  | t   j | |  j d d  j d |  j  } t d | j   f g  | d  <|  j j d
 d t |  d t |  d | | d  k	 rF|  j j  d  n  |	 d  k	 re|  j j  d  n  d  S("   Ni   i    u   gR?   u   url(#%s)u	   clip-pathu   au
   xlink:hrefu   svg.image_inlineu   imageu   data:image/png;base64,
u   asciii   u   %s.image%d.pngu$   Writing image file for inclusion: %su   Im_u   idg      R@R   u   scaleiu	   translateR$   R   R^   R_   g      ?u   opacityg      g        u   matrixu	   transform(   i   i(!   t   shapeR   RP   Rc   RC   t   get_gidR   R	   RR   t   BytesIOR   t	   write_pngR   RV   t   base64t	   b64encodeR   Rg   R   Rf   t   _logt   infoRd   RL   R[   R%   R_   R   R   R   R   R,  RH   (   R/   R   R$   R   t   imR   R   R   R?   R   R   R  t   bytesiot   filenamet   alphat   flipped(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt
   draw_image%  sj    $ 
&&

	"
		c         C` s   | j  d d  S(   Nu   %20u   _(   R   (   R/   t   char_id(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   _adjust_char_idm  s    c	       	   C` s  |  j  }	 |	 j |  |  j }
 |  j } t | j    } | j   } i  } | d k re | | d <n  | j   d k r t | j    | d <n  | s]| j	 |  } | j
 | | d |
 d t } | \ } } } | r\|	 j d  xW t j |  D]F \ } } t |   } |  j | d t } |	 j d	 d
 | d | q W|	 j d  |
 j |  n  i  } t |  | d <| | j } t d | | f f d | f f d | | f f g  | d <|	 j d d | x| | D]t \ } } } } i d | d 6} | d k rt |  | d <n  | d k r6t |  | d <n  |	 j d d | qW|	 j d  nJ| d k r| j | | d |
 d t } n | j | | d |
 d t } | \ } } } | ri|	 j d  x t j |  D]n \ } } |  j |  } t | d  sd } n! t |   } |  j | d t } |	 j d	 d
 | d | qW|	 j d  |
 j |  n  i  } | | j } t |  | d <t d | | f f d | f f d | | f f g  | d <|	 j d d | xn | D]f \ } } } } |  j |  } |	 j d d t d | | f f d | f f g  d i d | d 6qWxK | D]C \ } } t | |  } |  j | d t } |	 j d	 d | qSW|	 j d  d S(   u  
        draw the text by converting them to paths using textpath module.

        Parameters
        ----------
        prop : `matplotlib.font_manager.FontProperties`
          font property

        s : str
          text to be converted

        usetex : bool
          If True, use matplotlib usetex mode.

        ismath : bool
          If True, use mathtext parser. If "TeX", use *usetex* mode.

        u   #000000u   fillg      ?u   opacityt	   glyph_mapt   return_new_glyphs_onlyu   defsR   u   pathRI   R   u   styleu	   translateu   rotateu   scaleu	   transformu   gR?   u   #%su
   xlink:hrefg        u   xu   yu   useu   TeXi    u    R   N(   Rc   RD   Rr   t
   _text2pathR   R   R   R   R%   R   t   get_glyphs_with_fontRO   RC   R<   R=   R   R   RK   RL   RH   R:   R\   t
   FONT_SCALER[   t   get_glyphs_text   get_glyphs_mathtextRD  R8   (    R/   R   R$   R   R   R   t   anglet   ismatht   mtextRc   RE  t	   text2patht   colort   fontsizeR   R   t   _glyphst
   glyph_infot   glyph_map_newt   rectsRC  t
   glyph_pathR   R   R?   t
   font_scalet   glyph_idt	   xpositiont	   ypositionR   R   R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   _draw_text_as_pathp  s    					c	   +      C` s  |  j  }	 t | j    }
 i  } |
 d k r: |
 | d <n  | j   d k re t | j    | d <n  | s.|  j |  } | j | d d t | j   } | j	 } | j
   } i  } t |  d | d <t j |  | d	 <| j
   j   | d
 <t j | j    j   | d <t |  | d <| r| d k sG| j   d k r| j   } | j | j    \ } } |  j | } t j |  } t j t j |  t j |  g  } t j | | | | | g  } | | | d } | | | d } i d d 6d d 6d d 6} | | j   | d <t |  | d <t |  | d <t |  | d <d t |  t |  t |  f | d <|	 j d | d | nB t d | | f f d | f f g  | d <|	 j d | d | t d d  k r|  j j  | j! t"    } x$ | D] } | j# t$ |   qWqnZ|	 j% |  |  j& j' | d! |  \ } } } } } | j( } | j) }  i  } t |  | d <t d | | f f d | f f g  | d <|	 j* d" d | |	 j* d  t+   }! x | D] \ } } }" }# }$ }% t i t |  d d 6| j	 d	 6| j, j   d
 6| j, j   d 6 } |" d# k rZd$ }" n  |! j  | g   j- |# |$ |" f  qWt d d  k rxK | D]@ \ } } }" }# }$ }% |  j j  | j! t"    } | j# |"  qWn  xt j. |!  D]\ } }& |& j/   t0 }' t1 |&  d k rl|& d d }( x> t2 d t1 |&   D]$ }) |& |) d |( k rAt3 }' PqAqAWn  |' rt j |& d d  }* n d% j4 d&   |& D  }* i | d 6d% j4 d'   |& D  d 6|* d 6} |	 j d( d) j4 d*   |& D  d | qW|	 j5 d  t1 |   r{x_ |  D]T \ } } } } |	 j d+ d, t |  d- t | |  d. t |  d/ t |  q Wn  |	 j5 d"  d  S(0   Nu   #000000u   fillg      ?u   opacityg        R   u   pxu	   font-sizeu   font-familyu
   font-styleu   font-weightu   stylei    u   anchori   u   startu   leftu   endu   rightu   middleu   centeru   text-anchoru   xu   yu   rotate(%s, %s, %s)u	   transformu   textR?   u	   translateu   rotateu   svg.fonttypeu   svgfontiH   u   gi    i   u    c         s` s"   |  ] } t  j | d   Vq d S(   i   N(   R<   R   (   RQ   R#  (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pys	   <genexpr>f  s    c         s` s   |  ] } t  | d   Vq d S(   i    N(   R%   (   RQ   R#  (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pys	   <genexpr>j  s    u   tspanu    c         s` s   |  ] } t  | d   Vq d S(   i   N(   R   (   RQ   R#  (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pys	   <genexpr>p  s    u   rectR$   R   R^   R_   (6   Rc   R   R   R   R%   R   t   set_textR   R   R   t	   get_styleR<   R   R   t
   get_weightR\   t   get_rotation_modet   get_transformt   transform_pointt   get_positionR_   R  t   deg2radt   arrayt   sint   cost   dott   get_haRL   R[   R	   Ro   t
   setdefaultR   t   sett   addt   ordRD   Rp   t   parset
   svg_glyphst	   svg_rectsRC   R   R   R7   R=   t   sortRO   R8   R   RK   R2   RH   (+   R/   R   R$   R   R   R   RL  RM  RN  Rc   RP  R   R   RQ  t
   fontfamilyt	   fontstyleR?   R   t   axt   ayt	   angle_radt   dir_vertt   v_offsett   ha_mpl_to_svgt   fontsetR#  R^   R_   t   descentt   svg_elementst   used_charactersRn  Ro  t   spanst   thetextt   new_xt   new_yt   metricsR   t   same_yt   last_yR  t   ys(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   _draw_text_as_text  s    		$' 

	'			
	'

u   TeX!c	   	   	   C` s&   |  j  | | | | | | d d d  S(   NRM  u   TeX(   R[  (	   R/   R   R$   R   R   R   RL  RM  RN  (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   draw_tex  s    c	   
   	   C` s  |  j  |  }	 |	 d  k	 r? |  j j d d i d |	 d 6n  | j   d  k	 rt |  j j d i | j   d 6 n  t d d k r |  j | | | | | | | |  n" |  j | | | | | | | |  | j   d  k	 r |  j j d  n  |	 d  k	 r|  j j d  n  d  S(	   Nu   gR?   u   url(#%s)u	   clip-pathu   au
   xlink:hrefu   svg.fonttypeu   path(	   R   RP   Rc   RC   R   R	   R[  R  RH   (
   R/   R   R$   R   R   R   RL  RM  RN  R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt	   draw_text  s    	#%"c         C` s   t  S(   N(   RO   (   R/   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   flipy  s    c         C` s   |  j  |  j f S(   N(   R^   R_   (   R/   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   get_canvas_width_height  s    c         C` s   |  j  j | | |  S(   N(   RG  t   get_text_width_height_descent(   R/   R   R   RM  (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR    s    N((   RM   RN   RI  R   t   fontdRP   R1   R|   Ru   R   R   R   R   Rz   R   R   R   Ry   R{   R   R   R   R   R   R   R   R+  R2  R3  R4  RB  RD  R[  R  R  RK   R  R  R  R  (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR]     sH   %							(	-				$				)	:	`			H	~		t   FigureCanvasSVGc           B` sF   e  Z i d  d 6d  d 6Z d Z d   Z d   Z d   Z d   Z RS(   u   Scalable Vector Graphicsu   svgu   svgziH   c         O` s   t  j | d d d  } t | d d  } t | t j  sH d } n  t  j |  r` t } n9 t j r~ t	 j
 | d  } n t j d  |  } t } |  j | | |  } | r t j r | j   q | j   t	 j   | _ n  Wd  QX| S(   Nu   wt   encodingu   utf-8u   nameu    (   R   t   open_file_cmt   getattrRT   R<   t   string_typest   file_requires_unicodeRK   R   RR   t   TextIOWrappert   codecst	   getwriterRO   t
   _print_svgt   detacht   resetR7  t   stream(   R/   R?  t   argst   kwargst   fhR  t   result(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt	   print_svg  s"    				
c      
   O` sM   t  j | d  5 } t j d d d |   } |  j |  SWd  QXWd  QXd  S(   Nu   wbt   modeu   wt   fileobj(   R   R  t   gzipt   GzipFileR  (   R/   R?  R  R  R  t
   gzipwriter(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt
   print_svgz  s    c         K` s   | j  d d  } |  j j d  |  j j   \ } } | d | d } } | j  d d   }	 t |  j | | | t | | | | |  d |	 }
 |  j j |
  |
 j   d  S(   Nu   dpiiH   g      R@u   bbox_inches_restoret   bbox_inches_restore(	   RG   t   figuret   set_dpit   get_size_inchesRP   R   R]   t   drawR|   (   R/   R?  R  R  Rd   R^   R_   R   R   t   _bbox_inches_restoret   renderer(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR    s    	c         C` s   d S(   Nu   svg(    (   R/   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   get_default_filetype  s    (   RM   RN   t	   filetypest	   fixed_dpiR  R  R  R  (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR    s   

			t   FigureManagerSVGc           B` s   e  Z RS(    (   RM   RN   (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR    s   u   <?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Created with matplotlib (http://matplotlib.org/) -->
t   _BackendSVGc           B` s   e  Z e Z e Z RS(    (   RM   RN   R  t   FigureCanvasR  t   FigureManager(    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyR    s   (H   t
   __future__R    R   R   R   t   collectionsR   R<   R   t	   six.movesR   R9  R  R  R   RR   t   loggingt   reR   t   numpyR  t
   matplotlibR   R   R	   t   matplotlib.backend_basesR
   R   R   R   t!   matplotlib.backends.backend_mixedR   t   matplotlib.cbookR   R   t   matplotlib.colorsR   t   matplotlib.font_managerR   R   t   matplotlib.ft2fontR   t   matplotlib.mathtextR   t   matplotlib.pathR   R   t   matplotlib.transformsR   R   R   t	   getLoggerRM   R;  t   backend_versionR   t   compileR   R    R!   R%   t   objectR&   R[   R\   R   R]   R  R  Rs   t   exportR  (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_svg.pyt   <module>   sZ   ""'				|   :		