@@ -392,7 +392,7 @@ def get_width_height_descent(self, text, prop):
392392
393393class  RendererPgf (RendererBase ):
394394
395-     def  __init__ (self , figure , fh ):
395+     def  __init__ (self , figure , fh ,  dummy = False ):
396396        """ 
397397        Creates a new PGF renderer that translates any drawing instruction 
398398        into text commands to be interpreted in a latex pgfpicture environment. 
@@ -410,6 +410,13 @@ def __init__(self, figure, fh):
410410        # get LatexManager instance 
411411        self .latexManager  =  LatexManagerFactory .get_latex_manager ()
412412
413+         # dummy==True deactivate all methods 
414+         if  dummy :
415+             nop  =  lambda  * args , ** kwargs : None 
416+             for  m  in  RendererPgf .__dict__ .keys ():
417+                 if  m .startswith ("draw_" ):
418+                     self .__dict__ [m ] =  nop 
419+ 
413420    def  draw_markers (self , gc , marker_path , marker_trans , path , trans , rgbFace = None ):
414421        writeln (self .fh , r"\begin{pgfscope}" )
415422
@@ -743,6 +750,11 @@ def get_default_filetype(self):
743750        return  'pdf' 
744751
745752    def  _print_pgf_to_fh (self , fh , * args , ** kwargs ):
753+         if  kwargs .get ("dryrun" , False ):
754+             renderer  =  RendererPgf (self .figure , None , dummy = True )
755+             self .figure .draw (renderer )
756+             return 
757+ 
746758        header_text  =  """%% Creator: Matplotlib, PGF backend 
747759%% 
748760%% To include the figure in your LaTeX document, write 
@@ -799,6 +811,7 @@ def print_pgf(self, fname_or_fh, *args, **kwargs):
799811        rendered in latex documents. 
800812        """ 
801813        if  kwargs .get ("dryrun" , False ):
814+             self ._print_pgf_to_fh (None , * args , ** kwargs )
802815            return 
803816
804817        # figure out where the pgf is to be written to 
@@ -861,6 +874,10 @@ def print_pdf(self, fname_or_fh, *args, **kwargs):
861874        """ 
862875        Use LaTeX to compile a Pgf generated figure to PDF. 
863876        """ 
877+         if  kwargs .get ("dryrun" , False ):
878+             self ._print_pgf_to_fh (None , * args , ** kwargs )
879+             return 
880+ 
864881        # figure out where the pdf is to be written to 
865882        if  is_string_like (fname_or_fh ):
866883            with  open (fname_or_fh , "wb" ) as  fh :
@@ -894,6 +911,10 @@ def print_png(self, fname_or_fh, *args, **kwargs):
894911        """ 
895912        Use LaTeX to compile a pgf figure to pdf and convert it to png. 
896913        """ 
914+         if  kwargs .get ("dryrun" , False ):
915+             self ._print_pgf_to_fh (None , * args , ** kwargs )
916+             return 
917+ 
897918        if  is_string_like (fname_or_fh ):
898919            with  open (fname_or_fh , "wb" ) as  fh :
899920                self ._print_png_to_fh (fh , * args , ** kwargs )
@@ -903,7 +924,7 @@ def print_png(self, fname_or_fh, *args, **kwargs):
903924            raise  ValueError ("filename must be a path or a file-like object" )
904925
905926    def  get_renderer (self ):
906-         return  RendererPgf (self .figure , None )
927+         return  RendererPgf (self .figure , None ,  dummy = True )
907928
908929
909930class  FigureManagerPgf (FigureManagerBase ):
0 commit comments