@@ -33,6 +33,7 @@ def __init__(self, **kwargs):
3333 self ._width = kwargs .get ("width" , "17cm" )
3434 self ._ratio = kwargs .get ("ratio" , "golden" )
3535 self ._gridspec_kw = kwargs .get ("gridspec_kw" , {"wspace" : 0.08 , "hspace" : 0.1 })
36+ self ._plotted = False
3637
3738 # Dictionary to store lines for each subplot
3839 # Key: (row, col), Value: list of lines with their data and kwargs
@@ -126,6 +127,7 @@ def savefig(
126127 layers = None ,
127128 layer_by_layer = False ,
128129 verbose = False ,
130+ plot = True ,
129131 ):
130132 filename_no_extension , extension = os .path .splitext (filename )
131133 if backend == "matplotlib" :
@@ -145,10 +147,16 @@ def savefig(
145147 full_filepath = filename
146148 else :
147149 full_filepath = f"{ filename_no_extension } _{ layers } .{ extension } "
148- fig , axs = self .plot (
149- show = False , backend = "matplotlib" , savefig = True , layers = layers
150- )
151- fig .savefig (full_filepath )
150+ print (f"Save to { full_filepath } " )
151+ if self ._plotted :
152+ self ._matplotlib_fig .savefig (full_filepath )
153+ else :
154+
155+ fig , axs = self .plot (
156+ show = False , backend = "matplotlib" , savefig = True , layers = layers
157+ )
158+ print ('done plotting' )
159+ fig .savefig (full_filepath )
152160 if verbose :
153161 print (f"Saved { full_filepath } " )
154162
@@ -166,7 +174,7 @@ def plot_matplotlib(self, show=True, savefig=False, layers=None, usetex=False):
166174 filename (str, optional): Filename to save the figure.
167175 show (bool): Whether to display the plot.
168176 """
169-
177+ print ( f"Plotting with maxplotlib " )
170178 tex_fonts = plt_utils .setup_tex_fonts (fontsize = self .fontsize , usetex = usetex )
171179
172180 plt_utils .setup_plotstyle (
@@ -198,6 +206,7 @@ def plot_matplotlib(self, show=True, savefig=False, layers=None, usetex=False):
198206
199207 for (row , col ), subplot in self .subplots .items ():
200208 ax = axes [row ][col ]
209+ print (f"subplot.plot_matplotlib(ax, layers=layers)" )
201210 subplot .plot_matplotlib (ax , layers = layers )
202211 # ax.set_title(f"Subplot ({row}, {col})")
203212 ax .grid ()
@@ -208,6 +217,9 @@ def plot_matplotlib(self, show=True, savefig=False, layers=None, usetex=False):
208217 plt .show ()
209218 # else:
210219 # plt.close()
220+ self ._plotted = True
221+ self ._matplotlib_fig = fig
222+ self ._matplotlib_axes = axes
211223 return fig , axes
212224
213225 def plot_plotly (self , show = True , savefig = None , usetex = False ):
0 commit comments