Skip to content

Commit

Permalink
[FIX] Fix overlapping titles for plot_matrix function (#3899)
Browse files Browse the repository at this point in the history
* Simplify add title

* [full doc] build examples

* Update test
  • Loading branch information
ymzayek committed Aug 18, 2023
1 parent 082d260 commit 058adcd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
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

0 comments on commit 058adcd

Please sign in to comment.