+
    i                     @   ^ RI t ^ RIt^ RIt^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIHt ^ RIt^ RIHt ^ RIt^ RIHtHt ^ RIHtHtHtHt ^ RIHt ^ RIHtHt ^ R	IH t  ^ R
I!H"t" ^ RI#H$t$ ^ RI%H&t& ]PN                  ! ](4      t)Rt*R t+R"t,R],,          t-R#t.R].,          t/R t0R t1R t2R t3R t4 ! R R]54      t6 ! R R4      t7]Pp                  ! ^4      R 4       t9 ! R R]4      t: ! R R]4      t;]t<]Pz                   ! R R]4      4       t> ! R  R!4      t?R# )$    N)BytesIO)TemporaryDirectory)Image)cbookfont_manager)_BackendFigureCanvasBaseFigureManagerBaseRendererBase)MixedModeRenderer)_create_pdf_info_dict_datetime_to_pdf)Path)Figure)FontProperties)Gcfz\documentclass{article}c                    \        \        P                  R,          R7      P                  4       p RP	                  RRRRV ,          RR	V R
V ,          3,          RR\        P                  R,          .	\        P                  R,          '       d   RR.\        . ROR Uu. uF-  p\        P                  ! \        P                  ! V4      4      NK/  	  up4       UUu. uF6  w  r#RV: RVP                  : RVP                  P                  4       : R2NK8  	  upp,           R.,           M. O\        P                  P                  RRR7      N4      # u upi u uppi )z=Prepare a LaTeX preamble based on the rcParams configuration.z	font.size)size
z\def\mathdefault#1{#1}z4\everymath=\expandafter{\the\everymath\displaystyle}z\IfFileExists{scrextend.sty}{z'  \usepackage[fontsize=%fpt]{scrextend}z}{z:  \renewcommand{\normalsize}{\fontsize{%f}{%f}\selectfont}333333?z  \normalsize}zpgf.preamblepgf.rcfontsz1\ifdefined\pdftexversion\else  % non-pdftex case.z  \usepackage{fontspec}z  \{z}[Path=\detokenize{z/}]z\fi
underscorestrings)option)setmainfontsetsansfontsetmonofont)serifzsans\-serif	monospace)r   mplrcParamsget_size_in_pointsjoinzippathlibr   fmfindfontnameparentas_posix
texmanager_usepackage_if_not_loaded)font_size_ptfamilycommandpaths       /Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/matplotlib/backends/backend_pgf.py_get_preambler4   '   sV   !\\+&  99 	"?
 	)2\AE|+
,	-^$%!< ]33 A&
 "%=EGEV bkk&12EG"
" 		4;;#7#7#9;"

 H :<=!@ 	00i0PA! ! !6G
s   3E<E      ?c                &    V P                  RR4      # )z\
Do some necessary and/or useful substitutions for texts to be included in
LaTeX documents.
u   −z\ensuremath{-})replace)texts   &r3   _tex_escaper9   X   s    
 <<(*;<<    c                 J    V P                  V4       V P                  R 4       R# )z%
N)write)fhlines   &&r3   _writelnr?   `   s     HHTNHHUOr:   c                  a . pRRRRRRRR/pVP                  4       ^ ,          oSV9   d   VP                  VS,          4       M\        P                  R,          '       g   VP                  R	4       M\        ;QJ d7    V3R
 l\
        P                  P                   4       F  '       g   K   RM,	  RM(! V3R
 l\
        P                  P                   4       4      '       d   VP                  RS,          4       M\        P                  RS4       VP                  4       pVP                  RWDR,          3,          4       RRRRRR/pVP                  WQP                  4       ,          4       . ROpVP                  4       V9   d   VP                  R4       VP                  R4       RRP                  V4      ,           R,           R,           \        V 4      ,           R,           # )zw
Generate a TeX string that renders string *s* with font properties *prop*,
also applying any required escapes to *s*.
r    z	\rmfamilysansz	\sffamilyz
sans-serifr!   z	\ttfamilyr   z\fontfamily{\familydefault}c              3   @   <"   T F  qP                   S8H  x  K  	  R # 5iN)r*   ).0fontr0   s   & r3   	<genexpr>*_escape_and_apply_props.<locals>.<genexpr>u   s     D-CTYY& -Cs   TFz9\ifdefined\pdftexversion\else\setmainfont{%s}\rmfamily\fizIgnoring unknown font: %sz\fontsize{%f}{%f}r   normal italicz\itshapeobliquez\slshapez	\bfseriesz\selectfontr   z1\catcode`\^=\active\def^{\ifmmode\sp\else\^{}\fi}z\catcode`\%=\active\def%{\%}r   )semibolddemibolddemiboldheavyz
extra boldblack)
get_familyappendr"   r#   anyr(   fontManagerttflist_logwarningr$   	get_style
get_weightr%   r9   )spropcommandsfamiliesr   styles
boldstylesr0   s   &&     @r3   _escape_and_apply_propsra   g   s   
 Hv|lKGH__q!F()\\-((67	DR^^-C-CDDR^^-C-CD	D	DH6Q	S 	0&9""$DOO(D*+==>X{I{KFOOF>>+,-)JJ&%OON#
''(
	
>	? *	* a.	 	
r:   c                    \        V\        P                  4      '       d   \        V4      pM.V R8X  d   VP                  P	                  R4      pM\        V4      pV  RV R2# )z;Convert metadata key/value to a form that hyperref accepts.Trappedasciiz={r   )
isinstancedatetimer   r*   decodestr)keyvalues   &&r3   _metadata_to_strrk      sW    %**++ '			

!!'*E
U#eWBr:   c                    a   \         P                  ! R4       R #   \         P                   d     Mi ; i \         P                  ! R4      o T 3R l#   \         P                   d     Mi ; i\        R4      h)z9Return a function that converts a pdf file to a png file.
pdftocairoc                     \         P                  ! R RRRRRV,          V \        P                  P	                  V4      ^ ,          .\         P
                  R7      # )rm   z-singlefilez-transpz-pngz-rz%dstderr)
subprocesscheck_outputosr2   splitextSTDOUT)pdffilepngfiledpis   &&&r3   <lambda>+make_pdf_to_png_converter.<locals>.<lambda>   sG    Z-D-D=)VT4#:bgg&&w/24$$.&r:   gsc                    < \         P                  ! SP                  R RRRRRRRRR	R
V,          RV,          V .\         P                  R7      # )z-dQUIETz-dSAFERz-dBATCHz	-dNOPAUSEz
-dNOPROMPTz-dUseCIEColorz-dTextAlphaBits=4z-dGraphicsAlphaBits=4z-dDOINTERPOLATEz-sDEVICE=pngalphaz-sOutputFile=%sz-r%dro   )rq   rr   
executableru   )rv   rw   rx   gs_infos   &&&r3   ry   rz      sT    Z-D-D	9k<1$&7 "3g"=c\7$ $$.&r:   z&No suitable pdf to png renderer found.)r"   _get_executable_infoExecutableNotFoundErrorRuntimeError)r~   s   @r3   make_pdf_to_png_converterr      s    &  .& 	& && &**40& 	& &&  ?
@@s    44A A,+A,c                   <   a a ] tR t^t oRV 3R lltR tRtVtV ;t# )
LatexErrorc                2   < \         SV `  V4       W n        R # rC   )super__init__latex_output)selfmessager   	__class__s   &&&r3   r   LatexError.__init__   s    !(r:   c                z    V P                   w  pV P                  '       d   VR V P                  ,           ,          pV# )r   )argsr   r   r[   s   & r3   __str__LatexError.__str__   s3    YY))))Ar:   )r   )rI   )	__name__
__module____qualname____firstlineno__r   r   __static_attributes____classdictcell____classcell__r   __classdict__s   @@r3   r   r      s     ) r:   r   c                      a  ] tR t^t o Rt]R 4       t]R 4       t]]	P                  ! ^4      R 4       4       tR tR tR tR tR	R
/R ltR tR tRtV tR# )LatexManagerz
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 custom preamble in `.rcParams`.
c                 |    \         R \        P                  R,           2R\        4       RR.p RP	                  V 4      # )z% !TeX program = pgf.texsystemz\usepackage{graphicx}\begin{document}z!\typeout{pgf_backend_query_start}r   )_DOCUMENTCLASSr"   r#   r4   r%   )latex_headers    r3   _build_latex_header LatexManager._build_latex_header   sC      !o!> ?@$O0

 yy&&r:   c                @    V P                  V P                  4       4      # )zl
Return the previous LatexManager if the header and tex system did not
change, or a new instance otherwise.
)_get_cached_or_new_implr   )clss   &r3   _get_cached_or_newLatexManager._get_cached_or_new   s     **3+B+B+DEEr:   c                    V ! 4       # rC    )r   headers   &&r3   r   $LatexManager._get_cached_or_new_impl   s     ur:   c                   V P                   f   V P                  4        V P                   P                  P                  V4       V P                   P                  P                  R4       V P                   P                  P	                  4        R # )Nr   )latex_setup_latex_processstdinr<   flushr   s   &&r3   _stdin_writelnLatexManager._stdin_writeln   s^    ::%%'

q!

t$

 r:   c                b   \        V4      p. p V P                  P                  P                  ^4      pVP	                  V4       V\        V4      ) R V8X  d   MFV'       d   KV  V P                  P                  4        RV n        \        RRP                  V4      4      hRP                  V4      # )TNzLaTeX process haltedrI   )	listr   stdoutreadrS   lenkillr   r%   )r   r[   charscs   &&  r3   _expectLatexManager._expect   s    G

!!&&q)ALLOc!fWX!#1

!!
 !7HHwwu~r:   c                $    V P                  R 4      # )z
*)r   r   s   &r3   _expect_promptLatexManager._expect_prompt   s    ||E""r:   c                   \        4       V n        V P                  P                  V n        \        P
                  ! W P                  P                  4      V n        V P                  R R7       V P                  P                  R4      w  rV P                  P                  ^ 8w  d   \        RV P                  4        2V4      hRV n	        \        P                  ! V P                   4      V n        R# )F)expect_replyz
\makeatletter\@@end
zaLaTeX errored (probably missing font or error in preamble) while processing the following input:
N)r   _tmpdirr*   tmpdirweakreffinalizecleanup_finalize_tmpdirr   r   communicate
returncoder   r   	functools	lru_cache_get_box_metrics)r   r   rp   s   &  r3   r   LatexManager.__init__  s    )+ll'' ' 0 0||7K7K L 	!!u!5//0KL::  A%:++-.0 	 
 
 ) 3 3D4I4I Jr:   r   Tc               ~    \         P                  ! \        P                  R ,          R.\         P                  \         P                  RV P
                  R7      V n        R p\        P                  ! YT P                  4      T n        T P                  T P                  4       4       T'       d$   T P                  R4       T P!                  4        R# R#   \         d+   p\        \        P                  R ,          : R24      ThRp?i\         d+   p\        R\        P                  R ,          : 24      ThRp?ii ; i)	r   -halt-on-errorutf-8)r   r   encodingcwdz] not found; install it or change rcParams['pgf.texsystem'] to an available TeX implementationNzError starting c                     V P                  4         V P                  4        R #   \         d    T P                  4         R # i ; irC   )r   r   r   wait)r   s   &r3   finalize_latex9LatexManager._setup_latex_process.<locals>.finalize_latex(  s4    JJL!!# 

s   $ AAz*pgf_backend_query_start)rq   Popenr"   r#   PIPEr   r   FileNotFoundErrorr   OSErrorr   r   _finalize_latexr   r   r   r   )r   r   errr   s   &$  r3   r   !LatexManager._setup_latex_process  s   	N#))o.0@A oojoo dkk3DJ	  '//$** . 	D4467LL34! ) ! 	<<03 4O P   	N!#,,"?!BCEJMN	Ns*   AC D<%DD<D<%D77D<c                6    V P                  \        W4      4      # )zo
Get the width, total height, and descent (in TeX points) for a text
typeset by the current LaTeX environment.
)r   ra   )r   r8   r\   s   &&&r3   get_width_height_descent%LatexManager.get_width_height_descent7  s    
 $$%<T%HIIr:   c                   V P                  RV,          4        V P                  4       p TP                  4       R,          P                  R4      w  rEp\        TRR 4      \        TRR 4      \        TRR 4      rpYxT	,           T	3#   \         d+   p\        RP	                  YP
                  4      4      ThRp?ii ; i  \         d!   p\        RP	                  Y4      4      ThRp?ii ; i)zv
Get the width, total height and descent (in TeX points) for a TeX
command's output in the current LaTeX environment.
zW{\catcode`\^=\active\catcode`\%%=\active\sbox0{%s}\typeout{\the\wd0,\the\ht0,\the\dp0}}z#Error measuring {}
LaTeX Output:
{}N,)
r   r   r   
ValueErrorformatr   
splitlinessplit	Exceptionfloat)
r   texanswerr   widthheightoffsetwhos
   &&        r3   r   LatexManager._get_box_metrics>  s    	5		F((*F	< %+$5$5$7$;$A$A#$F!E6 cr
#U6#2;%7vcr{9Ka a%{  	F D$fS*:*:;=BEF	F  	<D$fS138;<	<s.   B )C  B=%B88B= C+C&&C+)r   r   r   r   r   r   N)r   r   r   r   __doc__staticmethodr   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   s   @r3   r   r      s      ' ' F F   !#K&!"4 !"FJ r:   r   c                  $   \         P                  4       p V P                  R \        P                  ! R4      P                  4       ,          4        V P                  4        R#   \         d#    \         P                  P                  4         R# i ; i)z&\includegraphics[interpolate=true]{%s}zimages/matplotlib.pngz\includegraphicsz	\pgfimage)
r   r   r   r   _get_data_pathr,   r   r   r   cache_clear)mans    r3   _get_image_inclusion_commandr   ^  sx    

)
)
+C1


6
7
@
@
B	CD" ,,88:s   A" ")BBc                      a a ] tR tRt oV 3R ltRR ltRR ltR tR tRR lt	RR	 lt
R
 tR tRR ltRR/R ltRR ltR tR tR tR tRtVtV ;t# )RendererPgfin  c                l   < \         SV `  4        VP                  V n        W n        Wn        ^ V n        R# )aN  
Create 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.
N)r   r   rx   r=   figureimage_counter)r   r  r=   r   s   &&&r3   r   RendererPgf.__init__p  s-     	::r:   Nc                   \        V P                  R 4       RV P                  ,          pV P                  V4       V P	                  W4       VP                  V4      P                  4       w  rV^ ,          V,          V^,          V,          V	^ ,          V,          V	^,          V,          3p
\        V P                  RV
,          4       V P                  RW#4       V P                  VP                  4       R8g  VRJR7       \        V P                  R4       RV P                  ,          pV) V) W3pVP                  VRVR7       F  w  rV^ ,          V,          V^,          V,          pp\        V P                  R 4       \        V P                  R	VV3,          4       \        V P                  R
4       \        V P                  R4       K  	  \        V P                  R4       R# )\begin{pgfscope}r5   zQ\pgfsys@defobject{currentmarker}{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{N        strokefillr   F)simplifyclip"\pgfsys@transformshift{%fin}{%fin}z"\pgfsys@useobject{currentmarker}{}\end{pgfscope}B^!Vl@)r?   r=   rx   _print_pgf_clip_print_pgf_path_stylesget_extents
get_points_print_pgf_path_pgf_path_drawget_linewidthiter_segments)r   gcmarker_pathmarker_transr2   transrgbFacefbltrcoordsmaxcoordr  pointcodexys   &&&&&&&          r3   draw_markersRendererPgf.draw_markers  s    	-. M 	R ##B0 ((6AACABqEAIr!uqy"Q%!);FHNO	P 	T;=2#3#3#5#<!(!4 	 	6$ 488+	H9h9  --ee37 . 9KE8a<qAqATWW12TWWCq!fLMTWWCDTWW/09 	+,r:   c                j   \        V P                  R 4       V P                  V4       V P                  W4       V P	                  WW44       V P                  VP                  4       R8g  VRJR7       \        V P                  R4       VP                  4       '       Ed   \        V P                  R 4       V P                  W4       V P                  V4       V P	                  WW44       \        V P                  R4       \        V P                  R4       \        V P                  R 4       \        V P                  R4       \        V P                  R4       \        P                  P                  4       P                  V P                  4      pV P	                  RVP                  4       V4       V P                  RR	7       \        V P                  R4       \        V P                  R
4       RV P                  ,          pVP                  V4      P                  4       w  w  rxw  rWg,          Wi,          rWh,          Wj,          r\         P"                  ! W,
          4      \         P"                  ! W,
          4      r\        V P                  RWx3,          4       \%        V4       Ft  p\%        V4       F/  p\        V P                  R4       \        V P                  R4       K1  	  \        V P                  RV,          4       \        V P                  R4       Kv  	  \        V P                  R4       R# R# )r  r  Nr  r  \pgfusepath{clip}zN\pgfsys@defobject{currentpattern}{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}{z=\pgfpathrectangle{\pgfqpoint{0in}{0in}}{\pgfqpoint{1in}{1in}}T)r	  r   r5   r  z#\pgfsys@useobject{currentpattern}{}z \pgfsys@transformshift{1in}{0in}z"\pgfsys@transformshift{-%din}{0in}z \pgfsys@transformshift{0in}{1in})r?   r=   r  r  r  r  r  	get_hatchr"   
transformsAffine2Dscalerx   get_hatch_pathr  r  mathceilrange)r   r  r2   	transformr  r-  r  xminyminxmaxymaxrepxrepyiyixs   &&&&&          r3   	draw_pathRendererPgf.draw_path  s{   -.R ##B0Ry:2#3#3#5#<!(!4 	 	6+, <<>>TWW12''4   $  9>TWW23 TWWFG TWW12TWWEF TWW23NN++-33DHH=E  r'8'8':EBt,TWW/0TWWd#TXXA  +668 'LT,418$18$4;/4;1G$TWW:d\IKDk+BTWW&LMTWW&IJ & "G$"NO"EF " TWW/0O r:   c                   R V P                   ,          pVP                  4       pV'       d~   VP                  4       w  rEWT,
          w  rgV^ ,          V,          V^,          V,          Wb,          Wr,          3p\        V P                  RV,          4       \        V P                  R4       VP                  4       w  rV	e+   V P                  WV
4       \        V P                  R4       R# R# )r5   zA\pgfpathrectangle{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}r)  N)rx   get_clip_rectangler  r?   r=   get_clip_pathr  )r   r  r  bboxp1p2r   r   r   clippathclippath_transs   &&         r3   r  RendererPgf._print_pgf_clip  s    M$$&__&FB7DAUQY1	15!%7FTWWI TWW23 $&#3#3#5   ~>TWW23  r:   c                   R RRRRR/p\        V P                  W1P                  4       ,          4       RRRRR	R
/p\        V P                  WAP                  4       ,          4       VRJpVP	                  4       '       d   VP                  4       ;rgM:VP                  4       ^,          pV'       d   \        V4      ^8  d
   V^,          MRpV'       dD   \        V P                  R\        VR,          4      ,          4       \        V P                  R4       V'       d%   VR8w  d   \        V P                  RV,          4       VP                  4       \        ,          \        ,          pVP                  4       p	\        V P                  RV,          4       \        V P                  RV	R,          ,          4       \        V P                  R4       VR8w  d   \        V P                  RV,          4       VP                  4       w  rVf   \        V P                  R4       R# \        V P                  RRP                  R V 4       4      V
3,          4       R# )buttz\pgfsetbuttcaproundz\pgfsetroundcap
projectingz\pgfsetrectcapmiterz\pgfsetmiterjoinz\pgfsetroundjoinbevelz\pgfsetbeveljoinNr5   z(\definecolor{currentfill}{rgb}{%f,%f,%f}N   Nz\pgfsetfillcolor{currentfill}\pgfsetfillopacity{%f}z\pgfsetlinewidth{%fpt}z*\definecolor{currentstroke}{rgb}{%f,%f,%f}z!\pgfsetstrokecolor{currentstroke}\pgfsetstrokeopacity{%f}z\pgfsetdash{}{0pt}z\pgfsetdash{%s}{%fpt}rI   c              3   4   "   T F  pR V,          x  K  	  R# 5i)z{%fpt}Nr   )rD   dashs   & r3   rF   5RendererPgf._print_pgf_path_styles.<locals>.<genexpr>"  s     GYT	D 0 0Ys   )r?   r=   get_capstyleget_joinstyleget_forced_alpha	get_alphaget_rgbr   tupler  mpl_pt_to_inlatex_in_to_pt
get_dashesr%   )r   r  r  	capstyles
joinstyleshas_fillfillopacitystrokeopacitylwstroke_rgbadash_offset	dash_lists   &&&         r3   r  "RendererPgf._print_pgf_path_styles  s   .0!#46	 	)OO$567 2224
 	*%5%5%789 $&  *,,,.8K-JJLOM(0S\A5E'!*3KTWW@WR[)*+ TWW>?s*TWW7+EF ,.?jjl3b89>r?#	$ 	>?CTWW9MIJ "$TWW34TWW-GYGG#%%&r:   c                   R V P                   ,          pV'       d   VP                  4       MRpRV P                   ,          pV'       dd   Vf`   VP                  4       w  r\        V^ ,          V) 4      \        V^,          V) 4      \	        V	^ ,          V4      \	        V	^,          V4      3p
MV) V) Ww3p
VP                  W:R7       EF  w  rV\        P                  8X  d;   \        V4      w  r\        V P                  RW],          W^,          3,          4       KU  V\        P                  8X  d   \        V P                  R4       K  V\        P                  8X  d;   \        V4      w  r\        V P                  RW],          W^,          3,          4       K  V\        P                  8X  dR   \        V4      w  ppppW,          VV,          VV,          VV,          3p\        V P                  RV,          4       EK7  V\        P                  8X  g   EKO  \        V4      w  ppppppVV,          VV,          VV,          VV,          VV,          VV,          3p\        V P                  RV,          4       EK  	  V'       d   VP                  4       MRpVe   Vw  pppVe   VR,          pV^,          p\        V P                  R	4       \        V P                  R
4       \        V P                  RVV,          R RVV,          R R24       \        V P                  R\!        V4       R24       \        V P                  R4       R# R# R# )r5   N)r  z&\pgfpathmoveto{\pgfqpoint{%fin}{%fin}}z\pgfpathclosez&\pgfpathlineto{\pgfqpoint{%fin}{%fin}}zH\pgfpathquadraticcurveto{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}zW\pgfpathcurveto{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}g      ?z\usepgfmodule{decorations}z(\usepgflibrary{decorations.pathmorphing}z/\pgfkeys{/pgf/decoration/.cd, segment length = r  zin, amplitude = zin}z\pgfmathsetseed{r   z%\pgfdecoratecurrentpath{random steps}r  )rx   r>  r  maxminr  r   MOVETOrX  r?   r=   	CLOSEPOLYLINETOCURVE3CURVE4get_sketch_paramsint)r   r  r2   r2  r  r  r@  r!  rA  rB  r  pointsr#  r$  r%  cxcypxpyr   c1xc1yc2xc2ysketch_paramsr-  length
randomnesss   &&&&&                       r3   r  RendererPgf._print_pgf_path%  s   M*,r$$&$ 488+W___&FB1y)3r!uxi+@1x(#beX*>@D Iy(=D ..y.DLFt{{"V}B%() '"23$V}B%() $!&vBBaaa7M!"# $-26]*S#sBq#'37C!GR!VR!VK5 "	"#/ E> 35,,.$$ )6%E6: #
"?@"MN #-.4qj!,< =().Ad#< = $6s:6Gr"JK"JK ! %r:   c                    . pV'       d   VP                  R 4       V'       d   VP                  R4       \        V P                  RRP                  V4      ,          4       R# )r	  r
  z\pgfusepath{%s}r   N)rS   r?   r=   r%   )r   r	  r
  actionss   &&& r3   r  RendererPgf._pgf_path_drawg  sB    NN8$NN6",sxx/@@Ar:   c                    R # )Tr   r   s   &r3   option_scale_imageRendererPgf.option_scale_imageo  s    r:   c                :    \         P                  R ,          '       * # )zimage.composite_image)r"   r#   r   s   &r3   option_image_nocomposite$RendererPgf.option_image_nocomposites  s    << 7888r:   c                   VP                   R ,          w  rgV^ 8X  g   V^ 8X  d   R# \        P                  P                  \	        V P
                  RR4      4      '       g   \        R4      h\        P                  ! V P
                  P                  4      pRVP                  V P                  3,          p	\        P                  ! VRRR1,          4      P                  VP                  V	,          4       V ;P                  ^,          un        \!        V P
                  R4       V P#                  V4       RV P$                  ,          p
Vf<   \!        V P
                  RW*,          W:,          3,          4       Wz,          Wj,          rgM|VP'                  4       P)                  4       w  rrpp\!        V P
                  R	W,          W,          W,          W,          W,           V
,          VV,           V
,          3,          4       ^;rv\+        VRJ 4      P-                  4       p\!        V P
                  R
\/        4       VWvV	3,          4       \!        V P
                  R4       R# ):N   NNr*   rI   zXstreamed pgf-code does not support raster graphics, consider using the pgf-to-pdf optionz%s-img%d.pngr  r5   r  z/\pgfsys@transformcm{%f}{%f}{%f}{%f}{%fin}{%fin}zD\pgftext[left,bottom]{%s[interpolate=%s,width=%fin,height=%fin]{%s}}r  )shapers   r2   existsgetattrr=   r   r'   r   r*   stemr  r   	fromarraysaver+   r?   r  rx   frozen	to_valuesrh   lowerr   )r   r  r$  r%  imr2  r   r   r2   	fname_imgr  tr1tr2tr3tr4tr5tr6interps   &&&&&&            r3   
draw_imageRendererPgf.draw_imagew  s    xx|6Q!Vww~~gdggvr:;;./ /
 ||DGGLL)"dii1C1C%DD	4R4!&&t{{Y'>?a 	-.R MTWW:aeQU^KM5!%q+4+;+;+=+G+G+I(CcSTWWGgsww!mcAg]445 IAY$&'--/D.0!	++	,
 	+,r:   mtextc               2    V P                  WW4WVR VR7       R# )TeX)ismathr  N)	draw_text)r   r  r$  r%  r[   r\   angler  s   &&&&&&&$r3   draw_texRendererPgf.draw_tex  s    raDUKr:   c	                   \        WE4      p\        V P                  R 4       V P                  V4       VP	                  4       p	V	R8w  d;   \        V P                  RV	,          4       \        V P                  RV	,          4       \        VP                  4       4      R,          p
\        V P                  RV
,          4       \        V P                  R4       \        V P                  R4       RV,           pV P                  P                  p. pV'       d   V^ 8X  g   VP                  4       R	8X  d   VP                  4       R
8w  d   VP                  4       pVP                  4       P                  V4      w  r#RRRRRR/pRRRRRRRR/pVP                  RW+,          R R2RW;,          R R2WP                  4       ,          WP                  4       ,          .4       M&VP!                  RW+,          R RW;,          R R24       V^ 8w  d   VP!                  RV,          4       \        V P                  RRP#                  V4      : RV: R24       \        V P                  R4       R# ) r  r5   rN  rO  rL  z&\definecolor{textcolor}{rgb}{%f,%f,%f}z\pgfsetstrokecolor{textcolor}z\pgfsetfillcolor{textcolor}z\color{textcolor}anchorcenter_baselineleftrightcenterrI   topbottombaselinebasezx=r  inzy=zin, y=zin, left, basez	rotate=%fz	\pgftext[r   z]{r   r  N)ra   r?   r=   r  rV  rX  rW  r  rx   get_rotation_modeget_verticalalignmentget_unitless_positionget_transformr2  extendget_horizontalalignmentrS   r%   )r   r  r$  r%  r[   r\   r  r  r  alphargbrx   	text_argsposhalignvaligns   &&&&&&&&&       r3   r  RendererPgf.draw_text  s    $A,-.R C<TWW7%?@TWW9EABBJJL!"%CcIJ:;89 1$kkoo	!((*h6++-1BB --/C&&(2237DAfgw"EFUHh &(B8FQU1IR QU1IR 44672245	  r!%&q	HIA:[501)1DaHI+,r:   c                    \         P                  4       P                  W4      w  rEp\        V P                  ,          pWG,          WW,          Wg,          3# rC   )r   r   r   rY  rx   )r   r[   r\   r  r   r   dr  s   &&&&    r3   get_text_width_height_descent)RendererPgf.get_text_width_height_descent  sG      224,,Q5 	a
 488#uaeQU""r:   c                    R # )Fr   r   s   &r3   flipyRendererPgf.flipy  s    r:   c                    V P                   P                  4       V P                  ,          V P                   P                  4       V P                  ,          3# rC   )r  get_figwidthrx   get_figheightr   s   &r3   get_canvas_width_height#RendererPgf.get_canvas_width_height  s>    ((*TXX5))+dhh68 	8r:   c                >    V\         ,          V P                  ,          # rC   )rY  rx   )r   rp  s   &&r3   points_to_pixelsRendererPgf.points_to_pixels  s    $txx//r:   )rx   r=   r  r  rC   )TF)FN)r   r   r   r   r   r&  r;  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   s   @@r3   r   r   n  sl     &$-L31j4(1&f@LDB9'-RL$ L.-`	#8
0 0r:   r   c                   v   a a ] tR tRt oRRRRRR/tR tR	R
/R ltR tRR
/R ltR t	R t
V 3R ltRtVtV ;t# )FigureCanvasPgfi  pgfzLaTeX PGF picturepdfzLaTeX compiled PGF picturepngzPortable Network Graphicsc                    R # )r  r   r   s   &r3   get_default_filetype$FigureCanvasPgf.get_default_filetype  s    r:   bbox_inches_restoreNc          
        R pR.p\        4       P                  4        F  pVP                  RV,           4       K  	  VP                  R4       RP                  V4      pV P                  P                  4       V P                  P                  4       rvV P                  P                  pVP                  V4       VP                  V4       VP                  R4       \        VR4       \        VR4       \        VR4       \        VRWg3,          4       \        VR	4       \        V P                  WgV\        V P                  V4      VR
7      p	V P                  P                  V	4       \        VR4       \        VR4       \        VR4       R# )a  %% 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}
%%
%% Also ensure that all the required font packages are loaded; for instance,
%% the lmodern package is sometimes necessary when using math font.
%%   \usepackage{lmodern}
%%
%% 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}
%%
z)%% Matplotlib used the following preamblez%%   z%%r   z\begingroupz\makeatletterz\begin{pgfpicture}z:\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}z&\pgfusepath{use as bounding box, clip})r  z\end{pgfpicture}z\makeatotherz	\endgroupN)r4   r   rS   r%   r  r  r  rx   r<   r?   r   r   draw)
r   r=   r  header_textheader_info_preambler>   r   r   rx   renderers
   &&$       r3   _print_pgf_to_fh FigureCanvasPgf._print_pgf_to_fh  sO   . !LL!O..0D ''$7 1##D)#yy)=> {{'')4;;+D+D+F1kkoo 	
%&
^$%&*+N6	 	>?$T[[!%0b%A9LN 	" 	()_%\"r:   c                   \         P                  ! VRRR7      ;_uu_ 4       p\         P                  ! V4      '       g   \        P                  ! R4      ! V4      pV P
                  ! V3/ VB  RRR4       R#   + '       g   i     R# ; i)za
Output pgf macros for drawing the figure so it can be included and
rendered in latex documents.
r   r   r   N)r   open_file_cmfile_requires_unicodecodecs	getwriterr  )r   fname_or_fhkwargsfiles   &&, r3   	print_pgfFigureCanvasPgf.print_pgf-  sd    
 S7CCt..t44''06!!$1&1 DCCCs   AA88B		metadatac                  V P                   P                  4       w  rE\        RT;'       g    / 4      pRP                  R VP	                  4        4       4      p\        4       ;_uu_ 4       p\        P                  ! V4      p	V P                  ! V	R,          3/ VB  V	R,          P                  RP                  \        RV,          RWE3,          R	\        4       R
RRR.	4      RR7       \        P                  R,          p
\        P                  ! V
RRR.\         VR7       V	R,          P#                  R4      ;_uu_ 4       p\        P$                  ! VR4      ;_uu_ 4       p\&        P(                  ! W4       RRR4       RRR4       RRR4       R#   + '       g   i     L"; i  + '       g   i     L-; i  + '       g   i     R# ; i)z3Use LaTeX to compile a pgf generated figure to pdf.r  r   c              3   <   "   T F  w  r\        W4      x  K  	  R # 5irC   rk   rD   kvs   &  r3   rF   ,FigureCanvasPgf.print_pdf.<locals>.<genexpr><  s       B/@tqQ""/@   z
figure.pgfz
figure.texr   #\usepackage[pdfinfo={%s}]{hyperref}8\usepackage[papersize={%fin,%fin}, margin=0in]{geometry}\usepackage{pgf}r   z
\centeringz\input{figure.pgf}z\end{document}r   r  r   -interaction=nonstopmoder   r   
figure.pdfrbwbN)r  get_size_inchesr   r%   itemsr   r'   r   r  
write_textr   r4   r"   r#   r   _check_and_log_subprocessrW   openr  shutilcopyfileobj)r   r  r  r  r   r   	info_dictpdfinfor   tmppath
texcommandorigdests   &&$,         r3   	print_pdfFigureCanvasPgf.print_pdf7  sy   {{**,)%R@	(( B/8/@B B  !!Vll6*GNN7\1<V<|#//		":WDOf'!O'!)%  % 0 & o6J++79I $&2 \)//55$$[$774""4. 8 6) "!* 87 65) "!!s=   +CF8 F%	!F8F%	 F8F"F%	%F50F88G		c                6   \        4       p\        4       ;_uu_ 4       p\        P                  ! V4      pVR,          pVR,          pV P                  ! V3/ VB  V! WgV P
                  P                  R7       VP                  R4      ;_uu_ 4       p\        P                  ! VR4      ;_uu_ 4       p	\        P                  ! W4       RRR4       RRR4       RRR4       R#   + '       g   i     L"; i  + '       g   i     L-; i  + '       g   i     R# ; i)z?Use LaTeX to compile a pgf figure to pdf and convert it to png.r  z
figure.png)rx   r  r  N)r   r   r'   r   r  r  rx   r  r   r  r  r  )
r   r  r  	converterr   r  pdf_pathpng_pathr  r  s
   &&,       r3   	print_pngFigureCanvasPgf.print_pngX  s    -/	!!Vll6*G-H-HNN8.v.hdkkoo>--%%$$[$774""4. 8 & "! 87 &% "!!s<   A3D C4	0C!C4	D!C1,C4	4D?DD	c                .    \        V P                  R 4      # rC   )r   r  r   s   &r3   get_rendererFigureCanvasPgf.get_renderere  s    4;;--r:   c                T   < V P                   P                  4        \        SV `  4       # rC   )r  draw_without_renderingr   r  )r   r   s   &r3   r  FigureCanvasPgf.drawh  s    **,w|~r:   r   )r   r   r   r   	filetypesr  r  r  r  r  r  r  r   r   r   r   s   @@r3   r  r    sV     +437I6#$ 6#p2/ /B/. r:   r  c                       ] tR tRt]tRtR# )_BackendPgfip  r   N)r   r   r   r   r  FigureCanvasr   r   r:   r3   r  r  p  s    "Lr:   r  c                   `   a  ] tR tRt o RtRR/R ltR tR tR tR	 t	R
 t
RR ltR tRtV tR# )PdfPagesiu  am  
A multi-page PDF file using the pgf backend

Examples
--------
>>> import matplotlib.pyplot as plt
>>> # Initialize:
>>> with PdfPages('foo.pdf') as pdf:
...     # As many times as you like, create a figure fig and save it:
...     fig = plt.figure()
...     pdf.savefig(fig)
...     # When no figure is specified the current figure is saved
...     pdf.savefig()
r  Nc                   Wn         ^ V n        T;'       g    / P                  4       V n        \	        RV P                  4      V n        \        4       V n        R# )a!  
Create a new PdfPages object.

Parameters
----------
filename : str or path-like
    Plots using `PdfPages.savefig` will be written to a file at this
    location. Any older file with the same name is overwritten.

metadata : dict, optional
    Information dictionary object (see PDF reference section 10.2.1
    'Document Information Dictionary'), e.g.:
    ``{'Creator': 'My software', 'Author': 'Me', 'Title': 'Awesome'}``.

    The standard keys are 'Title', 'Author', 'Subject', 'Keywords',
    'Creator', 'Producer', 'CreationDate', 'ModDate', and
    'Trapped'. Values have been predefined for 'Creator', 'Producer'
    and 'CreationDate'. They can be removed by setting them to `None`.

    Note that some versions of LaTeX engines may ignore the 'Producer'
    key and set it to themselves.
r  N)_output_name
_n_figurescopy	_metadatar   
_info_dictr   _file)r   filenamer  s   &&$r3   r   PdfPages.__init__  sB    . %"..b..0/t~~FY
r:   c           	         R P                  R V P                  P                  4        4       4      pRP                  \        RV,          RW3,          R\	        4       RR.4      pV P
                  P                  VP                  R4      4       R	# )
r   c              3   <   "   T F  w  r\        W4      x  K  	  R # 5irC   r  r  s   &  r3   rF   )PdfPages._write_header.<locals>.<genexpr>  s       H/FtqQ""/Fr  r   r  r  r  z\setlength{\parindent}{0pt}z\begin{document}%r   N)r%   r  r  r   r4   r  r<   encode)r   width_inchesheight_inchesr   r   s   &&&  r3   _write_headerPdfPages._write_header  s    (( H/3/D/D/FH Hyy2W<G+,O* 	"
 	 	

,,W56r:   c                    V # rC   r   r   s   &r3   	__enter__PdfPages.__enter__  s    r:   c                &    V P                  4        R # rC   )close)r   exc_typeexc_valexc_tbs   &&&&r3   __exit__PdfPages.__exit__  s    

r:   c                    V P                   P                  R4       V P                  ^ 8  d   V P                  4        V P                   P	                  4        R# )zk
Finalize this object, running LaTeX in a temporary directory
and moving the final pdf file to *filename*.
s   \end{document}\nN)r  r<   r  
_run_latexr.  r   s   &r3   r.  PdfPages.close  s=    
 	

-.??QOO

r:   c                   \         P                  R ,          p\        4       ;_uu_ 4       p\        P                  ! VR4      pVP                  V P                  P                  4       4       \        P                  ! VRRV.\        VR7       \        P                  ! VP                  R4      V P                  4       RRR4       R#   + '       g   i     R# ; i)r   zpdf_pages.texr  r   r  z.pdfN)r"   r#   r   r'   r   write_bytesr  getvaluer   r  rW   r  movewith_suffixr  )r   r  r   
tex_sources   &   r3   r5  PdfPages._run_latex  s    \\/2
!!V fo>J""4::#6#6#89++79I&" KK
..v68I8IJ "!!!s   BCC	c                   \        V\        4      '       gY   Vf   \        P                  ! 4       pM\        P                  ! V4      pVf   \        RV 24      hVP                  P                  pVP                  4       w  rEV P                  ^ 8X  d   V P                  WE4       M#V P                  P                  RWE3,          4       VP                  ! V P                  3RRRR/VB  V ;P                  ^,          un	        R# )z
Save a `.Figure` to this file as a new page.

Any other keyword arguments are passed to `~.Figure.savefig`.

Parameters
----------
figure : `.Figure` or int, default: the active figure
    The figure, or index of the figure, that is saved to the file.
Nz
No figure s   \newpage\ifdefined\pdfpagewidth\pdfpagewidth\else\pagewidth\fi=%fin\ifdefined\pdfpageheight\pdfpageheight\else\pageheight\fi=%fin%%
r   r  backend)re   r   r   
get_activeget_fig_managerr   canvasr  r  r  r(  r  r<   savefig)r   r  r  managerr   r   s   &&,   r3   rC  PdfPages.savefig  s     &&))~..*--f5 :fX!677^^**F..0??au-
 JJ !/* 	tzzI%II&I1r:   c                    V P                   # )z=Return the current number of pages in the multipage pdf file.)r  r   s   &r3   get_pagecountPdfPages.get_pagecount  s    r:   )r  r  r  r  r  rC   )r   r   r   r   r   r   r(  r+  r2  r.  r5  rC  rG  r   r   r   s   @r3   r  r  u  s@     T :7	K"H r:   r  gRhV?gqq?)@r  rf   r   ior   loggingr/  rs   r'   r  rq   tempfiler   r   PILr   
matplotlibr"   r   r   r(   matplotlib.backend_basesr   r	   r
   r   !matplotlib.backends.backend_mixedr   matplotlib.backends.backend_pdfr   r   matplotlib.pathr   matplotlib.figurer   matplotlib.font_managerr   matplotlib._pylab_helpersr   	getLoggerr   rW   r   r4   latex_pt_to_inrZ  rY  mpl_in_to_ptr9   r?   ra   rk   r   r   r   r   r   r   r   r  FigureManagerPgfexportr  r  r   r:   r3   <module>rZ     s5         	    '    0  @-   $ 2 )" ,&V n$L =*Z A6	 	U Up Q |0, |0~}& }@ %  
#( # #} }r:   