diff --git a/doc/changes/devel/12703.newfeature.rst b/doc/changes/devel/12703.newfeature.rst new file mode 100644 index 00000000000..0c6afa4468b --- /dev/null +++ b/doc/changes/devel/12703.newfeature.rst @@ -0,0 +1 @@ +Montage plots created with :meth:`~mne.channels.DigMontage.plot` now scale both the channel dots *and* channel names with the new ``scale`` parameter. The default is ``scale=1`` (factors less than 1 will scale down, whereas factors greater than 1 will scale up). The previous ``scale_factor`` parameter only affected marker size, and this parameter is now deprecated. By `Clemens Brunner`_. \ No newline at end of file diff --git a/mne/channels/montage.py b/mne/channels/montage.py index ea6d7ba92be..8ebbce0cfc0 100644 --- a/mne/channels/montage.py +++ b/mne/channels/montage.py @@ -369,17 +369,19 @@ def __repr__(self): @copy_function_doc_to_method_doc(plot_montage) def plot( self, - scale_factor=20, + *, + scale=None, + scale_factor=None, show_names=True, kind="topomap", show=True, sphere=None, - *, axes=None, verbose=None, ): return plot_montage( self, + scale=scale, scale_factor=scale_factor, show_names=show_names, kind=kind, diff --git a/mne/viz/montage.py b/mne/viz/montage.py index 935a306e0d9..4e45ac0a513 100644 --- a/mne/viz/montage.py +++ b/mne/viz/montage.py @@ -16,12 +16,13 @@ @verbose def plot_montage( montage, - scale_factor=20, + *, + scale=None, + scale_factor=None, show_names=True, kind="topomap", show=True, sphere=None, - *, axes=None, verbose=None, ): @@ -31,8 +32,11 @@ def plot_montage( ---------- montage : instance of DigMontage The montage to visualize. + scale : float + Determines the scale of the channel points and labels; values < 1 will scale + down, whereas values > 1 will scale up. Default to None, which implies 1. scale_factor : float - Determines the size of the points. + Determines the size of the points. Deprecated, use scale instead. show_names : bool | list Whether to display all channel names. If a list, only the channel names in the list are shown. Defaults to True. @@ -51,8 +55,20 @@ def plot_montage( fig : instance of matplotlib.figure.Figure The figure object. """ + import matplotlib.pyplot as plt + from ..channels import DigMontage, make_dig_montage + if scale_factor is not None: + msg = "scale_factor has been deprecated and will be removed. Use scale instead." + if scale is not None: + raise ValueError( + " ".join(["scale and scale_factor cannot be used together.", msg]) + ) + logger.info(msg) + if scale is None: + scale = 1 + _check_option("kind", kind, ["topomap", "3d"]) _validate_type(montage, DigMontage, item_name="montage") ch_names = montage.ch_names @@ -93,6 +109,25 @@ def plot_montage( sphere=sphere, axes=axes, ) - collection = fig.axes[0].collections[0] - collection.set_sizes([scale_factor]) + + if scale_factor is not None: + # scale points + collection = fig.axes[0].collections[0] + collection.set_sizes([scale_factor]) + elif scale is not None: + # scale points + collection = fig.axes[0].collections[0] + collection.set_sizes([scale * 10]) + + # scale labels + labels = fig.findobj(match=plt.Text) + x_label, y_label = fig.axes[0].xaxis.label, fig.axes[0].yaxis.label + z_label = fig.axes[0].zaxis.label if kind == "3d" else None + tick_labels = fig.axes[0].get_xticklabels() + fig.axes[0].get_yticklabels() + if kind == "3d": + tick_labels += fig.axes[0].get_zticklabels() + for label in labels: + if label not in [x_label, y_label, z_label] + tick_labels: + label.set_fontsize(label.get_fontsize() * scale) + return fig