2525@savefig
2626@style_plot
2727@check_dependency (plt , 'matplotlib' )
28- def plot_fm (fm , plot_peaks = None , plot_aperiodic = True , plt_log = False , add_legend = True ,
29- save_fig = False , file_name = None , file_path = None , ax = None , data_kwargs = None ,
30- model_kwargs = None , aperiodic_kwargs = None , peak_kwargs = None , ** plot_kwargs ):
28+ def plot_fm (fm , plot_peaks = None , plot_aperiodic = True , freqs = None , power_spectrum = None ,
29+ freq_range = None , plt_log = False , add_legend = True , save_fig = False , file_name = None ,
30+ file_path = None , ax = None , data_kwargs = None , model_kwargs = None , aperiodic_kwargs = None ,
31+ peak_kwargs = None , ** plot_kwargs ):
3132 """Plot the power spectrum and model fit results from a FOOOF object.
3233
3334 Parameters
@@ -39,6 +40,14 @@ def plot_fm(fm, plot_peaks=None, plot_aperiodic=True, plt_log=False, add_legend=
3940 Can also be a combination of approaches, separated by '-', for example: 'shade-line'.
4041 plot_aperiodic : boolean, optional, default: True
4142 Whether to plot the aperiodic component of the model fit.
43+ freqs : 1d array, optional
44+ Frequency values of the power spectrum to plot, in linear space.
45+ If provided, this overrides the values in the model object.
46+ power_spectrum : 1d array, optional
47+ Power values to plot, in linear space.
48+ If provided, this overrides the values in the model object.
49+ freq_range : list of [float, float], optional
50+ Frequency range to plot, defined in linear space.
4251 plt_log : boolean, optional, default: False
4352 Whether to plot the frequency values in log10 spacing.
4453 add_legend : boolean, optional, default: False
@@ -64,16 +73,22 @@ def plot_fm(fm, plot_peaks=None, plot_aperiodic=True, plt_log=False, add_legend=
6473
6574 ax = check_ax (ax , plot_kwargs .pop ('figsize' , PLT_FIGSIZES ['spectral' ]))
6675
76+ # Check inputs for what to plot
77+ custom_spectrum = (np .any (freqs ) and np .any (power_spectrum ))
78+
6779 # Log settings - note that power values in FOOOF objects are already logged
6880 log_freqs = plt_log
6981 log_powers = False
7082
7183 # Plot the data, if available
72- if fm .has_data :
84+ if fm .has_data or custom_spectrum :
7385 data_defaults = {'color' : PLT_COLORS ['data' ], 'linewidth' : 2.0 ,
7486 'label' : 'Original Spectrum' if add_legend else None }
7587 data_kwargs = check_plot_kwargs (data_kwargs , data_defaults )
76- plot_spectra (fm .freqs , fm .power_spectrum , log_freqs , log_powers , ax = ax , ** data_kwargs )
88+ plot_spectra (freqs if custom_spectrum else fm .freqs ,
89+ power_spectrum if custom_spectrum else fm .power_spectrum ,
90+ log_freqs , log_powers if not custom_spectrum else True ,
91+ freq_range , ax = ax , ** data_kwargs )
7792
7893 # Add the full model fit, and components (if requested)
7994 if fm .has_model :
0 commit comments