@@ -390,7 +390,7 @@ def get_width_height_descent(self, text, prop):
390
390
391
391
class RendererPgf (RendererBase ):
392
392
393
- def __init__ (self , figure , fh ):
393
+ def __init__ (self , figure , fh , dummy = False ):
394
394
"""
395
395
Creates a new PGF renderer that translates any drawing instruction
396
396
into text commands to be interpreted in a latex pgfpicture environment.
@@ -408,6 +408,13 @@ def __init__(self, figure, fh):
408
408
# get LatexManager instance
409
409
self .latexManager = LatexManagerFactory .get_latex_manager ()
410
410
411
+ # dummy==True deactivate all methods
412
+ if dummy :
413
+ nop = lambda * args , ** kwargs : None
414
+ for m in RendererPgf .__dict__ .keys ():
415
+ if m .startswith ("draw_" ):
416
+ self .__dict__ [m ] = nop
417
+
411
418
def draw_markers (self , gc , marker_path , marker_trans , path , trans , rgbFace = None ):
412
419
writeln (self .fh , r"\begin{pgfscope}" )
413
420
@@ -741,6 +748,11 @@ def get_default_filetype(self):
741
748
return 'pdf'
742
749
743
750
def _print_pgf_to_fh (self , fh , * args , ** kwargs ):
751
+ if kwargs .get ("dryrun" , False ):
752
+ renderer = RendererPgf (self .figure , None , dummy = True )
753
+ self .figure .draw (renderer )
754
+ return
755
+
744
756
header_text = r"""%% Creator: Matplotlib, PGF backend
745
757
%%
746
758
%% To include the figure in your LaTeX document, write
@@ -797,6 +809,7 @@ def print_pgf(self, fname_or_fh, *args, **kwargs):
797
809
rendered in latex documents.
798
810
"""
799
811
if kwargs .get ("dryrun" , False ):
812
+ self ._print_pgf_to_fh (None , * args , ** kwargs )
800
813
return
801
814
802
815
# figure out where the pgf is to be written to
@@ -859,6 +872,10 @@ def print_pdf(self, fname_or_fh, *args, **kwargs):
859
872
"""
860
873
Use LaTeX to compile a Pgf generated figure to PDF.
861
874
"""
875
+ if kwargs .get ("dryrun" , False ):
876
+ self ._print_pgf_to_fh (None , * args , ** kwargs )
877
+ return
878
+
862
879
# figure out where the pdf is to be written to
863
880
if is_string_like (fname_or_fh ):
864
881
with open (fname_or_fh , "wb" ) as fh :
@@ -892,6 +909,10 @@ def print_png(self, fname_or_fh, *args, **kwargs):
892
909
"""
893
910
Use LaTeX to compile a pgf figure to pdf and convert it to png.
894
911
"""
912
+ if kwargs .get ("dryrun" , False ):
913
+ self ._print_pgf_to_fh (None , * args , ** kwargs )
914
+ return
915
+
895
916
if is_string_like (fname_or_fh ):
896
917
with open (fname_or_fh , "wb" ) as fh :
897
918
self ._print_png_to_fh (fh , * args , ** kwargs )
@@ -901,7 +922,7 @@ def print_png(self, fname_or_fh, *args, **kwargs):
901
922
raise ValueError ("filename must be a path or a file-like object" )
902
923
903
924
def get_renderer (self ):
904
- return RendererPgf (self .figure , None )
925
+ return RendererPgf (
87D4
self .figure , None , dummy = True )
905
926
906
927
907
928
class FigureManagerPgf (FigureManagerBase ):
0 commit comments