Skip to content

Commit d63aae0

Browse files
committed
fix list input to plot_spectra
1 parent 6f48eed commit d63aae0

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

fooof/plts/spectra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def plot_spectra(freqs, power_spectra, log_freqs=False, log_powers=False, freq_r
6060
freq_range = np.log10(freq_range) if log_freqs else freq_range
6161

6262
# Make inputs iterable if need to be passed multiple times to plot each spectrum
63-
plt_powers = np.reshape(power_spectra, (1, -1)) if np.ndim(power_spectra) == 1 else \
64-
power_spectra
63+
plt_powers = np.reshape(power_spectra, (1, -1)) if isinstance(freqs, np.ndarray) and \
64+
np.ndim(power_spectra) == 1 else power_spectra
6565
plt_freqs = repeat(freqs) if isinstance(freqs, np.ndarray) and freqs.ndim == 1 else freqs
6666

6767
# Set labels

fooof/tests/plts/test_spectra.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,31 @@
1515
@plot_test
1616
def test_plot_spectra(tfm, tfg, skip_if_no_mpl):
1717

18-
# Test with 1d inputs - 1d freq array and list of 1d power spectra
18+
# Test with 1d inputs - 1d freq array & list of 1d power spectra
1919
plot_spectra(tfm.freqs, tfm.power_spectrum,
2020
save_fig=True, file_path=TEST_PLOTS_PATH, file_name='test_plot_spectra_1d.png')
2121

22-
# Test with 1d inputs - 1d freq array and list of 1d power spectra
22+
# Test with 1d inputs - 1d freq array & list of 1d power spectra
2323
plot_spectra(tfg.freqs, [tfg.power_spectra[0, :], tfg.power_spectra[1, :]],
24-
save_fig=True, file_path=TEST_PLOTS_PATH, file_name='test_plot_spectra_list_1d.png')
24+
save_fig=True, file_path=TEST_PLOTS_PATH,
25+
file_name='test_plot_spectra_list_1d.png')
2526

26-
# Test with multiple freq inputs - list of 1d freq array and list of 1d power spectra
27-
plot_spectra([tfg.freqs, tfg.freqs], [tfg.power_spectra[0, :], tfg.power_spectra[1, :]],
27+
# Test with multiple lists - list of 1d freqs & list of 1d power spectra (different f ranges)
28+
plot_spectra([tfg.freqs, tfg.freqs[:-5]],
29+
[tfg.power_spectra[0, :], tfg.power_spectra[1, :-5]],
2830
save_fig=True, file_path=TEST_PLOTS_PATH,
2931
file_name='test_plot_spectra_lists_1d.png')
3032

3133
# Test with 2d array inputs
3234
plot_spectra(np.vstack([tfg.freqs, tfg.freqs]),
3335
np.vstack([tfg.power_spectra[0, :], tfg.power_spectra[1, :]]),
34-
save_fig=True, file_path=TEST_PLOTS_PATH, file_name='test_plot_spectra_2d.png')
36+
save_fig=True, file_path=TEST_PLOTS_PATH,
37+
file_name='test_plot_spectra_2d.png')
3538

3639
# Test with labels
3740
plot_spectra(tfg.freqs, [tfg.power_spectra[0, :], tfg.power_spectra[1, :]], labels=['A', 'B'],
38-
save_fig=True, file_path=TEST_PLOTS_PATH, file_name='test_plot_spectra_labels.png')
41+
save_fig=True, file_path=TEST_PLOTS_PATH,
42+
file_name='test_plot_spectra_labels.png')
3943

4044
@plot_test
4145
def test_plot_spectra_shading(tfm, tfg, skip_if_no_mpl):

0 commit comments

Comments
 (0)