+
     ]i  c                   s@   ^ 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# )$i    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                 s   \        \        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\fiZ
underscoreZstrings)Zoption)ZsetmainfontZsetsansfontZsetmonofont)serifzsans\-serif	monospace)r   mplrcParamsget_size_in_pointsjoinZzippathlibr   fmZfindfontnameparentas_posixZ
texmanagerZ_usepackage_if_not_loaded)Zfont_size_ptfamilyZcommandpaths       F/usr/lib64/python3.14/site-packages/matplotlib/backends/backend_pgf.py_get_preambler$   '   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                s&    V P                  RR4      # )z\
Do some necessary and/or useful substitutions for texts to be included in
LaTeX documents.
u   −z\ensuremath{-})Zreplace)text   &r#   _tex_escaper(   X   s    
 <<(*;<<    c                 sJ    V P                  V4       V P                  R 4       R# )z%
N)write)fhline   &&r#   _writelnr.   `   s     HHTNHHUOr)   c                s  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	\rmfamilyZsansz	\sffamilyz
sans-serifr   z	\ttfamilyr   z\fontfamily{\familydefault}c              3   s@   <"   T F  qP                   S8H  x  K  	  R # 5iN)r   ).0Zfontr!   s   & r#   	<genexpr>Z*_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   Znormal Zitalicz\itshapeZobliquez\slshapez	\bfseriesz\selectfontr   z1\catcode`\^=\active\def^{\ifmmode\sp\else\^{}\fi}z\catcode`\%=\active\def%{\%}r   )ZsemiboldZdemiboldZdemiZboldZheavyz
extra boldZblack)Z
get_familyappendr   r   Zanyr   ZfontManagerZttflist_logZwarningr   Z	get_styleZ
get_weightr   r(   )spropZcommandsZfamiliesr   ZstylesZ
boldstylesr!   s   &&     @r#   _escape_and_apply_propsr7   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                s    \        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.ZTrappedZasciiz={r   )
isinstancedatetimer   r   Zdecodestr)ZkeyZvaluer-   r#   _metadata_to_strr;      sW    %**++ '			

!!'*E
U#eWBr)   c                 s   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                 s    \         P                  ! R RRRRRV,          V \        P                  P	                  V4      ^ ,          .\         P
                  R7      # )r<   z-singlefilez-transpz-pngz-rz%dstderr)
subprocesscheck_outputosr"   ZsplitextSTDOUT)pdffilepngfiledpi   &&&r#   <lambda>+make_pdf_to_png_converter.<locals>.<lambda>   sG    Z-D-D=)VT4#:bgg&&w/24$$.&r)   Zgsc                 s   < \         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%dr=   )r?   r@   Z
executablerB   )rC   rD   rE   gs_info   &&&r#   rG   rH      sT    Z-D-D	9k<1$&7 "3g"=c\7$ $$.&r)   z&No suitable pdf to png renderer found.)r   Z_get_executable_infoZExecutableNotFoundErrorRuntimeError)rI      @r#   make_pdf_to_png_converterrM      s    &  .& 	& && &**40& 	& &&  ?
@@s    44A A,+A,c                   s<   a a ] tR t^t oRV 3R lltR tRtVtV ;t# )
LatexErrorc                s2   < \         SV `  V4       W n        R # r/   )super__init__latex_output)selfZmessagerQ   	__class__rJ   r#   rP   ZLatexError.__init__   s    !(r)   c                sz    V P                   w  pV P                  '       d   VR V P                  ,           ,          pV# )r   )ZargsrQ   rR   r5      & r#   __str__ZLatexError.__str__   s3    YY))))Ar)   )rQ   )r2   )	__name__
__module____qualname____firstlineno__rP   rV   __static_attributes____classdictcell____classcell__rS   __classdict__   @@r#   rN   rN      s     ) r)   rN   c                   s   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                 s|    \         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   r$   r   )latex_header    r#   _build_latex_headerZ LatexManager._build_latex_header   sC      !o!> ?@$O0

 yy&&r)   c                s@    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_implrg   )clsr'   r#   _get_cached_or_newZLatexManager._get_cached_or_new   s     **3+B+B+DEEr)   c                s    V ! 4       # r/    )ri   Zheaderr-   r#   rh   Z$LatexManager._get_cached_or_new_impl   s     ur)   c                s   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*   ZflushrT   r-   r#   _stdin_writelnZLatexManager._stdin_writeln   s^    ::%%'

q!

t$

 r)   c                sb   \        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 haltedr2   )	Zlistrl   stdoutZreadr3   lenkillrN   r   )rR   r5   ZcharsZcs   &&  r#   _expectZLatexManager._expect   s    G

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

!!
 !7HHwwu~r)   c                s$    V P                  R 4      # )z
*)rs   rR   r'   r#   _expect_promptZLatexManager._expect_prompt   s    ||E""r)   c                s   \        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finalizeZcleanup_finalize_tmpdirrm   rl   communicateZ
returncoderN   rg   	functools	lru_cache_get_box_metrics)rR   rp   r>      &  r#   rP   ZLatexManager.__init__  s    )+ll'' ' 0 0||7K7K L 	!!u!5//0KL::  A%:++-.0 	 
 
 ) 3 3D4I4I Jr)   rv   Tc               s~    \         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)	rb   -halt-on-errorutf-8)rn   rp   encodingcwdz] not found; install it or change rcParams['pgf.texsystem'] to an available TeX implementationNzError starting c                 s    V P                  4         V P                  4        R #   \         d    T P                  4         R # i ; ir/   )rr   r|   rK   Zwait)rl   r'   r#   finalize_latexZ9LatexManager._setup_latex_process.<locals>.finalize_latex(  s4    JJL!!# 

s   $ AAz*pgf_backend_query_start)r?   ZPopenr   r   ZPIPErx   rl   ZFileNotFoundErrorrK   ZOSErrorry   rz   _finalize_latexro   rg   rs   ru   )rR   rv   errr   s   &$  r#   rm   Z!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                s6    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   r7   )rR   r&   r6   rF   r#   get_width_height_descentZ%LatexManager.get_width_height_descent7  s    
 $$%<T%HIIr)   c                s   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,ii)
ro   ru   rN   
ValueErrorformatrQ   
splitlinesZsplit	ExceptionZfloat)
rR   ZtexZanswerr   widthheightZoffsetwhZos
   &&        r#   r   Z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   rw   rl   rx   N)rW   rX   rY   rZ   __doc__Zstaticmethodrg   Zclassmethodrj   r}   r~   rh   ro   rs   ru   rP   rm   r   r   r[   r\   r_   rL   r#   ra   ra      s      ' ' F F   !#K&!"4 !"FJ r)   ra   c                  s$   \         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)
ra   rj   ro   r   Z_get_data_pathr    ru   rN   rh   Zcache_clear)Zmanrf   r#   _get_image_inclusion_commandr   ^  sx    

)
)
+C1


6
7
@
@
B	CD" ,,88:s   A" ")BBc                   s   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                sl   < \         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)rO   rP   rE   r+   figureimage_counter)rR   r   r+   rS   rJ   r#   rP   ZRendererPgf.__init__p  s-     	::r)   Nc                s   \        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}r%   zQ\pgfsys@defobject{currentmarker}{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}{N        strokefillr   F)Zsimplifyclip"\pgfsys@transformshift{%fin}{%fin}z"\pgfsys@useobject{currentmarker}{}\end{pgfscope}B^!Vl@)r.   r+   rE   _print_pgf_clip_print_pgf_path_stylesget_extents
get_points_print_pgf_path_pgf_path_drawget_linewidthiter_segments)rR   gcZmarker_pathZmarker_transr"   ZtransrgbFacefZblZtrcoordsmaxcoordr   Zpointcodexys   &&&&&&&          r#   draw_markersZ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                sj   \        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   r%   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   Z	get_hatchr   Z
transformsZAffine2DscalerE   Zget_hatch_pathr   r   mathZceilZrange)rR   r   r"   	transformr   r   r   ZxminZyminZxmaxZymaxZrepxZrepyZiyZixs   &&&&&          r#   	draw_pathZ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                s   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# )r%   zA\pgfpathrectangle{\pgfqpoint{%fin}{%fin}}{\pgfqpoint{%fin}{%fin}}r   N)rE   get_clip_rectangler   r.   r+   Zget_clip_pathr   )rR   r   r   bboxp1p2r   r   r   ZclippathZclippath_transs   &&         r#   r   Z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                s   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# )Zbuttz\pgfsetbuttcapZroundz\pgfsetroundcapZ
projectingz\pgfsetrectcapZmiterz\pgfsetmiterjoinz\pgfsetroundjoinZbevelz\pgfsetbeveljoinNr%   z(\definecolor{currentfill}{rgb}{%f,%f,%f}Ni   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}r2   c              3   s4   "   T F  pR V,          x  K  	  R# 5i)z{%fpt}Nrk   )r0   ZdashrU   r#   r1   Z5RendererPgf._print_pgf_path_styles.<locals>.<genexpr>"  s     GYT	D 0 0Ys   )r.   r+   Zget_capstyleZget_joinstyleZget_forced_alpha	get_alphaget_rgbrq   tupler   mpl_pt_to_inlatex_in_to_ptZ
get_dashesr   )rR   r   r   Z	capstylesZ
joinstylesZhas_fillZfillopacityZstrokeopacityZlwZstroke_rgbaZdash_offsetZ	dash_lists   &&&         r#   r   Z"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                s   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# )r%   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   )rE   r   r   ZmaxZminr   r   ZMOVETOr   r.   r+   Z	CLOSEPOLYZLINETOZCURVE3ZCURVE4Zget_sketch_paramsZint)rR   r   r"   r   r   r   r   r   r   r   r   pointsr   r   r   ZcxZcyZpxZpyr   Zc1xZc1yZc2xZc2yZsketch_paramsr   ZlengthZ
randomnesss   &&&&&                       r#   r   Z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                s    . 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)r3   r.   r+   r   )rR   r   r   Zactionss   &&& r#   r   ZRendererPgf._pgf_path_drawg  sB    NN8$NN6",sxx/@@Ar)   c                    R # )Trk   rt   r'   r#   option_scale_imageZRendererPgf.option_scale_imageo  s    r)   c                s:    \         P                  R ,          '       * # )zimage.composite_image)r   r   rt   r'   r#   option_image_nocompositeZ$RendererPgf.option_image_nocomposites  s    << 7888r)   c                s   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# ):Ni   NNr   r2   zXstreamed pgf-code does not support raster graphics, consider using the pgf-to-pdf optionz%s-img%d.pngr   r%   r   z/\pgfsys@transformcm{%f}{%f}{%f}{%f}{%fin}{%fin}zD\pgftext[left,bottom]{%s[interpolate=%s,width=%fin,height=%fin]{%s}}r   i)ZshaperA   r"   ZexistsZgetattrr+   r   r   r   r   Zstemr   r   Z	fromarrayZsaver   r.   r   rE   ZfrozenZ	to_valuesr:   Zlowerr   )rR   r   r   r   Zimr   r   r   r"   Z	fname_imgr   Ztr1Ztr2Ztr3Ztr4Ztr5Ztr6Zinterps   &&&&&&            r#   
draw_imageZ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               s2    V P                  WW4WVR VR7       R# )ZTeX)ismathr   N)	draw_text)rR   r   r   r   r5   r6   angler   s   &&&&&&&$r#   draw_texZRendererPgf.draw_tex  s    raDUKr)   c	                s   \        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   r%   r   r   r   z&\definecolor{textcolor}{rgb}{%f,%f,%f}z\pgfsetstrokecolor{textcolor}z\pgfsetfillcolor{textcolor}z\color{textcolor}ZanchorZcenter_baselineZleftZrightZcenterr2   ZtopZbottomZbaselineZbasezx=r   Zinzy=zin, y=zin, left, basez	rotate=%fz	\pgftext[r   z]{r   r   N)r7   r.   r+   r   r   r   r   r   rE   Zget_rotation_modeZget_verticalalignmentZget_unitless_positionZget_transformr   ZextendZget_horizontalalignmentr3   r   )rR   r   r   r   r5   r6   r   r   r   ZalphaZrgbrE   Z	text_argsZposZhalignZvaligns   &&&&&&&&&       r#   r   Z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                s    \         P                  4       P                  W4      w  rEp\        V P                  ,          pWG,          WW,          Wg,          3# r/   )ra   rj   r   r   rE   )rR   r5   r6   r   r   r   Zdr   s   &&&&    r#   get_text_width_height_descentZ)RendererPgf.get_text_width_height_descent  sG      224,,Q5 	a
 488#uaeQU""r)   c                r   )Frk   rt   r'   r#   flipyZRendererPgf.flipy  s    r)   c                s    V P                   P                  4       V P                  ,          V P                   P                  4       V P                  ,          3# r/   )r   get_figwidthrE   get_figheightrt   r'   r#   get_canvas_width_heightZ#RendererPgf.get_canvas_width_height  s>    ((*TXX5))+dhh68 	8r)   c                s>    V\         ,          V P                  ,          # r/   )r   rE   )rR   r   r-   r#   points_to_pixelsZRendererPgf.points_to_pixels  s    $txx//r)   )rE   r+   r   r   r/   )TF)FN)rW   rX   rY   rZ   rP   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r[   r\   r]   r^   r`   r#   r   r   n  sl     &$-L31j4(1&f@LDB9'-RL$ L.-`	#8
0 0r)   r   c                   sv   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 pictureZpngzPortable Network Graphicsc                r   )r   rk   rt   r'   r#   get_default_filetypeZ$FigureCanvasPgf.get_default_filetype  s    r)   bbox_inches_restoreNc          
     s   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)r$   r   r3   r   r   r   r   rE   r*   r.   r	   r   draw)
rR   r+   r   Zheader_textZheader_info_preambler,   r   r   rE   Zrenderers
   &&$       r#   _print_pgf_to_fhZ 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                s   \         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_cmZfile_requires_unicodecodecsZ	getwriterr   )rR   fname_or_fhkwargsZfiles   &&, r#   	print_pgfZFigureCanvasPgf.print_pgf-  sd    
 S7CCt..t44''06!!$1&1 DCCCs   AA88B		metadatac               s   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r/   r;   r0   ZkZvr   r#   r1   Z,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}rc   z
\centeringz\input{figure.pgf}z\end{document}r   r   rb   -interaction=nonstopmoder   r   
figure.pdfrbwbN)r   get_size_inchesr
   r   itemsr   r   r   r   Z
write_textrd   r$   r   r   r   _check_and_log_subprocessr4   openr   shutilcopyfileobj)rR   r   r   r   r   r   Z	info_dictpdfinforx   tmppath
texcommandorigdests   &&$,         r#   	print_pdfZ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                s6   \        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)rE   r   r   N)rM   r   r   r   r   r   rE   r   r   r   r   r   )
rR   r   r   Z	converterrx   r   Zpdf_pathZpng_pathr   r   s
   &&,       r#   	print_pngZ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                s.    \        V P                  R 4      # r/   )r   r   rt   r'   r#   get_rendererZFigureCanvasPgf.get_renderere  s    4;;--r)   c                sT   < V P                   P                  4        \        SV `  4       # r/   )r   Zdraw_without_renderingrO   r   )rR   rS   s   &r#   r   ZFigureCanvasPgf.drawh  s    **,w|~r)   rk   )rW   rX   rY   rZ   Z	filetypesr   r   r   r   r   r   r   r[   r\   r]   r^   r`   r#   r   r     sV     +437I6#$ 6#p2/ /B/. r)   r   c                   s    ] tR tRt]tRtR# )_BackendPgfip  rk   N)rW   rX   rY   rZ   r   ZFigureCanvasr[   rk   r)   r#   r   r   p  s    "Lr)   r   c                   s`   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               s    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_figuresZcopy	_metadatar
   
_info_dictr    _file)rR   Zfilenamer   s   &&$r#   rP   ZPdfPages.__init__  sB    . %"..b..0/t~~FY
r)   c           	     s    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   r   r/   r   r   r   r#   r1   Z)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   rd   r$   r  r*   Zencode)rR   Zwidth_inchesZheight_inchesr   re   s   &&&  r#   _write_headerZPdfPages._write_header  s    (( H/3/D/D/FH Hyy2W<G+,O* 	"
 	 	

,,W56r)   c                s    V # r/   rk   rt   r'   r#   	__enter__ZPdfPages.__enter__  s    r)   c                s&    V P                  4        R # r/   )close)rR   Zexc_typeZexc_valZexc_tbs   &&&&r#   __exit__ZPdfPages.__exit__  s    

r)   c                s    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  rt   r'   r#   r  ZPdfPages.close  s=    
 	

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

r)   c                s   \         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)rb   zpdf_pages.texr   r   r   z.pdfN)r   r   r   r   r   Zwrite_bytesr  Zgetvaluer   r   r4   r   ZmoveZwith_suffixr   )rR   r   rx   Z
tex_sources   &   r#   r  ZPdfPages._run_latex  s    \\/2
!!V fo>J""4::#6#6#89++79I&" KK
..v68I8IJ "!!!s   BCC	c                s   \        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   Zbackend)r8   r   r   Z
get_activeZget_fig_managerr   Zcanvasr   r   r   r  r  r*   savefig)rR   r   r   Zmanagerr   r   s   &&,   r#   r  ZPdfPages.savefig  s     &&))~..*--f5 :fX!677^^**F..0??au-
 JJ !/* 	tzzI%II&I1r)   c                s    V P                   # )z=Return the current number of pages in the multipage pdf file.)r   rt   r'   r#   get_pagecountZPdfPages.get_pagecount  s    r)   )r  r   r   r   r   r/   )rW   rX   rY   rZ   r   rP   r  r  r  r  r  r  r  r[   r\   r   rL   r#   r   r   u  s@     T :7	K"H r)   r   gRhV?gqq?)@r   r9   r}   Zior    Zloggingr   rA   r   r   r?   Ztempfiler   ry   ZPILr   Z
matplotlibr   r   r   r   Zmatplotlib.backend_basesr   r   r   r   Z!matplotlib.backends.backend_mixedr	   Zmatplotlib.backends.backend_pdfr
   r   Zmatplotlib.pathr   Zmatplotlib.figurer   Zmatplotlib.font_managerr   Zmatplotlib._pylab_helpersr   Z	getLoggerrW   r4   rd   r$   Zlatex_pt_to_inr   r   Zmpl_in_to_ptr(   r.   r7   r;   rM   r   rN   ra   r~   r   r   r   ZFigureManagerPgfZexportr   r   rk   r)   r#   <module>r	     s5         	    '    0  @-   $ 2 )" ,&V n$L =*Z A6	 	U Up Q |0, |0~}& }@ %  
#( # #} }r)   