Skip to content

Commit

Permalink
name tweak for updates to multi plot
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDonoghue committed Mar 5, 2024
1 parent 0a90f3a commit fc12bfd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ Combined
.. autosummary::
:toctree: generated/

plot_timeseries_and_spectrum
plot_timeseries_and_spectra

Utilities
---------
Expand Down
2 changes: 1 addition & 1 deletion neurodsp/plts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
from .spectral import (plot_power_spectra, plot_spectral_hist,
plot_scv, plot_scv_rs_lines, plot_scv_rs_matrix)
from .timefrequency import plot_timefrequency
from .combined import plot_timeseries_and_spectrum
from .combined import plot_timeseries_and_spectra
23 changes: 12 additions & 11 deletions neurodsp/plts/combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
###################################################################################################

@savefig
def plot_timeseries_and_spectrum(sig, fs, ts_range=None, f_range=None, times=None, start_val=0.,
spectrum_kwargs=None, ts_kwargs=None, psd_kwargs=None,
**plt_kwargs):
"""Plot a timeseries together with it's associated power spectrum.
def plot_timeseries_and_spectra(sigs, fs, ts_range=None, f_range=None, times=None, start_val=0.,
spectrum_kwargs=None, ts_kwargs=None, psd_kwargs=None,
**plt_kwargs):
"""Plot timeseries together with their associated power spectra.
Parameters
----------
sig : 1d or 2d array
sigs : 1d or 2d array
Time series to plot.
fs : float
Sampling rate, in Hz.
Expand Down Expand Up @@ -64,20 +64,21 @@ def plot_timeseries_and_spectrum(sig, fs, ts_range=None, f_range=None, times=Non
ax2 = fig.add_axes([1.5, 0.6, 0.6, 0.5])

if not times:
times = create_times(sig.shape[-1] / fs, fs, start_val=start_val)
times = create_times(sigs.shape[-1] / fs, fs, start_val=start_val)
if ts_range:
ts_kwargs = {} if ts_kwargs is None else ts_kwargs
ts_kwargs['xlim'] = ts_range

if sig.ndim == 1:
plot_time_series(times, sig, ax=ax1, **plt_kwargs,
if sigs.ndim == 1:
plot_time_series(times, sigs, ax=ax1, **plt_kwargs,
**ts_kwargs if ts_kwargs else {})
elif sig.ndim == 2:
plot_multi_time_series(times, sig, ax=ax1, **plt_kwargs,
elif sigs.ndim == 2:
plot_multi_time_series(times, sigs, ax=ax1, **plt_kwargs,
**ts_kwargs if ts_kwargs else {})
else:
raise ValueError('Only 1d or 2d inputs are supported.')

freqs, psd = compute_spectrum(sig, fs, **spectrum_kwargs if spectrum_kwargs else {})
freqs, psd = compute_spectrum(sigs, fs, **spectrum_kwargs if spectrum_kwargs else {})
if f_range:
freqs, psd = trim_spectrum(freqs, psd, f_range)
plot_power_spectra(freqs, psd, ax=ax2, **plt_kwargs,
Expand Down

0 comments on commit fc12bfd

Please sign in to comment.