Skip to content

Commit 72acddc

Browse files
authored
Merge pull request #287 from fooof-tools/grep
[MNT] - Plot & report tweaks
2 parents f8ed771 + 70c20e8 commit 72acddc

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

fooof/core/reports.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def save_report_fg(fg, file_name, file_path=None, add_settings=True):
9595

9696
# Initialize figure
9797
_ = plt.figure(figsize=REPORT_FIGSIZE)
98-
grid = gridspec.GridSpec(n_rows, 2, wspace=0.4, hspace=0.25, height_ratios=height_ratios)
98+
grid = gridspec.GridSpec(n_rows, 2, wspace=0.35, hspace=0.25, height_ratios=height_ratios)
9999

100100
# First / top: text results
101101
ax0 = plt.subplot(grid[0, :])
@@ -108,15 +108,15 @@ def save_report_fg(fg, file_name, file_path=None, add_settings=True):
108108

109109
# Aperiodic parameters plot
110110
ax1 = plt.subplot(grid[1, 0])
111-
plot_fg_ap(fg, ax1)
111+
plot_fg_ap(fg, ax1, custom_styler=None)
112112

113113
# Goodness of fit plot
114114
ax2 = plt.subplot(grid[1, 1])
115-
plot_fg_gf(fg, ax2)
115+
plot_fg_gf(fg, ax2, custom_styler=None)
116116

117117
# Peak center frequencies plot
118118
ax3 = plt.subplot(grid[2, :])
119-
plot_fg_peak_cens(fg, ax3)
119+
plot_fg_peak_cens(fg, ax3, custom_styler=None)
120120

121121
# Third - Model settings
122122
if add_settings:

fooof/plts/fg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@ def plot_fg(fg, save_fig=False, file_name=None, file_path=None, **plot_kwargs):
4444
raise NoModelError("No model fit results are available, can not proceed.")
4545

4646
fig = plt.figure(figsize=plot_kwargs.pop('figsize', PLT_FIGSIZES['group']))
47-
gs = gridspec.GridSpec(2, 2, wspace=0.4, hspace=0.25, height_ratios=[1, 1.2])
47+
gs = gridspec.GridSpec(2, 2, wspace=0.35, hspace=0.35, height_ratios=[1, 1.2])
4848

4949
# Apply scatter kwargs to all subplots
5050
scatter_kwargs = plot_kwargs
5151
scatter_kwargs['all_axes'] = True
5252

5353
# Aperiodic parameters plot
5454
ax0 = plt.subplot(gs[0, 0])
55-
plot_fg_ap(fg, ax0, **scatter_kwargs)
55+
plot_fg_ap(fg, ax0, **scatter_kwargs, custom_styler=None)
5656

5757
# Goodness of fit plot
5858
ax1 = plt.subplot(gs[0, 1])
59-
plot_fg_gf(fg, ax1, **scatter_kwargs)
59+
plot_fg_gf(fg, ax1, **scatter_kwargs, custom_styler=None)
6060

6161
# Center frequencies plot
6262
ax2 = plt.subplot(gs[1, :])
63-
plot_fg_peak_cens(fg, ax2, **plot_kwargs)
63+
plot_fg_peak_cens(fg, ax2, **plot_kwargs, custom_styler=None)
6464

6565

6666
@savefig

fooof/plts/settings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
###################################################################################################
77

88
# Define default figure sizes
9-
PLT_FIGSIZES = {'spectral' : (10, 8),
9+
PLT_FIGSIZES = {'spectral' : (8.5, 6.5),
1010
'params' : (7, 6),
11-
'group' : (12, 10)}
11+
'group' : (9, 7)}
1212

1313
# Define defaults for colors for plots, based on what is plotted
1414
PLT_COLORS = {'data' : 'black',
@@ -45,8 +45,8 @@
4545

4646
## Define default values for plot aesthetics
4747
# These are all custom style arguments
48-
TITLE_FONTSIZE = 20
49-
LABEL_SIZE = 16
50-
TICK_LABELSIZE = 16
48+
TITLE_FONTSIZE = 18
49+
LABEL_SIZE = 14
50+
TICK_LABELSIZE = 12
5151
LEGEND_SIZE = 12
5252
LEGEND_LOC = 'best'

fooof/plts/style.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,14 @@ def apply_custom_style(ax, **kwargs):
169169
ax.legend(prop={'size': kwargs.pop('legend_size', LEGEND_SIZE)},
170170
loc=kwargs.pop('legend_loc', LEGEND_LOC))
171171

172-
plt.tight_layout()
172+
# Apply tight layout to the figure object, if matplotlib is new enough
173+
# If available, `.set_layout_engine` should be equivalent to
174+
# `plt.tight_layout()`, but seems to raise fewer warnings...
175+
try:
176+
fig = plt.gcf()
177+
fig.set_layout_engine('tight')
178+
except:
179+
plt.tight_layout()
173180

174181

175182
def apply_style(ax, axis_styler=apply_axis_style, line_styler=apply_line_style,
@@ -192,10 +199,10 @@ def apply_style(ax, axis_styler=apply_axis_style, line_styler=apply_line_style,
192199
Each of these sub-functions can be replaced by passing in replacement callables.
193200
"""
194201

195-
axis_styler(ax, **kwargs)
196-
line_styler(ax, **kwargs)
197-
collection_styler(ax, **kwargs)
198-
custom_styler(ax, **kwargs)
202+
axis_styler(ax, **kwargs) if axis_styler is not None else None
203+
line_styler(ax, **kwargs) if line_styler is not None else None
204+
collection_styler(ax, **kwargs) if collection_styler is not None else None
205+
custom_styler(ax, **kwargs) if custom_styler is not None else None
199206

200207

201208
def style_plot(func, *args, **kwargs):

fooof/plts/templates.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from fooof.core.modutils import safe_import, check_dependency
1212
from fooof.plts.utils import check_ax, set_alpha
13+
from fooof.plts.settings import TITLE_FONTSIZE, LABEL_SIZE, TICK_LABELSIZE
1314

1415
plt = safe_import('.pyplot', 'matplotlib')
1516

@@ -46,14 +47,14 @@ def plot_scatter_1(data, label=None, title=None, x_val=0, ax=None):
4647
ax.scatter(x_data, data, s=36, alpha=set_alpha(len(data)))
4748

4849
if label:
49-
ax.set_ylabel(label, fontsize=16)
50+
ax.set_ylabel(label, fontsize=LABEL_SIZE)
5051
ax.set(xticks=[x_val], xticklabels=[label])
5152

5253
if title:
53-
ax.set_title(title, fontsize=20)
54+
ax.set_title(title, fontsize=TITLE_FONTSIZE)
5455

55-
ax.tick_params(axis='x', labelsize=16)
56-
ax.tick_params(axis='y', labelsize=12)
56+
ax.tick_params(axis='x', labelsize=TICK_LABELSIZE)
57+
ax.tick_params(axis='y', labelsize=TICK_LABELSIZE)
5758

5859
ax.set_xlim([-0.5, 0.5])
5960

@@ -89,12 +90,12 @@ def plot_scatter_2(data_0, label_0, data_1, label_1, title=None, ax=None):
8990
plot_scatter_1(data_1, label_1, x_val=1, ax=ax1)
9091

9192
if title:
92-
ax.set_title(title, fontsize=20)
93+
ax.set_title(title, fontsize=TITLE_FONTSIZE)
9394

9495
ax.set(xlim=[-0.5, 1.5],
9596
xticks=[0, 1],
9697
xticklabels=[label_0, label_1])
97-
ax.tick_params(axis='x', labelsize=16)
98+
ax.tick_params(axis='x', labelsize=TICK_LABELSIZE)
9899

99100

100101
@check_dependency(plt, 'matplotlib')
@@ -121,13 +122,13 @@ def plot_hist(data, label, title=None, n_bins=25, x_lims=None, ax=None):
121122

122123
ax.hist(data[~np.isnan(data)], n_bins, range=x_lims, alpha=0.8)
123124

124-
ax.set_xlabel(label, fontsize=16)
125-
ax.set_ylabel('Count', fontsize=16)
125+
ax.set_xlabel(label, fontsize=LABEL_SIZE)
126+
ax.set_ylabel('Count', fontsize=LABEL_SIZE)
126127

127128
if x_lims:
128129
ax.set_xlim(x_lims)
129130

130131
if title:
131-
ax.set_title(title, fontsize=20)
132+
ax.set_title(title, fontsize=TITLE_FONTSIZE)
132133

133-
ax.tick_params(axis='both', labelsize=12)
134+
ax.tick_params(axis='both', labelsize=TICK_LABELSIZE)

0 commit comments

Comments
 (0)