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

BUG: viz plot window's 'title' argument showed no effect. #12828

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/devel/12828.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed behavior of :func:`mne.viz.plot_source_estimates` where the ``title`` was not displayed properly, by :newcontrib:`Shristi Baral`.
1 change: 1 addition & 0 deletions doc/changes/names.inc
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
.. _Senwen Deng: https://snwn.de
.. _Seyed Yahya Shirazi: https://neuromechanist.github.io
.. _Sheraz Khan: https://github.com/SherazKhan
.. _Shristi Baral: https://github.com/shristibaral
.. _Silvia Cotroneo: https://github.com/sfc-neuro
.. _Simeon Wong: https://github.com/dtxe
.. _Simon Kern: https://skjerns.de
Expand Down
7 changes: 7 additions & 0 deletions mne/source_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ def plot(
transparent=True,
alpha=1.0,
time_viewer="auto",
*,
subjects_dir=None,
figure=None,
views="auto",
Expand Down Expand Up @@ -2256,6 +2257,7 @@ def plot(
vector_alpha=1.0,
scale_factor=None,
time_viewer="auto",
*,
subjects_dir=None,
figure=None,
views="lateral",
Expand All @@ -2267,6 +2269,7 @@ def plot(
foreground=None,
initial_time=None,
time_unit="s",
title=None,
show_traces="auto",
src=None,
volume_options=1.0,
Expand Down Expand Up @@ -2299,6 +2302,7 @@ def plot(
foreground=foreground,
initial_time=initial_time,
time_unit=time_unit,
title=title,
show_traces=show_traces,
src=src,
volume_options=volume_options,
Expand Down Expand Up @@ -2767,6 +2771,7 @@ def plot_3d(
vector_alpha=1.0,
scale_factor=None,
time_viewer="auto",
*,
subjects_dir=None,
figure=None,
views="axial",
Expand All @@ -2778,6 +2783,7 @@ def plot_3d(
foreground=None,
initial_time=None,
time_unit="s",
title=None,
show_traces="auto",
src=None,
volume_options=1.0,
Expand Down Expand Up @@ -2810,6 +2816,7 @@ def plot_3d(
foreground=foreground,
initial_time=initial_time,
time_unit=time_unit,
title=title,
show_traces=show_traces,
src=src,
volume_options=volume_options,
Expand Down
7 changes: 7 additions & 0 deletions mne/utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4631,6 +4631,13 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):
The title of the generated figure. If ``None`` (default), no title is
displayed.
"""

docdict["title_stc"] = """
title : str | None
Title for the figure and the subject name. If None, only the subject name will be
used.
Comment on lines +4637 to +4638
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this controls window title (in the GUI titlebar), not figure title (text on the figure image itself). So this text should be clarified, and also be more clear that the passed title will be prepended to the subject name. However, see other comment below; I'm not convinced that is the right behavior.

Suggested change
Title for the figure and the subject name. If None, only the subject name will be
used.
Title for the figure; will be prepended to the subject name (separated by a comma).
If ``None``, only the subject name will be used.

"""

docdict["title_tfr_plot"] = """
title : str | 'auto' | None
Title for the plot. If ``"auto"``, will use the channel name (if ``combine`` is
Expand Down
19 changes: 16 additions & 3 deletions mne/viz/_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,7 @@ def plot_source_estimates(
transparent=True,
alpha=1.0,
time_viewer="auto",
*,
subjects_dir=None,
figure=None,
views="auto",
Expand Down Expand Up @@ -2430,8 +2431,7 @@ def plot_source_estimates(
Defaults to 'oct6'.

.. versionadded:: 0.15.0
title : str | None
Title for the figure. If None, the subject name will be used.
%(title_stc)s

.. versionadded:: 0.17.0
%(show_traces)s
Expand Down Expand Up @@ -2510,6 +2510,7 @@ def plot_source_estimates(
view_layout=view_layout,
add_data_kwargs=add_data_kwargs,
brain_kwargs=brain_kwargs,
title=title,
**kwargs,
)

Expand Down Expand Up @@ -2545,6 +2546,7 @@ def _plot_stc(
view_layout,
add_data_kwargs,
brain_kwargs,
title,
):
from ..source_estimate import _BaseVolSourceEstimate
from .backends.renderer import _get_3d_backend, get_brain_class
Expand Down Expand Up @@ -2587,7 +2589,12 @@ def _plot_stc(
if overlay_alpha == 0:
smoothing_steps = 1 # Disable smoothing to save time.

title = subject if len(hemis) > 1 else f"{subject} - {hemis[0]}"
sub_info = subject if len(hemis) > 1 else f"{subject} - {hemis[0]}"
if not title:
title = sub_info
else:
title = f"{title}, {sub_info}"
Comment on lines +2593 to +2596
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right behavior. I don't like that there is no way to prevent subject name from appearing. One concrete case where you don't want to show it: if your subject names aren't de-identified, and you want to show an STC plot in a public presentation/demo.

Most (all?) other places in our codebase, if we have some sort of default/automatic title when title=None, then passing title="whatever" would completely replace the default title. I think we should do likewise here.

Suggested change
if not title:
title = sub_info
else:
title = f"{title}, {sub_info}"
title = title if title is not None else sub_info


kwargs = {
"subject": subject,
"hemi": hemi,
Expand Down Expand Up @@ -3220,6 +3227,7 @@ def plot_vector_source_estimates(
vector_alpha=1.0,
scale_factor=None,
time_viewer="auto",
*,
subjects_dir=None,
figure=None,
views="lateral",
Expand All @@ -3231,6 +3239,7 @@ def plot_vector_source_estimates(
foreground=None,
initial_time=None,
time_unit="s",
title=None,
show_traces="auto",
src=None,
volume_options=1.0,
Expand Down Expand Up @@ -3308,6 +3317,9 @@ def plot_vector_source_estimates(
time_unit : 's' | 'ms'
Whether time is represented in seconds ("s", default) or
milliseconds ("ms").
%(title_stc)s

.. versionadded:: 1.9
%(show_traces)s
%(src_volume_options)s
%(view_layout)s
Expand Down Expand Up @@ -3354,6 +3366,7 @@ def plot_vector_source_estimates(
cortex=cortex,
foreground=foreground,
size=size,
title=title,
scale_factor=scale_factor,
show_traces=show_traces,
src=src,
Expand Down