File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -199,11 +199,28 @@ def decorated(*args, **kwargs):
199199 func (* args , ** kwargs )
200200
201201 if save_fig :
202- if not file_name :
203- raise ValueError ("Input 'file_name' is required to save out the plot." )
204- plt .savefig (fpath (file_path , fname (file_name , 'png' )), ** save_kwargs )
205-
206- if close :
207- plt .close ()
202+ save_figure (file_name , file_path , close , ** save_kwargs )
208203
209204 return decorated
205+
206+
207+ def save_figure (file_name , file_path = None , close = False , ** save_kwargs ):
208+ """Save out a figure.
209+
210+ Parameters
211+ ----------
212+ file_name : str
213+ File name for the figure file to save out.
214+ file_path : str or Path
215+ Path for where to save out the figure to.
216+ close : bool, optional, default: False
217+ Whether to close the plot after saving.
218+ save_kwargs
219+ Additional arguments to pass into the save function.
220+ """
221+
222+ full_path = fpath (file_path , fname (file_name , 'png' ))
223+ plt .savefig (full_path , ** save_kwargs )
224+
225+ if close :
226+ plt .close ()
Original file line number Diff line number Diff line change @@ -95,3 +95,9 @@ def example_plot():
9595 # Test does not save when `save_fig` set to False
9696 example_plot (save_fig = False , file_path = TEST_PLOTS_PATH , file_name = 'test_savefig_nope.pdf' )
9797 assert not os .path .exists (os .path .join (TEST_PLOTS_PATH , 'test_savefig_nope.pdf' ))
98+
99+ def test_save_figure ():
100+
101+ plt .plot ([1 , 2 ], [3 , 4 ])
102+ save_figure (file_name = 'test_save_figure.pdf' , file_path = TEST_PLOTS_PATH )
103+ assert os .path .exists (os .path .join (TEST_PLOTS_PATH , 'test_save_figure.pdf' ))
You can’t perform that action at this time.
0 commit comments