Skip to content

Commit 70c20e8

Browse files
committed
tweak tight layout application for mpl version
1 parent 8d2fd25 commit 70c20e8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

fooof/plts/style.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +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-
# Apply tight layout to the figure object
173-
# This should be equivalent to `plt.tight_layout()`, but seems to raise fewer warnings...
174-
fig = plt.gcf()
175-
fig.set_layout_engine('tight')
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()
176180

177181

178182
def apply_style(ax, axis_styler=apply_axis_style, line_styler=apply_line_style,

0 commit comments

Comments
 (0)