-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathfg.py
More file actions
130 lines (105 loc) · 4.25 KB
/
fg.py
File metadata and controls
130 lines (105 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""Plots for the FOOOFGroup object.
Notes
-----
This file contains plotting functions that take as input a FOOOFGroup object.
"""
from fooof.core.errors import NoModelError
from fooof.core.modutils import safe_import, check_dependency
from fooof.plts.settings import PLT_FIGSIZES
from fooof.plts.templates import plot_scatter_1, plot_scatter_2, plot_hist
from fooof.plts.utils import savefig
from fooof.plts.style import style_plot
plt = safe_import('.pyplot', 'matplotlib')
gridspec = safe_import('.gridspec', 'matplotlib')
###################################################################################################
###################################################################################################
@savefig
@check_dependency(plt, 'matplotlib')
def plot_fg(fg, save_fig=False, file_name=None, file_path=None, **plot_kwargs):
"""Plot a figure with subplots visualizing the parameters from a FOOOFGroup object.
Parameters
----------
fg : FOOOFGroup
Object containing results from fitting a group of power spectra.
save_fig : bool, optional, default: False
Whether to save out a copy of the plot.
file_name : str, optional
Name to give the saved out file.
file_path : Path or str, optional
Path to directory to save to. If None, saves to current directory.
**plot_kwargs
Additional plot related keyword arguments, with styling options managed by ``style_plot``.
Raises
------
NoModelError
If the FOOOF object does not have model fit data available to plot.
"""
if not fg.has_model:
raise NoModelError("No model fit results are available, can not proceed.")
fig = plt.figure(figsize=plot_kwargs.pop('figsize', PLT_FIGSIZES['group']))
gs = gridspec.GridSpec(2, 2, wspace=0.35, hspace=0.35, height_ratios=[1, 1.2])
# Apply scatter kwargs to all subplots
scatter_kwargs = plot_kwargs
scatter_kwargs['all_axes'] = True
# Aperiodic parameters plot
ax0 = plt.subplot(gs[0, 0])
plot_fg_ap(fg, ax0, **scatter_kwargs, custom_styler=None)
# Goodness of fit plot
ax1 = plt.subplot(gs[0, 1])
plot_fg_gf(fg, ax1, **scatter_kwargs, custom_styler=None)
# Center frequencies plot
ax2 = plt.subplot(gs[1, :])
plot_fg_peak_cens(fg, ax2, **plot_kwargs, custom_styler=None)
@savefig
@style_plot
@check_dependency(plt, 'matplotlib')
def plot_fg_ap(fg, ax=None, **plot_kwargs):
"""Plot aperiodic fit parameters, in a scatter plot.
Parameters
----------
fg : FOOOFGroup
Object to plot data from.
ax : matplotlib.Axes, optional
Figure axes upon which to plot.
**plot_kwargs
Additional plot related keyword arguments, with styling options managed by ``style_plot``.
"""
if fg.aperiodic_mode == 'knee':
plot_scatter_2(fg.get_params('aperiodic_params', 'exponent'), 'Exponent',
fg.get_params('aperiodic_params', 'knee'), 'Knee',
'Aperiodic Fit', ax=ax)
else:
plot_scatter_1(fg.get_params('aperiodic_params', 'exponent'), 'Exponent',
'Aperiodic Fit', ax=ax)
@savefig
@style_plot
@check_dependency(plt, 'matplotlib')
def plot_fg_gf(fg, ax=None, **plot_kwargs):
"""Plot goodness of fit results, in a scatter plot.
Parameters
----------
fg : FOOOFGroup
Object to plot data from.
ax : matplotlib.Axes, optional
Figure axes upon which to plot.
**plot_kwargs
Additional plot related keyword arguments, with styling options managed by ``style_plot``.
"""
plot_scatter_2(fg.get_params('error'), 'Error',
fg.get_params('r_squared'), 'R^2', 'Goodness of Fit', ax=ax)
@savefig
@style_plot
@check_dependency(plt, 'matplotlib')
def plot_fg_peak_cens(fg, ax=None, **plot_kwargs):
"""Plot peak center frequencies, in a histogram.
Parameters
----------
fg : FOOOFGroup
Object to plot data from.
ax : matplotlib.Axes, optional
Figure axes upon which to plot.
**plot_kwargs
Additional plot related keyword arguments, with styling options managed by ``style_plot``.
"""
plot_hist(fg.get_params('peak_params', 0)[:, 0], 'Center Frequency',
'Peaks - Center Frequencies', x_lims=fg.freq_range, ax=ax)