Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Fix overlapping titles for plot_matrix function #3899

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 3 additions & 12 deletions nilearn/plotting/matrix_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,9 @@ def plot_matrix(
fig.tight_layout()

if title is not None:
# Adjust the size
text_len = np.max([len(t) for t in title.split("\n")])
size = axes.bbox.size[0] / text_len
axes.text(
0.95,
0.95,
title,
horizontalalignment="right",
verticalalignment="top",
transform=axes.transAxes,
size=size,
)
axes.set_title(title, size=16)
fig.tight_layout()

return display


Expand Down
6 changes: 3 additions & 3 deletions nilearn/plotting/tests/test_matrix_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ def test_matrix_plotting_labels(mat, lab):
@pytest.mark.parametrize("title", ["foo", "foo bar", " ", None])
def test_matrix_plotting_set_title(mat, labels, title):
ax = plot_matrix(mat, labels=labels, title=title)
nb_txt = 0 if title is None else 1
assert len(ax._axes.texts) == nb_txt
nb_txt = 0 if title is None else len(title)
assert len(ax._axes.title.get_text()) == nb_txt
if title is not None:
assert ax._axes.texts[0].get_text() == title
assert ax._axes.title.get_text() == title
plt.close()


Expand Down