Skip to content

Commit

Permalink
add plot_kwargs to report methods
Browse files Browse the repository at this point in the history
**plot_kwargs added to FOOOF.report, FOOOF.save_report, and save_report_fm.
FOOOF.plot and plot_fm already had a plot_kwargs argument; however, this argument was not accessed in plot_fm so it was removed.
  • Loading branch information
mwprestonjr committed Jun 29, 2023
1 parent 6f185a6 commit 60f3295
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
19 changes: 4 additions & 15 deletions fooof/core/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
###################################################################################################

@check_dependency(plt, 'matplotlib')
def save_report_fm(fm, file_name, file_path=None, plot_peaks=None, plot_aperiodic=True,
plt_log=True, add_legend=True, data_kwargs=None, model_kwargs=None,
aperiodic_kwargs=None, peak_kwargs=None):
def save_report_fm(fm, file_name, file_path=None, plt_log=True, **plot_kwargs):
"""Generate and save out a PDF report for a power spectrum model fit.
Parameters
Expand All @@ -35,17 +33,10 @@ def save_report_fm(fm, file_name, file_path=None, plot_peaks=None, plot_aperiodi
Name to give the saved out file.
file_path : str, optional
Path to directory to save to. If None, saves to current directory.
plot_peaks : None or {'shade', 'dot', 'outline', 'line'}, optional
What kind of approach to take to plot peaks. If None, peaks are not specifically plotted.
Can also be a combination of approaches, separated by '-', for example: 'shade-line'.
plot_aperiodic : boolean, optional, default: True
Whether to plot the aperiodic component of the model fit.
plt_log : bool, optional, default: False
Whether or not to plot the frequency axis in log space.
add_legend : boolean, optional, default: False
Whether to add a legend describing the plot components.
data_kwargs, model_kwargs, aperiodic_kwargs, peak_kwargs : None or dict, optional
Keyword arguments to pass into the plot call for each plot element.
plot_kwargs : keyword arguments
Keyword arguments to pass into the plot method.
"""

# Set up outline figure, using gridspec
Expand All @@ -62,9 +53,7 @@ def save_report_fm(fm, file_name, file_path=None, plot_peaks=None, plot_aperiodi

# Second - data plot
ax1 = plt.subplot(grid[1])
fm.plot(plot_peaks=plot_peaks, plot_aperiodic=plot_aperiodic, plt_log=plt_log, add_legend=add_legend,
ax=ax1, data_kwargs=data_kwargs, model_kwargs=model_kwargs, aperiodic_kwargs=aperiodic_kwargs,
peak_kwargs=peak_kwargs)
fm.plot(plt_log=plt_log, ax=ax1, **plot_kwargs)

# Third - FOOOF settings
ax2 = plt.subplot(grid[2])
Expand Down
10 changes: 6 additions & 4 deletions fooof/objs/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def add_results(self, fooof_result):
self._check_loaded_results(fooof_result._asdict())


def report(self, freqs=None, power_spectrum=None, freq_range=None, plt_log=False):
def report(self, freqs=None, power_spectrum=None, freq_range=None, plt_log=False, **plot_kwargs):
"""Run model fit, and display a report, which includes a plot, and printed results.
Parameters
Expand All @@ -386,14 +386,16 @@ def report(self, freqs=None, power_spectrum=None, freq_range=None, plt_log=False
If not provided, fits across the entire given range.
plt_log : bool, optional, default: False
Whether or not to plot the frequency axis in log space.
**plot_kwargs
Keyword arguments to pass into the plot method.
Notes
-----
Data is optional, if data has already been added to the object.
"""

self.fit(freqs, power_spectrum, freq_range)
self.plot(plt_log=plt_log)
self.plot(plt_log=plt_log, **plot_kwargs)
self.print_results(concise=False)


Expand Down Expand Up @@ -642,9 +644,9 @@ def plot(self, plot_peaks=None, plot_aperiodic=True, plt_log=False,


@copy_doc_func_to_method(save_report_fm)
def save_report(self, file_name, file_path=None, plt_log=False):
def save_report(self, file_name, file_path=None, plt_log=False, **plot_kwargs):

save_report_fm(self, file_name, file_path, plt_log)
save_report_fm(self, file_name, file_path, plt_log, **plot_kwargs)


@copy_doc_func_to_method(save_fm)
Expand Down
4 changes: 1 addition & 3 deletions fooof/plts/fm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@check_dependency(plt, 'matplotlib')
def plot_fm(fm, plot_peaks=None, plot_aperiodic=True, plt_log=False, add_legend=True,
save_fig=False, file_name=None, file_path=None, ax=None, data_kwargs=None,
model_kwargs=None, aperiodic_kwargs=None, peak_kwargs=None, **plot_kwargs):
model_kwargs=None, aperiodic_kwargs=None, peak_kwargs=None):
"""Plot the power spectrum and model fit results from a FOOOF object.
Parameters
Expand All @@ -53,8 +53,6 @@ def plot_fm(fm, plot_peaks=None, plot_aperiodic=True, plt_log=False, add_legend=
Figure axes upon which to plot.
data_kwargs, model_kwargs, aperiodic_kwargs, peak_kwargs : None or dict, optional
Keyword arguments to pass into the plot call for each plot element.
**plot_kwargs
Keyword arguments to pass into the ``style_plot``.
Notes
-----
Expand Down

0 comments on commit 60f3295

Please sign in to comment.