marimo icon indicating copy to clipboard operation
marimo copied to clipboard

mo.mpl.interactive() should not change focus when plot is rendered

Open ggggggggg opened this issue 1 year ago • 1 comments

Description

I've been working with multiple notebooks making extensive use of mo.mpl.interactive() for the the past few weeks. My workflow has been to develop code in the notebook, then refactor that code into a package, and rely on autoloading to re-run the notebook. I'm finding that the behavior of moving focus to a plot when it is rendered is quite annoying. It steals focus from the cell I'm typing in, so i just have to wait a fairly long time for all plots to render, then scroll back to find out where I was, then start typing again.

Suggested solution

The notebook should NOT shift focus to a plot when it is rendered, specifically for mo.mpl.interactive() since that is what I use. I don't know how other plots and UI elements behave, but I highly suspect they also should no shift focus when rendered (which may already be the case, I just don't know).

Alternative

Add an optional argument to disable focus shift like mo.mpl.interactive(focus_on_render=False) or a notebook wide setting like mo.mpl.set_global(focus_on_render=False).

Additional context

No response

ggggggggg avatar Aug 02 '24 18:08 ggggggggg

I'm running into this too—especially when using cmd-enter to execute code but stay in a cell, I expect to be able to start typing again almost immediately, but instead I have to use the mouse to get focus back onto the cell again.

anjiro avatar Jan 08 '25 11:01 anjiro

i found that this comes from upstream https://github.com/matplotlib/matplotlib/blob/4c345b42048811a2122ba0db68551c6ea4ddaf6a/lib/matplotlib/backends/web_backend/js/mpl.js#L338-L343

we can look into patching this or making the fix upstream

mscolnick avatar Jul 08 '25 19:07 mscolnick