simpeg / discretize

Discretization tools for finite volume and inverse problems.
http://discretize.simpeg.xyz/
MIT License
163 stars 33 forks source link

Capture scroll #322

Closed prisae closed 1 year ago

prisae commented 1 year ago

The behaviour changed with the advent of ipympl (Lab; modern Notebook), I think. Currently the scroll over a figure makes the notebook keep scrolling, so it is hard to scroll over a slicer-image through the volume.

This PR implements the fix suggested by Matplotlib (PR 235).

codecov[bot] commented 1 year ago

Codecov Report

Merging #322 (48deb4b) into main (0f9fe1f) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #322   +/-   ##
=======================================
  Coverage   85.41%   85.41%           
=======================================
  Files          38       38           
  Lines       11420    11421    +1     
=======================================
+ Hits         9754     9755    +1     
  Misses       1666     1666           
Impacted Files Coverage Δ
discretize/mixins/mpl_mod.py 72.55% <100.00%> (+0.02%) :arrow_up:
jcapriot commented 1 year ago

Looks good to me, I'm assuming you've tested this yourself and it works well on your end too

prisae commented 1 year ago

"Have tested it" is probably a big word. It worked locally in a Python 3.11 environment, I checked with Jupyter Lab, and also that it doesn't break in IPython.

prisae commented 1 year ago

However, the fig.canvas attribute exists always, as in other parts of the code we set

fig.canvas.mpl_connect("scroll_event", tracker.onscroll)

to listen to the scroll events. So setting

self.fig.canvas.capture_scroll = True

Should always be possible, and I cannot imagine that it has any negative side effects. It was created for this reason.

Let me know if you would prefer that I do a more thorough testing.

prisae commented 1 year ago

As reference maybe also this: https://matplotlib.org/ipympl/examples/full-example.html#comprehensive-example (9th cell from the top)