66from fooof .core .errors import NoModelError
77from fooof .core .funcs import gaussian_function
88from fooof .core .modutils import safe_import , check_dependency
9+
910from fooof .sim .gen import gen_aperiodic
10- from fooof .plts .utils import check_ax
11- from fooof .plts .spectra import plot_spectra
12- from fooof .plts .settings import PLT_FIGSIZES , PLT_COLORS
13- from fooof .plts .style import check_n_style , style_spectrum_plot
1411from fooof .analysis .periodic import get_band_peak_fm
1512from fooof .utils .params import compute_knee_frequency , compute_fwhm
1613
14+ from fooof .plts .spectra import plot_spectra
15+ from fooof .plts .utils import check_ax , savefig
16+ from fooof .plts .settings import PLT_FIGSIZES , PLT_COLORS
17+ from fooof .plts .style import style_spectrum_plot
18+
1719plt = safe_import ('.pyplot' , 'matplotlib' )
1820mpatches = safe_import ('.patches' , 'matplotlib' )
1921
2022###################################################################################################
2123###################################################################################################
2224
25+ @savefig
2326@check_dependency (plt , 'matplotlib' )
24- def plot_annotated_peak_search (fm , plot_style = style_spectrum_plot ):
27+ def plot_annotated_peak_search (fm ):
2528 """Plot a series of plots illustrating the peak search from a flattened spectrum.
2629
2730 Parameters
2831 ----------
2932 fm : FOOOF
3033 FOOOF object, with model fit, data and settings available.
31- plot_style : callable, optional, default: style_spectrum_plot
32- A function to call to apply styling & aesthetics to the plots.
3334 """
3435
3536 # Recalculate the initial aperiodic fit and flattened spectrum that
@@ -46,14 +47,12 @@ def plot_annotated_peak_search(fm, plot_style=style_spectrum_plot):
4647 # This forces the creation of a new plotting axes per iteration
4748 ax = check_ax (None , PLT_FIGSIZES ['spectral' ])
4849
49- plot_spectra (fm .freqs , flatspec , ax = ax , plot_style = None ,
50- label = 'Flattened Spectrum' , color = PLT_COLORS ['data' ], linewidth = 2.5 )
51- plot_spectra (fm .freqs , [fm .peak_threshold * np .std (flatspec )]* len (fm .freqs ),
52- ax = ax , plot_style = None , label = 'Relative Threshold' ,
53- color = 'orange' , linewidth = 2.5 , linestyle = 'dashed' )
54- plot_spectra (fm .freqs , [fm .min_peak_height ]* len (fm .freqs ),
55- ax = ax , plot_style = None , label = 'Absolute Threshold' ,
56- color = 'red' , linewidth = 2.5 , linestyle = 'dashed' )
50+ plot_spectra (fm .freqs , flatspec , ax = ax , linewidth = 2.5 ,
51+ label = 'Flattened Spectrum' , color = PLT_COLORS ['data' ])
52+ plot_spectra (fm .freqs , [fm .peak_threshold * np .std (flatspec )]* len (fm .freqs ), ax = ax ,
53+ label = 'Relative Threshold' , color = 'orange' , linewidth = 2.5 , linestyle = 'dashed' )
54+ plot_spectra (fm .freqs , [fm .min_peak_height ]* len (fm .freqs ), ax = ax ,
55+ label = 'Absolute Threshold' , color = 'red' , linewidth = 2.5 , linestyle = 'dashed' )
5756
5857 maxi = np .argmax (flatspec )
5958 ax .plot (fm .freqs [maxi ], flatspec [maxi ], '.' ,
@@ -65,18 +64,18 @@ def plot_annotated_peak_search(fm, plot_style=style_spectrum_plot):
6564 if ind < fm .n_peaks_ :
6665
6766 gauss = gaussian_function (fm .freqs , * fm .gaussian_params_ [ind , :])
68- plot_spectra (fm .freqs , gauss , ax = ax , plot_style = None ,
69- label = 'Gaussian Fit' , color = PLT_COLORS ['periodic' ],
70- linestyle = ':' , linewidth = 3.0 )
67+ plot_spectra (fm .freqs , gauss , ax = ax , label = 'Gaussian Fit' ,
68+ color = PLT_COLORS ['periodic' ], linestyle = ':' , linewidth = 3.0 )
7169
7270 flatspec = flatspec - gauss
7371
74- check_n_style ( plot_style , ax , False , True )
72+ style_spectrum_plot ( ax , False , True )
7573
7674
75+ @savefig
7776@check_dependency (plt , 'matplotlib' )
78- def plot_annotated_model (fm , plt_log = False , annotate_peaks = True , annotate_aperiodic = True ,
79- ax = None , plot_style = style_spectrum_plot ):
77+ def plot_annotated_model (fm , plt_log = False , annotate_peaks = True ,
78+ annotate_aperiodic = True , ax = None ):
8079 """Plot a an annotated power spectrum and model, from a FOOOF object.
8180
8281 Parameters
@@ -91,8 +90,6 @@ def plot_annotated_model(fm, plt_log=False, annotate_peaks=True, annotate_aperio
9190 Whether to annotate the aperiodic components of the model fit.
9291 ax : matplotlib.Axes, optional
9392 Figure axes upon which to plot.
94- plot_style : callable, optional, default: style_spectrum_plot
95- A function to call to apply styling & aesthetics to the plots.
9693
9794 Raises
9895 ------
@@ -112,7 +109,7 @@ def plot_annotated_model(fm, plt_log=False, annotate_peaks=True, annotate_aperio
112109
113110 # Create the baseline figure
114111 ax = check_ax (ax , PLT_FIGSIZES ['spectral' ])
115- fm .plot (plot_peaks = 'dot-shade-width' , plt_log = plt_log , ax = ax , plot_style = None ,
112+ fm .plot (plot_peaks = 'dot-shade-width' , plt_log = plt_log , ax = ax ,
116113 data_kwargs = {'lw' : lw1 , 'alpha' : 0.6 },
117114 aperiodic_kwargs = {'lw' : lw1 , 'zorder' : 10 },
118115 model_kwargs = {'lw' : lw1 , 'alpha' : 0.5 },
@@ -219,7 +216,7 @@ def plot_annotated_model(fm, plt_log=False, annotate_peaks=True, annotate_aperio
219216 color = PLT_COLORS ['aperiodic' ], fontsize = fontsize )
220217
221218 # Apply style to plot & tune grid styling
222- check_n_style ( plot_style , ax , plt_log , True )
219+ style_spectrum_plot ( ax , plt_log , True )
223220 ax .grid (True , alpha = 0.5 )
224221
225222 # Add labels to plot in the legend
0 commit comments