Skip to content

Commit

Permalink
tweak times related inputs to plot_combined
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDonoghue committed Feb 20, 2024
1 parent b551ef1 commit 0189891
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions neurodsp/plts/combined.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
###################################################################################################

@savefig
def plot_timeseries_and_spectrum(sig, fs, ts_range=None, f_range=None, spectrum_kwargs=None,
start_val=0., ts_kwargs=None, psd_kwargs=None, **plt_kwargs):
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.
Parameters
Expand All @@ -26,12 +27,15 @@ def plot_timeseries_and_spectrum(sig, fs, ts_range=None, f_range=None, spectrum_
For visualization only - the power spectrum is computed over the entire time series.
f_range : list of [float, float], optional
The frequency range to restrict the power spectrum to.
times : 1d, optional
Time definition for the time series to be plotted.
If not provided, times are recomputed from signal length and sampling rate.
start_val : float, optional, default: 0.
The starting value for the time definition for the time series.
Only used if `times` is not provided.
spectrum_kwargs : dict, optional
Keyword arguments for computing the power spectrum.
See `compute_spectrum` for details.
start_val : float, optional
The starting value for the time definition for the time series.
If not provided, defaults to zero.
ts_kwargs : dict, optional
Keyword arguments for customizing the time series plot.
psd_kwargs : dict, optional
Expand Down Expand Up @@ -59,9 +63,10 @@ def plot_timeseries_and_spectrum(sig, fs, ts_range=None, f_range=None, spectrum_
ax1 = fig.add_axes([0.0, 0.6, 1.3, 0.5])
ax2 = fig.add_axes([1.5, 0.6, 0.6, 0.5])

if not times:
times = create_times(len(sig) / fs, fs, start_val=start_val)
if ts_range:
ts_kwargs['xlim'] = ts_range
times = create_times(len(sig) / fs, fs, start_val=start_val)
plot_time_series(times, sig, ax=ax1, **plt_kwargs,
**ts_kwargs if ts_kwargs else {})

Expand Down

0 comments on commit 0189891

Please sign in to comment.