From 176f64ff061136cf5628d76535a8d7e2e164d399 Mon Sep 17 00:00:00 2001 From: Shristi Baral Date: Fri, 10 Jan 2025 19:14:25 +0200 Subject: [PATCH] BUG: viz plot window's 'title' argument showed no effect. (#12828) Co-authored-by: shristi Co-authored-by: Eric Larson Co-authored-by: Daniel McCloy --- doc/changes/devel/12828.bugfix.rst | 1 + doc/changes/names.inc | 1 + mne/source_estimate.py | 7 +++++++ mne/utils/docs.py | 6 ++++++ mne/viz/_3d.py | 16 +++++++++++++--- 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 doc/changes/devel/12828.bugfix.rst diff --git a/doc/changes/devel/12828.bugfix.rst b/doc/changes/devel/12828.bugfix.rst new file mode 100644 index 00000000000..707385ac698 --- /dev/null +++ b/doc/changes/devel/12828.bugfix.rst @@ -0,0 +1 @@ +Fixed behavior of :func:`mne.viz.plot_source_estimates` where the ``title`` was not displayed properly, by :newcontrib:`Shristi Baral`. diff --git a/doc/changes/names.inc b/doc/changes/names.inc index 3dfc742b3b3..3ac0b1cd9c9 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -273,6 +273,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 diff --git a/mne/source_estimate.py b/mne/source_estimate.py index 39205e28af2..024d630535c 100644 --- a/mne/source_estimate.py +++ b/mne/source_estimate.py @@ -764,6 +764,7 @@ def plot( transparent=True, alpha=1.0, time_viewer="auto", + *, subjects_dir=None, figure=None, views="auto", @@ -2256,6 +2257,7 @@ def plot( vector_alpha=1.0, scale_factor=None, time_viewer="auto", + *, subjects_dir=None, figure=None, views="lateral", @@ -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, @@ -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, @@ -2767,6 +2771,7 @@ def plot_3d( vector_alpha=1.0, scale_factor=None, time_viewer="auto", + *, subjects_dir=None, figure=None, views="axial", @@ -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, @@ -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, diff --git a/mne/utils/docs.py b/mne/utils/docs.py index 60e02432c7b..aea0a17fd32 100644 --- a/mne/utils/docs.py +++ b/mne/utils/docs.py @@ -4656,6 +4656,12 @@ 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 window. If ``None``, 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 diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index 73f0065a58d..9c558d32a51 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -2354,6 +2354,7 @@ def plot_source_estimates( transparent=True, alpha=1.0, time_viewer="auto", + *, subjects_dir=None, figure=None, views="auto", @@ -2463,8 +2464,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 @@ -2543,6 +2543,7 @@ def plot_source_estimates( view_layout=view_layout, add_data_kwargs=add_data_kwargs, brain_kwargs=brain_kwargs, + title=title, **kwargs, ) @@ -2578,6 +2579,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 @@ -2620,7 +2622,9 @@ 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]}" + title = title if title is not None else sub_info + kwargs = { "subject": subject, "hemi": hemi, @@ -3251,6 +3255,7 @@ def plot_vector_source_estimates( vector_alpha=1.0, scale_factor=None, time_viewer="auto", + *, subjects_dir=None, figure=None, views="lateral", @@ -3262,6 +3267,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, @@ -3339,6 +3345,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 @@ -3385,6 +3394,7 @@ def plot_vector_source_estimates( cortex=cortex, foreground=foreground, size=size, + title=title, scale_factor=scale_factor, show_traces=show_traces, src=src,