Skip to content

Commit 682c4a2

Browse files
committed
enforce consistent xlims on time & event param plots
1 parent 34db090 commit 682c4a2

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

specparam/objs/time.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ def n_peaks_(self):
9696
if self.has_model else None
9797

9898

99+
@property
100+
def n_time_windows(self):
101+
"""How many time windows are included in the model object."""
102+
103+
return self.spectrogram.shape[1] if self.has_data else 0
104+
105+
99106
def _reset_time_results(self):
100107
"""Set, or reset, time results to be empty."""
101108

specparam/plts/event.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ def plot_event_model(event_model, **plot_kwargs):
5454
figsize=plot_kwargs.pop('figsize', [10, 4 + 4 * n_bands]))
5555
axes = cycle(axes)
5656

57+
xlim = [0, time_model.n_time_windows]
58+
5759
# 01: aperiodic params
5860
alabels = ['offset', 'knee', 'exponent'] if has_knee else ['offset', 'exponent']
5961
for alabel in alabels:
6062
plot_param_over_time_yshade(\
6163
None, event_model.event_time_results[alabel],
62-
label=alabel, drop_xticks=True, add_xlabel=False,
64+
label=alabel, drop_xticks=True, add_xlabel=False, xlim=xlim,
6365
title='Aperiodic Parameters' if alabel == 'offset' else None,
6466
color=PARAM_COLORS[alabel], ax=next(axes))
6567
next(axes).axis('off')
@@ -69,7 +71,7 @@ def plot_event_model(event_model, **plot_kwargs):
6971
for plabel in ['cf', 'pw', 'bw']:
7072
plot_param_over_time_yshade(\
7173
None, event_model.event_time_results[pe_labels[plabel][band_ind]],
72-
label=plabel.upper(), drop_xticks=True, add_xlabel=False,
74+
label=plabel.upper(), drop_xticks=True, add_xlabel=False, xlim=xlim,
7375
title='Periodic Parameters - ' + band_labels[band_ind] if plabel == 'cf' else None,
7476
color=PARAM_COLORS[plabel], ax=next(axes))
7577
next(axes).axis('off')
@@ -81,4 +83,4 @@ def plot_event_model(event_model, **plot_kwargs):
8183
drop_xticks=False if glabel == 'r_squared' else True,
8284
add_xlabel=True if glabel == 'r_squared' else False,
8385
title='Goodness of Fit' if glabel == 'error' else None,
84-
color=PARAM_COLORS[glabel], ax=next(axes))
86+
color=PARAM_COLORS[glabel], xlim=xlim, ax=next(axes))

specparam/plts/templates.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def plot_yshade(x_vals, y_vals, average='mean', shade='std', scale=1., color=Non
190190

191191
@check_dependency(plt, 'matplotlib')
192192
def plot_param_over_time(times, param, label=None, title=None, add_legend=True, add_xlabel=True,
193-
drop_xticks=False, ax=None, **plot_kwargs):
193+
xlim=None, drop_xticks=False, ax=None, **plot_kwargs):
194194
"""Plot a parameter over time.
195195
196196
Parameters
@@ -228,6 +228,9 @@ def plot_param_over_time(times, param, label=None, title=None, add_legend=True,
228228
if drop_xticks:
229229
ax.set_xticks([], [])
230230

231+
if xlim:
232+
ax.set_xlim(xlim)
233+
231234
if label and add_legend:
232235
ax.legend(loc='upper left', framealpha=plot_kwargs.pop('legend_framealpha', 0.9))
233236

specparam/plts/time.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def plot_time_model(time_model, **plot_kwargs):
5252
figsize=plot_kwargs.pop('figsize', [10, 4 + 2 * n_bands]))
5353
axes = cycle(axes)
5454

55+
xlim = [0, time_model.n_time_windows]
56+
5557
# 01: aperiodic parameters
5658
ap_params = [time_model.time_results['offset'],
5759
time_model.time_results['exponent']]
@@ -63,7 +65,7 @@ def plot_time_model(time_model, **plot_kwargs):
6365
ap_labels.insert(1, 'Knee')
6466
ap_colors.insert(1, PARAM_COLORS['knee'])
6567

66-
plot_params_over_time(None, ap_params, labels=ap_labels, add_xlabel=False,
68+
plot_params_over_time(None, ap_params, labels=ap_labels, add_xlabel=False, xlim=xlim,
6769
colors=ap_colors, title='Aperiodic Parameters', ax=next(axes))
6870

6971
# 02: periodic parameters
@@ -73,14 +75,14 @@ def plot_time_model(time_model, **plot_kwargs):
7375
[time_model.time_results[pe_labels['cf'][band_ind]],
7476
time_model.time_results[pe_labels['pw'][band_ind]],
7577
time_model.time_results[pe_labels['bw'][band_ind]]],
76-
labels=['CF', 'PW', 'BW'], add_xlabel=False,
78+
labels=['CF', 'PW', 'BW'], add_xlabel=False, xlim=xlim,
7779
colors=[PARAM_COLORS['cf'], PARAM_COLORS['pw'], PARAM_COLORS['bw']],
7880
title='Periodic Parameters - ' + band_labels[band_ind], ax=next(axes))
7981

8082
# 03: goodness of fit
8183
plot_params_over_time(None,
8284
[time_model.time_results['error'],
8385
time_model.time_results['r_squared']],
84-
labels=['Error', 'R-squared'],
86+
labels=['Error', 'R-squared'], xlim=xlim,
8587
colors=[PARAM_COLORS['error'], PARAM_COLORS['r_squared']],
8688
title='Goodness of Fit', ax=next(axes))

0 commit comments

Comments
 (0)