@@ -392,7 +392,7 @@ def get_width_height_descent(self, text, prop):
392
392
393
393
class RendererPgf (RendererBase ):
394
394
395
- def __init__ (self , figure , fh ):
395
+ def __init__ (self , figure , fh , dummy = False ):
396
396
"""
397
397
Creates a new PGF renderer that translates any drawing instruction
398
398
into text commands to be interpreted in a latex pgfpicture environment.
@@ -410,6 +410,13 @@ def __init__(self, figure, fh):
410
410
# get LatexManager instance
411
411
self .latexManager = LatexManagerFactory .get_latex_manager ()
412
412
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
+
413
420
def draw_markers (self , gc , marker_path , marker_trans , path , trans , rgbFace = None ):
414
421
writeln (self .fh , r"\begin{pgfscope}" )
415
422
@@ -743,6 +750,11 @@ def get_default_filetype(self):
743
750
return 'pdf'
744
751
745
752
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
+
746
758
header_text = """%% Creator: Matplotlib, PGF backend
747
759
%%
748
760
%% To include the figure in your LaTeX document, write
@@ -799,6 +811,7 @@ def print_pgf(self, fname_or_fh, *args, **kwargs):
799
811
rendered in latex documents.
800
812
"""
801
813
if kwargs .get ("dryrun" , False ):
814
+ self ._print_pgf_to_fh (None , * args , ** kwargs )
802
815
return
803
816
804
817
# figure out where the pgf is to be written to
@@ -861,6 +874,10 @@ def print_pdf(self, fname_or_fh, *args, **kwargs):
861
874
"""
862
875
Use LaTeX to compile a Pgf generated figure to PDF.
863
876
"""
877
+ if kwargs .get ("dryrun" , False ):
878
+ self ._print_pgf_to_fh (None , * args , ** kwargs )
879
+ return
880
+
864
881
# figure out where the pdf is to be written to
865
882
if is_string_like (fname_or_fh ):
866
883
with open (fname_or_fh , "wb" ) as fh :
@@ -894,6 +911,10 @@ def print_png(self, fname_or_fh, *args, **kwargs):
894
911
"""
895
912
Use LaTeX to compile a pgf figure to pdf and convert it to png.
896
913
"""
914
+ if kwargs .get ("dryrun" , False ):
915
+ self ._print_pgf_to_fh (None , * args , ** kwargs )
916
+ return
917
+
897
918
if is_string_like (fname_or_fh ):
898
919
with open (fname_or_fh , "wb" ) as fh :
899
920
self ._print_png_to_fh (fh , * args , ** kwargs )
@@ -903,7 +924,7 @@ def print_png(self, fname_or_fh, *args, **kwargs):
903
924
raise ValueError ("filename must be a path or a file-like object" )
904
925
905
926
def get_renderer (self ):
906
- return RendererPgf (self .figure , None )
927
+ return RendererPgf (self .figure , None , dummy = True )
907
928
908
929
909
930
class FigureManagerPgf (FigureManagerBase ):
0 commit comments