55This file contains functions for plotting power spectra, that take in data directly.
66"""
77
8+ from itertools import repeat
9+
810import numpy as np
911
1012from fooof .core .modutils import safe_import , check_dependency
@@ -59,20 +61,21 @@ def plot_spectrum(freqs, power_spectrum, log_freqs=False, log_powers=False,
5961
6062
6163@check_dependency (plt , 'matplotlib' )
62- def plot_spectra (freqs , power_spectra , log_freqs = False , log_powers = False ,
64+ def plot_spectra (freqs , power_spectra , log_freqs = False , log_powers = False , labels = None ,
6365 ax = None , style_plot = style_spectrum_plot , ** kwargs ):
6466 """Plot multiple power spectra on the same plot.
6567
6668 Parameters
6769 ----------
68- freqs : 1d array
70+ freqs : 2d array or 1d array or list of 1d array
6971 X-axis data, frequency values.
70- power_spectra : list of 1d array
72+ power_spectra : 2d array or list of 1d array
7173 Y-axis data, power values for spectra to plot.
7274 log_freqs : boolean, optional, default: False
7375 Whether or not to take the log of the power axis before plotting.
7476 log_powers : boolean, optional, default: False
7577 Whether or not to take the log of the power axis before plotting.
78+ labels " "
7679 ax : matplotlib.Axes, optional
7780 Figure axes upon which to plot.
7881 style_plot : callable, optional, default: style_spectrum_plot
@@ -81,9 +84,12 @@ def plot_spectra(freqs, power_spectra, log_freqs=False, log_powers=False,
8184 Keyword arguments to be passed to the plot call.
8285 """
8386
87+ freqs = repeat (freqs ) if isinstance (freqs , np .ndarray ) and freqs .ndim == 1 else freqs
88+ labels = repeat (labels ) if not isinstance (labels , list ) else labels
89+
8490 ax = check_ax (ax )
85- for power_spectrum in power_spectra :
86- plot_spectrum (freqs , power_spectrum , log_freqs , log_powers ,
91+ for freq , power_spectrum , label in zip ( freqs , power_spectra , labels ) :
92+ plot_spectrum (freq , power_spectrum , log_freqs , log_powers , label = label ,
8793 style_plot = None , ax = ax , ** kwargs )
8894 check_n_style (style_plot , ax , log_freqs , log_powers )
8995
@@ -97,7 +103,7 @@ def plot_spectrum_shading(freqs, power_spectrum, shades, add_center=False,
97103 ----------
98104 freqs : 1d array
99105 X-axis data, frequency values.
100- power_spectrum : list of 1d array
106+ power_spectrum : 1d array
101107 Y-axis data, power values for spectrum to plot.
102108 shades : list of [float, float] or list of list of [float, float]
103109 Shaded region(s) to add to plot, defined as [lower_bound, upper_bound].
@@ -124,9 +130,9 @@ def plot_spectra_shading(freqs, power_spectra, shades, add_center=False,
124130
125131 Parameters
126132 ----------
127- freqs : 1d array
133+ freqs : 2d array or 1d array or list of 1d array
128134 X-axis data, frequency values.
129- power_spectra : list of 1d array
135+ power_spectra : 2d array or list of 1d array
130136 Y-axis data, power values for spectra to plot.
131137 shades : list of [float, float] or list of list of [float, float]
132138 Shaded region(s) to add to plot, defined as [lower_bound, upper_bound].
@@ -137,7 +143,12 @@ def plot_spectra_shading(freqs, power_spectra, shades, add_center=False,
137143 style_plot : callable, optional, default: style_spectrum_plot
138144 A function to call to apply styling & aesthetics to the plot.
139145 **kwargs
140- Keyword arguments to be passed to the plot call.
146+ Keyword arguments to be passed to plot_spectra or the plot call.
147+
148+ Notes
149+ -----
150+ Parameters for `plot_spectra` can also be passed into this function as **kwargs.
151+ This includes `log_freqs`, `log_powers` & `labels`. See `plot_spectra for usage details.
141152 """
142153
143154 ax = check_ax (ax )
0 commit comments