
Y]c           @` s  d  d l  m Z m Z m Z 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 Z d  d l Z d  d l Z d  d l Z d  d l m Z m Z d  d l m Z m Z 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$ g  Z% e j& j' d
  rd  d l m( Z( xA e( j)   D]3 Z* y# e% j+ e( j, e- e*   j.  Wn n XqWn yl e" e- d  d d g  Z/ e/ j0 d  Z/ g  e/ j1   D] Z* e* j2 d  d  ^ qZ% e3 e4 e%   Z% Wn e j5 d e6  n Xd   Z7 d   Z8 d   Z9 d d Z: d e: Z; d d Z< d e< Z= d Z> e j? e> d  Z@ e j? e> d  ZA d   ZB e j? e> d  ZC d   ZD d   ZE d   ZF d    ZG d!   ZH d" eI f d#     YZJ d$ eK f d%     YZL d& eK f d'     YZM d( e f d)     YZN d* e f d+     YZO d, eK f d-     YZP d. e f d/     YZQ d0 e f d1     YZR e jS d2 e f d3     Y ZT d4   ZU e jV eU  d S(5   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   _pngt   rcParams(   t   _Backendt   FigureCanvasBaset   FigureManagerBaset   GraphicsContextBaset   RendererBase(   t   MixedModeRenderer(   t   is_writable_file_like(   t
   subprocess(   t   check_output(   t   Pathu   win(   t   font_manageru   fc-listu   :outline,scalableu   familyu   utf8u   ,u    error getting fonts from fc-listc          C` s-   d d d g }  t  d } | |  k r) | Sd S(   u   Get chosen TeX system from rc.u   xelatexu   lualatexu   pdflatexu   pgf.texsystem(   R   (   t   texsystem_optionst	   texsystem(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   get_texcommand4   s    
c          C` s   g  }  t    } | d k r+ |  j d  n  | d k r t d r d d d g } d d d	 g } xk t | |  D]W \ } } g  t d
 | D] } | t k r | ^ q } | ro |  j | | d  qo qo Wn  d j |   S(   u    Build fontspec preamble from rc.u   pdflatexu   \usepackage{fontspec}u   pgf.rcfontsu   serifu
   sans-serifu	   monospaceu   \setmainfont{%s}u   \setsansfont{%s}u   \setmonofont{%s}u   font.i    u   
(   R   t   appendR   t   zipt   system_fontst   join(   t   latex_fontspect
   texcommandt   familiest	   fontspecst   familyt   fontspect   ft   matches(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   get_fontspec;   s    		c           C` s   d j  t d  S(   u   Get LaTeX preamble from rc.u   
u   pgf.preamble(   R   R   (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   get_preambleS   s    g      ?gzGR@g      R@u   (?<!\\)(?:\\\\)*u   \$u   ([_^$%])c         C` s   d |  j  d  S(   Nu   \i   (   t   group(   t   m(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   <lambda>g   t    u   (\\mathdefault)c         C` s!   |  j  d  t |  j  d    S(   Ni    i   (   R"   t   len(   R#   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR$   i   R%   c         C` s~   t  j t |   }  t j |   } xM t |  D]? \ } } | d sY t j t |  } n
 d | } | | | <q. Wd j |  S(   uh   
    Do some necessary and/or useful substitutions for texts to be included in
    LaTeX documents.
    i   u   \(\displaystyle %s\)u    (	   t   re_mathdefaultt   subt   repl_mathdefaultt
   re_mathsept   splitt	   enumeratet   re_escapetextt   repl_escapetextR   (   t   textt   partst   it   s(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   common_texificationl   s    

c         C` s   |  j  |  |  j  d  d  S(   Nu   %
(   t   write(   t   fht   line(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   writeln   s    c         C` s7  g  } i d d 6d d 6d d 6d d 6} |  j    d } | | k rX | j | |  n/ | t k r t   d	 k r | j d
 |  n  |  j   } | j d | | d f  i d d 6d d 6d d 6} | j | |  j    d d d d d d d g } |  j   | k r| j d  n  | j d  d j |  S(   Nu	   \rmfamilyu   serifu	   \sffamilyu   sansu
   sans-serifu	   \ttfamilyu	   monospacei    u   pdflatexu   \setmainfont{%s}\rmfamilyu   \fontsize{%f}{%f}g333333?u    u   normalu   \itshapeu   italicu   \slshapeu   obliqueu   semiboldu   demiboldu   demiu   boldu   heavyu
   extra boldu   blacku	   \bfseriesu   \selectfont(   t
   get_familyR   R   R   t   get_size_in_pointst	   get_stylet
   get_weightR   (   t   propt   commandsR   R   t   sizet   stylest
   boldstyles(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   _font_properties_str   s$    c          ` s   g  }  y0 t  t d  d g d t j |  j d  Wn n Xt j   \   }   rh |  j d  n  d |  k r d   } | Sd |  k r   f d   } | St d   d S(	   uD   
    Returns a function that converts a pdf file to a png file.
    u
   pdftocairou   -vt   stderru   gsc         S` sL   t  d  d d d d | |  t j j |  d g } t | d t j d  S(   Nu
   pdftocairou   -singlefileu   -pngu   -ru   %di    RB   (   t   strt   ost   patht   splitextR   R   t   STDOUT(   t   pdffilet   pngfilet   dpit   cmd(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   cairo_convert   s    c         ` sU   t     d d d d d d d d d	 d
 d | d | |  g } t | d t j d  S(   Nu   -dQUIETu   -dSAFERu   -dBATCHu	   -dNOPAUSEu
   -dNOPROMPTu   -dUseCIEColoru   -dTextAlphaBits=4u   -dGraphicsAlphaBits=4u   -dDOINTERPOLATEu   -sDEVICE=png16mu   -sOutputFile=%su   -r%dRB   (   RC   R   R   RG   (   RH   RI   RJ   RK   (   t   gs(    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt
   gs_convert   s    	
u&   No suitable pdf to png renderer found.N(   R   RC   R   RG   R   t   mplt   checkdep_ghostscriptt   RuntimeError(   t   tools_availablet   verRL   RN   (    (   RM   s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   make_pdf_to_png_converter   s     	t
   LatexErrorc           B` s   e  Z d  d  Z RS(   u    c         C` s   t  j |  |  | |  _ d  S(   N(   t	   Exceptiont   __init__t   latex_output(   t   selft   messageRX   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyRW      s    (   t   __name__t
   __module__RW   (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyRU      s   t   LatexManagerFactoryc           B` s   e  Z d Z e d     Z RS(   c          C` s   t    }  t j   } t j } | r] | j | k r] | j |  k r] t d rY t d  n  | St d rt t d  n  t   } | t _ | Sd  S(   Nu	   pgf.debugu   reusing LatexManageru   creating LatexManager(	   R   t   LatexManagert   _build_latex_headerR]   t   previous_instancet   latex_headerR   R   t   print(   R   Ra   t   prevt   new_inst(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   get_latex_manager   s    		

		N(   R[   R\   t   NoneR`   t   staticmethodRe   (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR]      s   R^   c           B` sw   e  Z d  Z e j   Z e d    Z e d    Z d   Z	 d   Z
 d   Z d   Z d   Z d   Z d	   Z RS(
   u   
    The LatexManager opens an instance of the LaTeX application for
    determining the metrics of text elements. The LaTeX environment can be
    modified by setting fonts and/or a custem preamble in the rc parameters.
    c          C` s7   t    }  t   } d |  | d d d g } d j |  S(   Nu   \documentclass{minimal}u   \begin{document}u   text $math \mu$u!   \typeout{pgf_backend_query_start}u   
(   R!   R    R   (   t   latex_preambleR   Ra   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR_      s    			c          C` s.   t  t j  }  x |  D] } | j   q Wd  S(   N(   t   listR^   t   _unclean_instancest   _cleanup(   t   unclean_instancest   latex_manager(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   _cleanup_remaining_instances  s    c         C` s1   |  j  j |  |  j  j d  |  j  j   d  S(   Nu   
(   t   latex_stdin_utf8R4   t   flush(   RY   R2   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   _stdin_writeln  s    c         C` s   | j  d  } t   } xk t r |  j j j d  } | | 7} | t |  | k r[ Pn  t |  s t d | j d    q q W| j d  S(   Nu   utf8i   u   LaTeX process halted(	   t   encodet	   bytearrayt   Truet   latext   stdoutt   readR&   RU   t   decode(   RY   R2   t   expt   buft   b(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   _expect  s    		
c         C` s   |  j  d  S(   Nu   
*(   R|   (   RY   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   _expect_prompt  s    c         C` s  t  j |  _ t |  _ t d |  _ t j d d  |  _	 t
 j j |   t   |  _ t
 j   |  _ d } y= t j t |  j  d g d t j d t j d |  j	 } WnN t k
 r } | j t j k r t d	 |  j   q t d
 |  j   n X|  j | } | j | j d   \ } } | j d k rCt d |   n  t j t |  j  d g d t j d t j d |  j	 } | |  _ t j d  |  j j   |  _! |  j" |  j    |  j# d  |  j$   i  |  _% d  S(   Nu	   pgf.debugt   prefixu   mpl_pgf_lm_u   
\makeatletter
\@@end
u   -halt-on-errort   stdinRv   t   cwduS   Latex command not found. Install %r or change pgf.texsystem to the desired command.u   Error starting process %ru   utf-8i    uG   LaTeX returned an error, probably missing font or error in preamble:
%su   utf8u   *pgf_backend_query_start(&   RD   RE   t   _os_patht   shutilt   _shutilR   t   _debugt   tempfilet   mkdtempt   tmpdirR^   Rj   t   addR   R   R_   Ra   R   t   PopenRC   t   PIPEt   OSErrort   errnot   ENOENTRQ   t   communicateRr   t
   returncodeRU   Ru   t   codecst	   getwriterR   Ro   Rq   R|   R}   t	   str_cache(   RY   t	   latex_endRu   t   et
   test_inputRv   RB   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyRW     sD    				
c         C` s   |  j  j |  j  s d  Sy. |  j j   |  j j   |  j j j   Wn n Xy' |  j j	 |  j  t
 j j |   Wn t j j d |  j  n Xd  S(   Nu    error deleting tmp directory %s
(   R   t   isdirR   Ru   R   Ro   t   closeRv   R   t   rmtreeR^   Rj   t   discardt   sysRB   R4   (   RY   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyRk   L  s    c         C` s$   |  j  r t d  n  |  j   d  S(   Nu   deleting LatexManager(   R   Rb   Rk   (   RY   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   __del__[  s    	c         C` su  t  |  } d | | f } | |  j k r6 |  j | S|  j |  y |  j   Wn. t k
 r } t d j | | j    n X|  j d  y |  j   } Wn. t k
 r } t d j | | j    n Xy& | j   d j	 d  \ } } }	 Wn t d j | |    n Xt
 | d   t
 | d   t
 |	 d   }
 } } |
 | | | f |  j | <|
 | | | f S(   uy   
        Get the width, total height and descent for a text typesetted by the
        current LaTeX environment.
        u   \sbox0{%s %s}u&   Error processing '{}'
LaTeX Output:
{}u$   \typeout{\the\wd0,\the\ht0,\the\dp0}i    u   ,i(   RA   R   Rq   R}   RU   t
   ValueErrort   formatRX   t
   splitlinesR+   t   float(   RY   R/   R<   t	   prop_cmdst   textboxR   t   answert   widtht   heightt   offsett   wt   ht   o(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   get_width_height_descent`  s0    		&	2(   R[   R\   t   __doc__t   weakreft   WeakSetRj   Rg   R_   Rn   Rq   R|   R}   RW   Rk   R   R   (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR^      s   				0		t   RendererPgfc           B` s   e  Z e d   Z d d  Z d d  Z d   Z d   Z d d  Z	 e
 e d  Z d   Z d   Z d d	  Z d
 d d  Z e d d  Z d   Z d   Z d   Z d   Z d   Z RS(   c         C` s   t  j |   | j |  _ | |  _ | |  _ d |  _ t j   |  _ | r d   } x| t	 j
 D]% } | j d  r\ | |  j
 | <q\ q\ WnI t | d  s t j j | j  r t j d t  d   |  j
 d <n  d S(	   u  
        Creates a new PGF renderer that translates any drawing instruction
        into text commands to be interpreted in a latex pgfpicture environment.

        Attributes
        ----------
        figure : `matplotlib.figure.Figure`
            Matplotlib figure to initialize height, width and dpi from.
        fh : file-like
            File handle for the output of the drawing commands.

        i    c          _` s   d  S(   N(   Rf   (   t   argst   kwargs(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR$     R%   u   draw_u   nameuX   streamed pgf-code does not support raster graphics, consider using the pgf-to-pdf optionc          _` s   d  S(   N(   Rf   (   R   R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR$     R%   u
   draw_imageN(   R
   RW   RJ   R5   t   figuret   image_counterR]   Re   t   latexManagerR   t   __dict__t
   startswitht   hasattrRD   RE   t   existst   namet   warningst   warnt   UserWarning(   RY   R   R5   t   dummyt   nopR#   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyRW     s    				&	c         C` s  t  |  j d  d |  j } |  j |  |  j | |  | j |  j   \ } }	 | d | | d | |	 d | |	 d | f }
 t  |  j d |
  |  j d  | |  |  j	 d | j
   d k d | d  k	  t  |  j d	  x | j | d
 t D]s \ } } | d | | d | } } t  |  j d  t  |  j d | | f  t  |  j d  t  |  j d  q Wt  |  j d  d  S(   Nu   \begin{pgfscope}g      ?i    i   uQ   \pgfsys@defobject{currentmarker}{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{t   strokeg        t   fillu   }t   simplifyu"   \pgfsys@transformshift{%fin}{%fin}u"   \pgfsys@useobject{currentmarker}{}u   \end{pgfscope}(   R7   R5   RJ   t   _print_pgf_clipt   _print_pgf_path_stylest   get_extentst
   get_pointst   _print_pgf_pathRf   t   _pgf_path_drawt   get_linewidtht   iter_segmentst   False(   RY   t   gct   marker_patht   marker_transRE   t   transt   rgbFaceR   t   blt   trt   coordst   pointt   codet   xt   y(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   draw_markers  s(    2	"c         C` s  t  |  j d  |  j |  |  j | |  |  j | | | |  |  j d | j   d k d | d  k	  t  |  j d  | j   rt  |  j d  |  j | |  |  j |  |  j | | | |  t  |  j d  t  |  j d  t  |  j d  t  |  j d  t  |  j d  t	 j
 j   j |  j  } |  j d  | j   |  |  j d t  t  |  j d  t  |  j d	  d
 |  j } | j |  j   \ \ } } \ }	 }
 | | | |	 } }	 | | | |
 } }
 t t j |	 |   t t j |
 |   } } t  |  j d | | f  xo t |  D]a } x4 t |  D]& } t  |  j d  t  |  j d  qIWt  |  j d |  t  |  j d  q6Wt  |  j d  n  d  S(   Nu   \begin{pgfscope}R   g        R   u   \end{pgfscope}u   \pgfusepath{clip}uN   \pgfsys@defobject{currentpattern}{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}{u=   \pgfpathrectangle{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}u   }g      ?u"   \pgfsys@transformshift{%fin}{%fin}u#   \pgfsys@useobject{currentpattern}{}u    \pgfsys@transformshift{1in}{0in}u"   \pgfsys@transformshift{-%din}{0in}u    \pgfsys@transformshift{0in}{1in}(   R7   R5   R   R   R   R   R   Rf   t	   get_hatchRO   t
   transformst   Affine2Dt   scaleRJ   t   get_hatch_pathRt   R   R   t   intt   matht   ceilt   range(   RY   R   RE   t	   transformR   R   R   t   xmint   ymint   xmaxt   ymaxt   repxt   repyt   iyt   ix(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt	   draw_path  sL    		'3	c         C` s   d |  j  } | j   } | r | j   \ } } | | \ } } | d | | d | | | | | f } t |  j d |  t |  j d  n  | j   \ }	 }
 |	 d  k	 r |  j | |	 |
  t |  j d  n  d  S(   Ng      ?i    i   uA   \pgfpathrectangle{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}u   \pgfusepath{clip}(   RJ   t   get_clip_rectangleR   R7   R5   t   get_clip_pathRf   R   (   RY   R   R   t   bboxt   p1t   p2R   R   R   t   clippatht   clippath_trans(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR     s    *	c         C` s  i d d 6d d 6d d 6} t  |  j | | j    i d d 6d	 d 6d
 d 6} t  |  j | | j    | d  k	 } | j   r | j   } } n8 | j   d } | r t |  d k r | d n d } | rt  |  j d t	 | d    t  |  j d  n  | r-| d k r-t  |  j d |  n  | j
   t t } | j   }	 t  |  j d |  t  |  j d |	 d   t  |  j d  | d k rt  |  j d |  n  | j   \ }
 } | d  k rt  |  j d  n- t  |  j d d j d   | D  |
 f  d  S(   Nu   \pgfsetbuttcapu   buttu   \pgfsetroundcapu   roundu   \pgfsetrectcapu
   projectingu   \pgfsetmiterjoinu   miteru   \pgfsetroundjoinu   \pgfsetbeveljoinu   beveli   g      ?u(   \definecolor{currentfill}{rgb}{%f,%f,%f}u   \pgfsetfillcolor{currentfill}u   \pgfsetfillopacity{%f}u   \pgfsetlinewidth{%fpt}u*   \definecolor{currentstroke}{rgb}{%f,%f,%f}u!   \pgfsetstrokecolor{currentstroke}u   \pgfsetstrokeopacity{%f}u   \pgfsetdash{}{0pt}u   \pgfsetdash{%s}{%fpt}u    c         s` s   |  ] } d  | Vq d S(   u   {%fpt}N(    (   t   .0t   dash(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pys	   <genexpr>K  s    (   R7   R5   t   get_capstylet   get_joinstyleRf   t   get_forced_alphat	   get_alphat   get_rgbR&   t   tupleR   t   mpl_pt_to_int   latex_in_to_ptt
   get_dashesR   (   RY   R   R   t	   capstylest
   joinstylest   has_fillt   fillopacityt   strokeopacityt   lwt   stroke_rgbat   dash_offsett	   dash_list(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR     sH    



(			c         C` s   d |  j  } | r | j   n d  } | rn | d  k rn | j   \ } } | d | d | d | d f }	 n d  }	 x| j | d |	 D]\ }
 } | t j k r t |
  \ } } t |  j	 d | | | | f  q | t j
 k r t |  j	 d  q | t j k rDt |
  \ } } t |  j	 d | | | | f  q | t j k rt |
  \ } } } } | | | | | | | | f } t |  j	 d |  q | t j k r t |
  \ } } } } } } | | | | | | | | | | | | f } t |  j	 d	 |  q q Wd  S(
   Ng      ?i    i   t   clipu&   \pgfpathmoveto{\pgfqpoint{%fin}{%fin}}u   \pgfpathcloseu&   \pgfpathlineto{\pgfqpoint{%fin}{%fin}}uH   \pgfpathquadraticcurveto{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}uW   \pgfpathcurveto{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}(   RJ   R   Rf   R   R   R   t   MOVETOR   R7   R5   t	   CLOSEPOLYt   LINETOt   CURVE3t   CURVE4(   RY   R   RE   R   R   R   R   R   R   R  t   pointsR   R   R   t   cxt   cyt   pxt   pyR   t   c1xt   c1yt   c2xt   c2y(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR   N  s>    %"		"	0	c         C` sS   g  } | r | j  d  n  | r2 | j  d  n  t |  j d d j |   d  S(   Nu   strokeu   fillu   \pgfusepath{%s}u   ,(   R   R7   R5   R   (   RY   R   R   t   actions(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR   v  s    c         C` s   t  S(   uA   
        pgf backend supports affine transform of image.
        (   Rt   (   RY   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   option_scale_image~  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   (   RY   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   option_image_nocomposite  s    c      
   C` s  | j  d  \ } } | d k s+ | d k r/ d  St j j |  j j  } t j j t j j |  j j   d }	 d |	 |  j f }
 |  j d 7_ t	 j
 | d  d  d  t j j | |
   t |  j d  |  j |  d |  j } | d  k r-t |  j d | | | | f  | | | | } } nt | j   j   \ } } } } } } t |  j d	 | | | | | | | | | | | | | | f  d } } t | d  k  j   } t |  j d
 | | | |
 f  t |  j d  d  S(   Ni   i    u   %s-img%d.pngi   iu   \begin{pgfscope}g      ?u"   \pgfsys@transformshift{%fin}{%fin}u/   \pgfsys@transformcm{%f}{%f}{%f}{%f}{%fin}{%fin}uK   \pgftext[left,bottom]{\pgfimage[interpolate=%s,width=%fin,height=%fin]{%s}}u   \end{pgfscope}(   t   shapeRD   RE   t   dirnameR5   R   RF   t   basenameR   R   t	   write_pngR   R7   R   RJ   Rf   t   frozent	   to_valuesRC   t   lower(   RY   R   R   R   t   imR   R   R   RE   t   fnamet	   fname_imgR   t   tr1t   tr2t   tr3t   tr4t   tr5t   tr6t   interp(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt
   draw_image  s4    (,	$	
	u   TeX!c	   	   	   C` s&   |  j  | | | | | | | |  d  S(   N(   t	   draw_text(	   RY   R   R   R   R2   R<   t   anglet   ismatht   mtext(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   draw_tex  s    c	         C` s~  t  |  } t |  }	 d |	 | f } t |  j d  | j   }
 |
 d k r{ t |  j d |
  t |  j d |
  n  t | j    d  } | d k r t |  j d |  t |  j d	  t |  j d
  d | } n  d |  j j } g  } | r| d k s| j	   d k r| j
   d k r| j   j | j    \ } } | j d | |  | j d | |  i d d 6d d 6d d 6} i d d 6d d 6d d 6d d 6} | j | | j    | j | | j
    nD | j d | |  | j d | |  | j d  | j d  | d k rG| j d |  n  t |  j d d j |  | f  t |  j d  d  S(   Nu   %s %su   \begin{pgfscope}g      ?u   \pgfsetfillopacity{%f}u   \pgfsetstrokeopacity{%f}i   i    u&   \definecolor{textcolor}{rgb}{%f,%f,%f}u   \pgfsetstrokecolor{textcolor}u   \pgfsetfillcolor{textcolor}u   \color{textcolor}u   anchoru   center_baselineu   x=%finu   y=%finu   leftu   rightu    u   centeru   topu   bottomu   baseu   baselineu	   rotate=%fu   \pgftext[%s]{%s}u   ,u   \end{pgfscope}(   i    i    i    (   R3   RA   R7   R5   R   R   R   R   RJ   t   get_rotation_modet   get_vat   get_transformt   transform_pointt   get_positionR   t   get_haR   (   RY   R   R   R   R2   R<   R)  R*  R+  R   t   alphat   rgbR   t	   text_argst   halignt   valign(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR(    sH    !#c         C` sP   t  |  } |  j j | |  \ } } } t |  j } | | | | | | f S(   N(   R3   R   R   R   RJ   (   RY   R2   R<   R*  R   R   t   dR   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   get_text_width_height_descent  s    c         C` s   t  S(   N(   R   (   RY   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   flipy  s    c         C` s   |  j  j   |  j  j   f S(   N(   R   t   get_figwidtht   get_figheight(   RY   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   get_canvas_width_height  s    c         C` s   | t  |  j S(   N(   R   RJ   (   RY   R
  (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   points_to_pixels  s    c         C` s   t    S(   N(   t   GraphicsContextPgf(   RY   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   new_gc  s    N(   R[   R\   R   RW   Rf   R   R   R   R   R   Rt   R   R  R  R'  R,  R(  R9  R:  R=  R>  R@  (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR     s"   %4		3(		"2				R?  c           B` s   e  Z RS(    (   R[   R\   (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR?    s   t   TmpDirCleanerc           B` s/   e  Z e   Z e d     Z e d    Z RS(   c         C` s   t  j j |   d  S(   N(   RA  t   remaining_tmpdirsR   (   R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyR     s    c          C` sG   x@ t  j D]5 }  y t j |   Wq
 t j j d |   q
 Xq
 Wd  S(   Nu    error deleting tmp directory %s
(   RA  RB  R   R   R   RB   R4   (   R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   cleanup_remaining_tmpdirs  s
    (   R[   R\   t   setRB  Rg   R   RC  (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyRA    s   	t   FigureCanvasPgfc           B` sk   e  Z i d  d 6d d 6d d 6Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z	 d   Z
 RS(   u   LaTeX PGF pictureu   pgfu   LaTeX compiled PGF pictureu   pdfu   Portable Network Graphicsu   pngc         C` s   d S(   Nu   pdf(    (   RY   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   get_default_filetype  s    c         O` s  | j  d t  r> t |  j d  d t } |  j j |  d  Sd } d g } x( t   j   D] } | j	 d |  q] Wx( t
   j   D] } | j	 d |  q W| j	 d  d j |  } |  j j   |  j j   } }	 |  j j   }
 | j |  | j |  | j d  t | d  t | d	  t | d
  t | d | |	 f  t | d  | j d d   } t |  j | |	 |
 t |  j |  d | } |  j j |  t | d  t | d  t | d  d  S(   Nu   dryrunR   u  %% Creator: Matplotlib, PGF backend
%%
%% To include the figure in your LaTeX document, write
%%   \input{<filename>.pgf}
%%
%% Make sure the required packages are loaded in your preamble
%%   \usepackage{pgf}
%%
%% Figures using additional raster images can only be included by \input if
%% they are in the same directory as the main LaTeX file. For loading figures
%% from other directories you can use the `import` package
%%   \usepackage{import}
%% and then include the figures with
%%   \import{<path to file>}{<filename>.pgf}
%%
u)   %% Matplotlib used the following preambleu   %%   u   %%u   
u   \begingroupu   \makeatletteru   \begin{pgfpicture}u:   \pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}u&   \pgfusepath{use as bounding box, clip}u   bbox_inches_restoret   bbox_inches_restoreu   \end{pgfpicture}u   \makeatotheru	   \endgroup(   t   getR   R   R   Rf   Rt   t   drawR!   R   R   R    R   R;  R<  t   get_dpiR4   R7   t   popR   (   RY   R5   R   R   t   renderert   header_textt   header_info_preambleR6   R   R   RJ   t   _bbox_inches_restore(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   _print_pgf_to_fh  s@    		c         O` s   | j  d t  r) |  j d | |  d St | t j  rr t j | d d d  } |  j | | |  Wd QXnC t	 |  r t j
 d  |  } |  j | | |  n t d   d S(   u{   
        Output pgf commands for drawing the figure so it can be included and
        rendered in latex documents.
        u   dryrunNu   wt   encodingu   utf-8u   filename must be a path(   RH  R   RP  Rf   t
   isinstancet   sixt   string_typesR   t   openR   R   R   (   RY   t   fname_or_fhR   R   R5   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt	   print_pgfS  s    c         O` s  |  j  j   |  j  j   } } zSt j d d  } t j j | d  } t j j | d  } t j j | d  }	 |  j | | |  t	   }
 t
   } d | | |
 | f } t j | d d   } | j |  Wd  QXt   } t |  d	 d
 d g } y t | d t j d | Wn/ t j k
 rH} t d | | j f   n Xt |	 d   } t j | |  Wd  QXWd  y t j |  Wn t j |  n XXd  S(   NR~   u   mpl_pgf_u
   figure.pgfu
   figure.texu
   figure.pdfu   
\documentclass[12pt]{minimal}
\usepackage[paperwidth=%fin, paperheight=%fin, margin=0in]{geometry}
%s
%s
\usepackage{pgf}

\begin{document}
\centering
\input{figure.pgf}
\end{document}u   wu   utf-8u   -interaction=nonstopmodeu   -halt-on-errorRB   R   u3   %s was not able to process your file.

Full log:
%su   rb(   R   R;  R<  R   R   RD   RE   R   RW  R!   R    R   RU  R4   R   RC   R   R   RG   t   CalledProcessErrorRQ   t   outputR   t   copyfileobjR   RA  R   (   RY   R5   R   R   R   R   R   t	   fname_pgft	   fname_text	   fname_pdfRh   R   t	   latexcodet   fh_texR   t   cmdargsR   t   fh_src(    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   _print_pdf_to_fhf  s6    			c         O` s   | j  d t  r) |  j d | |  d St | t j  ri t | d   } |  j | | |  Wd QXn. t	 |  r |  j | | |  n t
 d   d S(   uE   
        Use LaTeX to compile a Pgf generated figure to PDF.
        u   dryrunNu   wbu-   filename must be a path or a file-like object(   RH  R   RP  Rf   RR  RS  RT  RU  Rb  R   R   (   RY   RV  R   R   R5   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt	   print_pdf  s    c   	      O` s   t    } z t j d d  } t j j | d  } t j j | d  } |  j | | |  | | | d |  j j t	 | d   } t
 j | |  Wd  QXWd  y t
 j |  Wn t j |  n XXd  S(   NR~   u   mpl_pgf_u
   figure.pdfu
   figure.pngRJ   u   rb(   RT   R   R   RD   RE   R   Rc  R   RJ   RU  R   RZ  R   RA  R   (	   RY   R5   R   R   t	   converterR   R]  t	   fname_pngRa  (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   _print_png_to_fh  s    	c         O` s   | j  d t  r) |  j d | |  d St | t j  ri t | d   } |  j | | |  Wd QXn. t	 |  r |  j | | |  n t
 d   d S(   uQ   
        Use LaTeX to compile a pgf figure to pdf and convert it to png.
        u   dryrunNu   wbu-   filename must be a path or a file-like object(   RH  R   RP  Rf   RR  RS  RT  RU  Rf  R   R   (   RY   RV  R   R   R5   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt	   print_png  s    c         C` s   t  |  j d  d t S(   NR   (   R   R   Rf   Rt   (   RY   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   get_renderer  s    (   R[   R\   t	   filetypesRF  RP  RW  Rb  Rc  Rf  Rg  Rh  (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyRE    s   

		:		0			t   FigureManagerPgfc           B` s   e  Z d    Z RS(   c         G` s   t  j |  |  d  S(   N(   R   RW   (   RY   R   (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyRW     s    (   R[   R\   RW   (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyRj    s   t   _BackendPgfc           B` s   e  Z e Z e Z RS(    (   R[   R\   RE  t   FigureCanvasRj  t   FigureManager(    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyRk    s   c           C` s   t  j   t j   d  S(   N(   R^   Rn   RA  RC  (    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   _cleanup_all  s    
(W   t
   __future__R    R   R   R   RS  t   atexitR   R   R   RD   t   reR   R   R   R   R   t
   matplotlibRO   R   R   t   matplotlib.backend_basesR   R   R   R	   R
   t!   matplotlib.backends.backend_mixedR   t   matplotlib.cbookR   t   matplotlib.compatR   t   matplotlib.compat.subprocessR   t   matplotlib.pathR   R   t   platformR   R   t   win32InstalledFontsR   R   t   get_fontRC   t   family_namet   fc_listRx   R   R+   Ri   RD  R   R   R   R    R!   t   latex_pt_to_inR   R   t   mpl_in_to_ptt	   NO_ESCAPEt   compileR*   R-   R.   R'   R)   R3   R7   RA   RT   RV   RU   t   objectR]   R^   R   R?  RA  RE  Rj  t   exportRk  Rn  t   register(    (    (    s>   lib/python2.7/site-packages/matplotlib/backends/backend_pgf.pyt   <module>   s   "(#,				



						& o		