Skip to content

Commit

Permalink
fix: revise fontsize settings
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Aug 25, 2024
1 parent 23855d3 commit 40181ee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
13 changes: 9 additions & 4 deletions nireports/reportlets/modality/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,29 @@ 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,
1,
figure=figure,
wspace=0.0,
hspace=0.05,
height_ratios=[1] * (nrows - 1) + [5],
height_ratios=height_ratios,
)

grid_id = 0
Expand Down
41 changes: 31 additions & 10 deletions nireports/reportlets/nuisance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 40181ee

Please sign in to comment.