Skip to content

Conversation

@cbrnr
Copy link
Contributor

@cbrnr cbrnr commented Jul 9, 2024

Previously, the scale_factor argument only scaled the points in montage.plot(). This PR changes the behavior to also scale the channel labels.

In addition, I've changed the scale_factor so that 1 corresponds to the default size, values less than 1 scale down, and values greater than 1 scale up. I've also decreased the default point size for kind="topo" a little bit.

I've tested both kind="topo" and kind="3d", I think they both look good.

An alternative to scaling both dots and labels would be to keep the current behavior of scale_factor and add a new parameter font_size, which would allow users to change both properties independently.

@cbrnr
Copy link
Contributor Author

cbrnr commented Jul 9, 2024

import mne
mne.channels.make_standard_montage("biosemi64").plot(kind="topo", scale_factor=1)

Default old

default_old

Default new

default_new

scale_factor=0.75 new

scale_0_75_new

scale_factor=1.5 new

scale_1_50_new

scale_factor=80 old

scale_80_old

scale_factor=0.5 and kind="3d" new

scale_0_5_new_3d

@cbrnr cbrnr changed the title Scale points and labels in montage plot Scale points *and* labels in montage plot Jul 9, 2024
@cbrnr cbrnr changed the title Scale points *and* labels in montage plot Scale points and labels in montage plot Jul 9, 2024
@cbrnr cbrnr requested a review from larsoner as a code owner July 9, 2024 09:00
Copy link
Contributor Author

@cbrnr cbrnr left a comment

Choose a reason for hiding this comment

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

BTW, ideally I'd want to change scaling_factor to just scale. Do you think this is worth it?

@larsoner
Copy link
Member

larsoner commented Jul 9, 2024

BTW, ideally I'd want to change scaling_factor to just scale. Do you think this is worth it?

One problem with the current PR is that it's a pretty big change for people who used this previously. We do often change viz functions but it's usually fairly subtle, but in this case a scale_factor=40 in main probably looks okay but will look wild (40x the normal size I think?) on this PR.

One way out of this is to:

  1. leave scale_factor as it is and just document that really just sets the marker_size property of the collection essentially.
  2. add a new scale=1. that does what this PR does, and scales the marker_size, text objects, etc. by that additional amount.

That stays 100% backward compatible but allows adding the new param and behavior with a better name.

@drammock
Copy link
Member

drammock commented Jul 9, 2024

One way out of this is to:

  1. leave scale_factor as it is and just document that really just sets the marker_size property of the collection essentially.

  2. add a new scale=1. that does what this PR does, and scales the marker_size, text objects, etc. by that additional amount.

I would add:

  1. do a normal deprecation cycle on scale_factor and in the depr message encourage folks to use scale instead. If folks really need to control marker size and font size independently, we can (later) make it easy to get the handles of the various artists within the fig.mne namespace perhaps.

@cbrnr cbrnr added this to the 1.8 milestone Jul 10, 2024
@cbrnr
Copy link
Contributor Author

cbrnr commented Jul 11, 2024

The functions have the following signature:

def plot_montage(
    montage,
    scale_factor=20,
    show_names=True,
    kind="topomap",
    show=True,
    sphere=None,
    *,
    axes=None,
    verbose=None,
):

Where would you like me to insert the new scale parameter? Ideally, it would be the second parameter and completely replace the current scale_factor after deprecation, but I'm not sure how flexible we are in changing parameter positions. We already use kw-only args, but only for the last two parameters. If possible, I'd move the * to right after montage.

@cbrnr cbrnr force-pushed the plot-montage-scale branch from 68f4d21 to 45de3ed Compare July 11, 2024 09:50
@larsoner
Copy link
Member

larsoner commented Jul 11, 2024

So far we've been willing to insert * at "reasonable places" knowing that users who need to adapt code 1) will get a reasonable error message, 2) those changes are backward- and forward-compatible, and 3) any changes they need to make are pretty straightforward (i.e., switch to keyword args). In this case we'd have to move the * to the second position which is much earlier than we generally do it, but might be okay here. People who had code:

plot_montage(montage, 10, True, ...)

could arguably benefit from having to updating their code to

plot_montage(montage, scale_factor=10, show_names=True, ...)

anyway because it's not at all obvious what the args are being used for in the first instance. (Whereas for something like the Epochs constructor you can reasonably do Epochs(raw, events, event_id) and it's pretty clear what's going on.)

So I think I'm okay with having the * right after montage here

@drammock
Copy link
Member

So I think I'm okay with having the * right after montage here

agreed.

@cbrnr cbrnr force-pushed the plot-montage-scale branch from 45de3ed to c00ab27 Compare July 12, 2024 07:18
Copy link
Contributor Author

@cbrnr cbrnr left a comment

Choose a reason for hiding this comment

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

Done and ready for review.

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

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

Looks good, thanks @cbrnr ! In principle we could add a test but I'm not sure it's worth it here.

@larsoner larsoner merged commit daca2b7 into mne-tools:main Jul 12, 2024
@cbrnr cbrnr deleted the plot-montage-scale branch July 15, 2024 05:52
larsoner added a commit to scott-huberty/mne-python that referenced this pull request Jul 16, 2024
* upstream/main: (252 commits)
  Disable the "Back to top" button in the documentation (mne-tools#12688)
  DOC: match_channel_orders works on Epochs and Evoked, too (mne-tools#12699)
  Scale points and labels in montage plot (mne-tools#12703)
  Add license header to mne.stats.erp (mne-tools#12712)
  Update license year to 2024 (mne-tools#12713)
  Add standardized measurement error (SME) (mne-tools#12707)
  ENH: Parallel example execution in doc build (mne-tools#12708)
  MAINT: Update PR template (mne-tools#12692)
  MAINT: Fix doc build (mne-tools#12706)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12702)
  Improve documentation of ylim argument through Evoked plotting function (mne-tools#12697)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12696)
  BUG: Fix bug with CSP rank="full" (mne-tools#12694)
  MRG: Add epochs metadata summary to HTML representation (mne-tools#12686)
  Correct `Epochs.apply_function` docstring (mne-tools#12691)
  FIX: Gracefully handle missing datetime in Eyelink File (mne-tools#12687)
  MAINT: Restore SciPy pre (mne-tools#12689)
  Enh single channel annotation (mne-tools#12669)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12682)
  Bump autofix-ci/action from 1.2 to 1.3 in the actions group (mne-tools#12681)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants