diff --git a/nireports/reportlets/modality/func.py b/nireports/reportlets/modality/func.py index 7a8d324b..d264572c 100644 --- a/nireports/reportlets/modality/func.py +++ b/nireports/reportlets/modality/func.py @@ -89,16 +89,21 @@ def __init__( for sp_file in spikes_files: self.spikes.append((np.loadtxt(sp_file), None, False)) - def plot(self, figure=None, out_file=None): + def plot(self, figure=None, out_file=None, fontsize=24): """Main plotter""" - if figure is None: - figure = plt.figure(figsize=(19.2, 32)) + plt.rcParams.update({'font.size': 22}) nconfounds = len(self.confounds) nspikes = len(self.spikes) nrows = 1 + nconfounds + nspikes + # Calculate height ratios in figure points + height_ratios = [0.8] * (nconfounds + nspikes) + [10] + + if figure is None: + figure = plt.figure(figsize=(19.2, sum(height_ratios))) + # Create grid grid = GridSpec( nrows, @@ -106,7 +111,7 @@ def plot(self, figure=None, out_file=None): figure=figure, wspace=0.0, hspace=0.05, - height_ratios=[1] * (nrows - 1) + [5], + height_ratios=height_ratios, ) grid_id = 0 diff --git a/nireports/reportlets/nuisance.py b/nireports/reportlets/nuisance.py index 4e484cb8..b291ec0f 100644 --- a/nireports/reportlets/nuisance.py +++ b/nireports/reportlets/nuisance.py @@ -230,6 +230,7 @@ def plot_carpet( sort_rows="ward", drop_trs=0, legend=True, + fontsize=None, ): """ Plot an image representation of voxel intensities across time. @@ -323,7 +324,15 @@ def plot_carpet( # If subplot is not defined if subplot is None: - subplot = GridSpec(1, 1)[0] + figure, allaxes = plt.subplots(figsize=(19.2, 10)) + allaxes.spines[:].set_visible(False) + allaxes.spines[:].set_color('none') + allaxes.get_xaxis().set_visible(False) + allaxes.get_yaxis().set_visible(False) + subplot = allaxes.get_subplotspec() + fontsize = fontsize or 24 + else: + figure = plt.gcf() # Length before decimation n_trs = data.shape[-1] - drop_trs @@ -428,11 +437,22 @@ def plot_carpet( fancybox=False, ncol=min(len(segments.keys()), 5), frameon=False, - prop={"size": 8}, + prop={"size": fontsize} if fontsize else {}, + ) + + if fontsize is not None: + ax.xaxis.label.set_fontsize( + max(8, fontsize * 0.75) ) + # Change font size according to figure size + for item in ( + [ax.title, ax.yaxis.label] + + ax.get_xticklabels() + + ax.get_yticklabels() + ): + item.set_fontsize(fontsize) if output_file is not None: - figure = plt.gcf() figure.savefig(output_file, bbox_inches="tight") plt.close(figure) figure = None @@ -644,7 +664,7 @@ def confoundplot( # Set 10 frame markers in X axis interval = max((ntsteps // 10, ntsteps // 5, 1)) - xticks = list(range(0, ntsteps)[::interval]) + xticks = list(np.arange(0, ntsteps)[::interval]) ax_ts.set_xticks(xticks) if not hide_x: @@ -657,20 +677,21 @@ def confoundplot( else: ax_ts.set_xticklabels([]) + fontsize = plt.rcParams['font.size'] if name is not None: if units is not None: name += f" [{units}]" ax_ts.annotate( name, - xy=(0.0, 0.7), + xy=(0.0, 0.2), xytext=(0, 0), xycoords="axes fraction", textcoords="offset points", - va="center", + va="top", ha="left", color=color, - size=8, + size=fontsize * 0.45, bbox={ "boxstyle": "round", "fc": "w", @@ -734,14 +755,14 @@ def confoundplot( ) ax_ts.annotate( stats_label, - xy=(0.98, 0.7), + xy=(0.98, 0.1), xycoords="axes fraction", xytext=(0, 0), textcoords="offset points", - va="center", + va="top", ha="right", color=color, - size=4, + size=fontsize * 0.5, bbox={ "boxstyle": "round", "fc": "w",