From 3ee2bffb50ea709cc792c3eaa3b161f8b419f384 Mon Sep 17 00:00:00 2001 From: andizq Date: Mon, 10 Jun 2024 01:55:01 -0400 Subject: [PATCH] refactor: add an optional argument to disable the display of open figures in plot_radial_profile() and allow for plot customisation through existing axes --- fil_finder/filament.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/fil_finder/filament.py b/fil_finder/filament.py index ec05578..70f9f38 100644 --- a/fil_finder/filament.py +++ b/fil_finder/filament.py @@ -1122,17 +1122,25 @@ def radprof_model(self): ''' return self._radprof_model - def plot_radial_profile(self, save_name=None, xunit=u.pix, - ax=None): + def plot_radial_profile(self, + ax=None, + save_name=None, + show_plot=True, + xunit=u.pix + ): ''' Plot the radial profile of the filament and the fitted model. Parameters ---------- - xunit : `~astropy.units.Unit`, optional - Pixel, angular, or physical unit to convert to. ax : `~matplotlib.axes`, optional Use an existing set of axes to plot the profile. + save_name : str, optional + Name of saved plot. A plot is only saved if a name is given. + show_plot : bool, optional + Display open figure. + xunit : `~astropy.units.Unit`, optional + Pixel, angular, or physical unit to convert to. ''' dist, radprof = self.radprofile @@ -1164,8 +1172,12 @@ def plot_radial_profile(self, save_name=None, xunit=u.pix, if save_name is not None: plt.savefig(save_name) - - plt.show() + if not show_plot: + plt.close() + + if show_plot: + plt.show() + if in_ipynb(): plt.clf()