From 0830bef4c1bfb78eced253bd1a05c44cb47cd633 Mon Sep 17 00:00:00 2001 From: shristi Date: Thu, 5 Sep 2024 13:10:39 +0300 Subject: [PATCH 1/3] BUG: viz plot window's 'title' argument showed no effect. Fix: if title is given, title along with subject's name will be displayed on plot window title, if title is none then subject name will be displayed as title. --- mne/viz/_3d.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index d671af626c9..14738957694 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -2365,7 +2365,7 @@ def plot_source_estimates( .. versionadded:: 0.15.0 title : str | None - Title for the figure. If None, the subject name will be used. + Title for the figure and the subject name. If None, only the subject name will be used. .. versionadded:: 0.17.0 %(show_traces)s @@ -2444,6 +2444,7 @@ def plot_source_estimates( view_layout=view_layout, add_data_kwargs=add_data_kwargs, brain_kwargs=brain_kwargs, + title=title, **kwargs, ) @@ -2479,6 +2480,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 @@ -2521,7 +2523,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}" + kwargs = { "subject": subject, "hemi": hemi, @@ -3171,6 +3178,7 @@ def plot_vector_source_estimates( view_layout="vertical", add_data_kwargs=None, brain_kwargs=None, + title=None, verbose=None, ): """Plot VectorSourceEstimate with PyVista. @@ -3288,6 +3296,7 @@ def plot_vector_source_estimates( cortex=cortex, foreground=foreground, size=size, + title=title, scale_factor=scale_factor, show_traces=show_traces, src=src, From de3cf83b7f18f8f206a57f8759417422298f86df Mon Sep 17 00:00:00 2001 From: shristi Date: Fri, 6 Sep 2024 16:55:53 +0300 Subject: [PATCH 2/3] Added: Contribution information Added: Bugfix-rst --- doc/changes/devel/12828.bugfix.rst | 1 + doc/changes/names.inc | 1 + 2 files changed, 2 insertions(+) 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 d8e33e02d3d..3e607520d20 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -270,6 +270,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 From d8e927695bf71f3d93dbe71fab983e8d3b6d56d5 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Fri, 6 Sep 2024 10:43:55 -0400 Subject: [PATCH 3/3] BUG: Fix consistency --- mne/source_estimate.py | 7 +++++++ mne/utils/docs.py | 7 +++++++ mne/viz/_3d.py | 10 +++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/mne/source_estimate.py b/mne/source_estimate.py index d719b34c9ea..99df3e4d605 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 a95b59f4b43..1cb39ecb312 100644 --- a/mne/utils/docs.py +++ b/mne/utils/docs.py @@ -4618,6 +4618,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. +""" + 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 14738957694..5e7b57b688f 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -2255,6 +2255,7 @@ def plot_source_estimates( transparent=True, alpha=1.0, time_viewer="auto", + *, subjects_dir=None, figure=None, views="auto", @@ -2364,8 +2365,7 @@ def plot_source_estimates( Defaults to 'oct6'. .. versionadded:: 0.15.0 - title : str | None - Title for the figure and the subject name. If None, only the subject name will be used. + %(title_stc)s .. versionadded:: 0.17.0 %(show_traces)s @@ -3161,6 +3161,7 @@ def plot_vector_source_estimates( vector_alpha=1.0, scale_factor=None, time_viewer="auto", + *, subjects_dir=None, figure=None, views="lateral", @@ -3172,13 +3173,13 @@ def plot_vector_source_estimates( foreground=None, initial_time=None, time_unit="s", + title=None, show_traces="auto", src=None, volume_options=1.0, view_layout="vertical", add_data_kwargs=None, brain_kwargs=None, - title=None, verbose=None, ): """Plot VectorSourceEstimate with PyVista. @@ -3250,6 +3251,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