@@ -846,7 +846,8 @@ def print_pgf(self, fname_or_fh, *args, **kwargs):
846
846
file = codecs .getwriter ("utf-8" )(file )
847
847
self ._print_pgf_to_fh (file , * args , ** kwargs )
848
848
849
- def _print_pdf_to_fh (self , fh , * args , metadata = None , ** kwargs ):
849
+ def print_pdf (self , fname_or_fh , * args , metadata = None , ** kwargs ):
850
+ """Use LaTeX to compile a pgf generated figure to pdf."""
850
851
w , h = self .figure .get_figwidth (), self .figure .get_figheight ()
851
852
852
853
info_dict = _create_pdf_info_dict ('pgf' , metadata or {})
@@ -879,29 +880,22 @@ def _print_pdf_to_fh(self, fh, *args, metadata=None, **kwargs):
879
880
[texcommand , "-interaction=nonstopmode" , "-halt-on-error" ,
880
881
"figure.tex" ], _log , cwd = tmpdir )
881
882
882
- with (tmppath / "figure.pdf" ).open ("rb" ) as fh_src :
883
- shutil .copyfileobj (fh_src , fh ) # copy file contents to target
883
+ with (tmppath / "figure.pdf" ).open ("rb" ) as orig , \
884
+ cbook .open_file_cm (fname_or_fh , "wb" ) as dest :
885
+ shutil .copyfileobj (orig , dest ) # copy file contents to target
884
886
885
- def print_pdf (self , fname_or_fh , * args , ** kwargs ):
886
- """Use LaTeX to compile a Pgf generated figure to PDF."""
887
- with cbook .open_file_cm (fname_or_fh , "wb" ) as file :
888
- self ._print_pdf_to_fh (file , * args , ** kwargs )
889
-
890
- def _print_png_to_fh (self , fh , * args , ** kwargs ):
887
+ def print_png (self , fname_or_fh , * args , ** kwargs ):
888
+ """Use LaTeX to compile a pgf figure to pdf and convert it to png."""
891
889
converter = make_pdf_to_png_converter ()
892
890
with TemporaryDirectory () as tmpdir :
893
891
tmppath = pathlib .Path (tmpdir )
894
892
pdf_path = tmppath / "figure.pdf"
895
893
png_path = tmppath / "figure.png"
896
894
self .print_pdf (pdf_path , * args , ** kwargs )
897
895
converter (pdf_path , png_path , dpi = self .figure .dpi )
898
- with png_path .open ("rb" ) as fh_src :
899
- shutil .copyfileobj (fh_src , fh ) # copy file contents to target
900
-
901
- def print_png (self , fname_or_fh , * args , ** kwargs ):
902
- """Use LaTeX to compile a pgf figure to pdf and convert it to png."""
903
- with cbook .open_file_cm (fname_or_fh , "wb" ) as file :
904
- self ._print_png_to_fh (file , * args , ** kwargs )
896
+ with png_path .open ("rb" ) as orig , \
897
+ cbook .open_file_cm (fname_or_fh , "wb" ) as dest :
898
+ shutil .copyfileobj (orig , dest ) # copy file contents to target
905
899
906
900
def get_renderer (self ):
907
901
return RendererPgf (self .figure , None )
0 commit comments