Skip to content
Merged
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/12703.newfeature.rst
Original file line number Diff line number Diff line change
@@ -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`_.
6 changes: 4 additions & 2 deletions mne/channels/montage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 40 additions & 5 deletions mne/viz/montage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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