1313import  matplotlib  as  mpl 
1414from  matplotlib .backend_bases  import  RendererBase , GraphicsContextBase ,\
1515    FigureManagerBase , FigureCanvasBase 
16+ from  matplotlib .backends .backend_mixed  import  MixedModeRenderer 
1617from  matplotlib .figure  import  Figure 
1718from  matplotlib .text  import  Text 
1819from  matplotlib .path  import  Path 
@@ -738,7 +739,7 @@ def __init__(self, *args):
738739    def  get_default_filetype (self ):
739740        return  'pdf' 
740741
741-     def  _print_pgf_to_fh (self , fh ):
742+     def  _print_pgf_to_fh (self , fh ,  * args ,  ** kwargs ):
742743        header_text  =  r"""%% Creator: Matplotlib, PGF backend 
743744%% 
744745%% To include the figure in your LaTeX document, write 
@@ -767,6 +768,7 @@ def _print_pgf_to_fh(self, fh):
767768
768769        # get figure size in inch 
769770        w , h  =  self .figure .get_figwidth (), self .figure .get_figheight ()
771+         dpi  =  self .figure .get_dpi ()
770772
771773        # create pgfpicture environment and write the pgf code 
772774        fh .write (header_text )
@@ -777,7 +779,10 @@ def _print_pgf_to_fh(self, fh):
777779        writeln (fh , r"\begin{pgfpicture}" )
778780        writeln (fh , r"\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{%fin}{%fin}}"  %  (w , h ))
779781        writeln (fh , r"\pgfusepath{use as bounding box}" )
780-         renderer  =  RendererPgf (self .figure , fh )
782+         _bbox_inches_restore  =  kwargs .pop ("bbox_inches_restore" , None )
783+         renderer  =  MixedModeRenderer (self .figure , w , h , dpi ,
784+                                      RendererPgf (self .figure , fh ),
785+                                      bbox_inches_restore = _bbox_inches_restore )
781786        self .figure .draw (renderer )
782787
783788        # end the pgfpicture environment 
@@ -796,14 +801,14 @@ def print_pgf(self, fname_or_fh, *args, **kwargs):
796801        # figure out where the pgf is to be written to 
797802        if  is_string_like (fname_or_fh ):
798803            with  codecs .open (fname_or_fh , "w" , encoding = "utf-8" ) as  fh :
799-                 self ._print_pgf_to_fh (fh )
804+                 self ._print_pgf_to_fh (fh ,  * args ,  ** kwargs )
800805        elif  is_writable_file_like (fname_or_fh ):
801806            raise  ValueError ("saving pgf to a stream is not supported, "  + 
802807                             "consider using the pdf option of the pgf-backend" )
803808        else :
804809            raise  ValueError ("filename must be a path" )
805810
806-     def  _print_pdf_to_fh (self , fh ):
811+     def  _print_pdf_to_fh (self , fh ,  * args ,  ** kwargs ):
807812        w , h  =  self .figure .get_figwidth (), self .figure .get_figheight ()
808813
809814        try :
@@ -814,7 +819,7 @@ def _print_pdf_to_fh(self, fh):
814819            fname_pdf  =  os .path .join (tmpdir , "figure.pdf" )
815820
816821            # print figure to pgf and compile it with latex 
817-             self .print_pgf (fname_pgf )
822+             self .print_pgf (fname_pgf ,  * args ,  ** kwargs )
818823
819824            latex_preamble  =  get_preamble ()
820825            latex_fontspec  =  get_fontspec ()
@@ -856,13 +861,13 @@ def print_pdf(self, fname_or_fh, *args, **kwargs):
856861        # figure out where the pdf is to be written to 
857862        if  is_string_like (fname_or_fh ):
858863            with  open (fname_or_fh , "wb" ) as  fh :
859-                 self ._print_pdf_to_fh (fh )
864+                 self ._print_pdf_to_fh (fh ,  * args ,  ** kwargs )
860865        elif  is_writable_file_like (fname_or_fh ):
861-             self ._print_pdf_to_fh (fname_or_fh )
866+             self ._print_pdf_to_fh (fname_or_fh ,  * args ,  ** kwargs )
862867        else :
863868            raise  ValueError ("filename must be a path or a file-like object" )
864869
865-     def  _print_png_to_fh (self , fh ):
870+     def  _print_png_to_fh (self , fh ,  * args ,  ** kwargs ):
866871        converter  =  make_pdf_to_png_converter ()
867872
868873        try :
@@ -871,7 +876,7 @@ def _print_png_to_fh(self, fh):
871876            fname_pdf  =  os .path .join (tmpdir , "figure.pdf" )
872877            fname_png  =  os .path .join (tmpdir , "figure.png" )
873878            # create pdf and try to convert it to png 
874-             self .print_pdf (fname_pdf )
879+             self .print_pdf (fname_pdf ,  * args ,  ** kwargs )
875880            converter (fname_pdf , fname_png , dpi = self .figure .dpi )
876881            # copy file contents to target 
877882            with  open (fname_png , "rb" ) as  fh_src :
@@ -888,9 +893,9 @@ def print_png(self, fname_or_fh, *args, **kwargs):
888893        """ 
889894        if  is_string_like (fname_or_fh ):
890895            with  open (fname_or_fh , "wb" ) as  fh :
891-                 self ._print_png_to_fh (fh )
896+                 self ._print_png_to_fh (fh ,  * args ,  ** kwargs )
892897        elif  is_writable_file_like (fname_or_fh ):
893-             self ._print_png_to_fh (fname_or_fh )
898+             self ._print_png_to_fh (fname_or_fh ,  * args ,  ** kwargs )
894899        else :
895900            raise  ValueError ("filename must be a path or a file-like object" )
896901
0 commit comments