mne-python icon indicating copy to clipboard operation
mne-python copied to clipboard

Optimize head placement in viz.plot_evoked() when spatial_colors=True

Open hoechenberger opened this issue 4 years ago • 4 comments

This is what I'm seeing in one of our analyses: Screen Shot 2021-03-11 at 11 42 47

Would be great if the head could be automatically placed such that it won't overlap with the traces – maybe even in a separate subplot?

hoechenberger avatar Mar 11 '21 10:03 hoechenberger

I think we rely on matplotlib's algorithm for picking the "best" position, but I think it might only consider corners, not sides. how does it look without the GFP, does it still fail then, or does it use one of the bottom corners?

I'd like to avoid implementing our own "find the best spot for this" algorithm. I'm not wild about the separate subplot idea (because in most cases it will lead to a lot of unnecessary whitespace); I'd rather

  1. make it easier for a user to tell us where they want the head circle, or
  2. make it really easy to add it after the fact.

drammock avatar Mar 11 '21 15:03 drammock

I'd like to add a third option which is to let people tweak the plot afterward if they need to. It requires learning some stuff about matplotlib internals (axes, parasite axes, etc.) but I think if we add it to some tutorial or example it'll be discoverable enough!

larsoner avatar Oct 01 '23 17:10 larsoner

@drammock

I think we rely on matplotlib's algorithm for picking the "best" position, but I think it might only consider corners, not sides. how does it look without the GFP, does it still fail then, or does it use one of the bottom corners?

This is the logic:

def _handle_spatial_colors(...
...
    loc = 1 if psd else 2  # Legend in top right for psd plot.
    _plot_legend(pos, colors, ax, bads, outlines, loc)

jona-sassenhagen avatar Jun 02 '25 11:06 jona-sassenhagen

The dirty fix is to use ts_args for plot_joint to change the ylim

jona-sassenhagen avatar Jun 02 '25 11:06 jona-sassenhagen