physiopy / prep4phys

A toolbox for physiological peak detection analyses. Formerly peakdet.
Apache License 2.0
1 stars 2 forks source link

Using `edit_physio()` in Spyder breaks console after closing interactive plot session and jupyter is also not working. #13

Open smoia opened 4 years ago

smoia commented 4 years ago

This happens in Spyder 4 (didn't test on previous Spyder versions), in Ubuntu 18.04 and latest winpython. If we can figure out why, it would be great - starting with trying to reproduce the problem in different environments @physiopy/all .

smoia commented 4 years ago

Update: it seems it's a problem related to the Qt4Agg and Qt5Agg backends in Spyder. Using the same backend from a python console (e.g. IPython) doesn't raise any issue. @rmarkello, which backend were you using when you were coding peakdet?

rmarkello commented 4 years ago

Oh jeez, that's a tough question... I was almost certainly using one of those you listed: likely originally Qt4Agg and then later Qt5Agg. I know that Spyder has a lot of confirmed graphical compatibility issues (e.g., I know it has bugs with the tqdm module). Note that I have never used Spyder myself, so all development was done in Python/IPython, exclusively.

smoia commented 4 years ago

Ok, that's good to know! Out of curiosity, did you also test it in a jupyter notebook? Does it work without issues? I guess that then we can just add a warning in the documentation saying not to use it in Spyder...

sangfrois commented 4 years ago

@smoia : I tested it in a jupyter notebook yesterday! that's a funny coincidence. I was thinking of posting something here to cover the issue.

At first I thought it may be a %pylab inline or %matplotlib inline confusion, but then I realized the issue was too complex for me to describe properly. Here I am : it doesn't work in jupyter.

smoia commented 4 years ago

Mmm, like this it might be a bit difficult to "debug", but I'd say the first thing we can do is to write in the readme and in the documentation that we don't guarantee that the interactive plot session works in Spyder or Jupyter notebook. Sounds good?

sangfrois commented 4 years ago

Sounds right yeah. Pin me if you think you'd need me to send a PR

smoia commented 4 years ago

Sure! Why don't you go on and open a PR?

rmarkello commented 4 years ago

@sangfrois @smoia: you will likely need to install ipympl and enable it with %matplotlib widget for use of peakdet in Jupyter notebooks! That is, loss of interactivity in maptlotlib plots is a standard feature of Jupyter notebooks and is not just peakdet specific. (That's not to say peakdet will 100% work with this solution, but it definitely won't work without it.)

(Also to explicitly answer @smoia's previous question: no, I had never tried testing in Jupyter!)

smoia commented 4 years ago

Ah, nice! @sangfrois care to try it out? If it works we can add ipympl as an extra dependency!

sangfrois commented 4 years ago

i think I've tried, but let me give it a shot again! I'll pin you once I'm done!

sangfrois commented 4 years ago

Ok, so : I've tried installing ipympl and executing %matplotlib widget to get the interactive plot (using operation.edit_physio(data)) and only got that string.

<matplotlib.axes._subplots.AxesSubplot at 0x1f3b07b9470>

Something seems to be processed here, so I've double checked with %matplotlib inline and got a static figure.

Assuming that the string output meant there was a plot object, I've tried to call plt.show() and got nothing 😢

Everything works fine in my terminal though. Even got the chance to try out the GUI. Looks great 😁

Here @smoia @rmarkello is there any other little tests you'd want me to try out?

smoia commented 4 years ago

New question: does the library need OpenGL?

rmarkello commented 3 years ago

@smoia: I'm not sure! I want to say no, probably not, but did very limited testing on this whole thing 😅 Sorry to not be of more help here.

me-pic commented 2 weeks ago

Revisiting that issue: The interactive plot is working for me in jupyter notebook when I specified either %matplotlib widget or %matplotlib ipympl. I can delete and add peaks. However, the deleted/added peaks do not appear afterward in the history of the Physio object...

smoia commented 2 weeks ago

Did you try to close the widget with ctrl+q as per documentation?

me-pic commented 2 weeks ago

Yes. It seems to close the plot since after doing ctrl+q I can't interact with it. However, if I delete some peaks, nor the peaks when I call peaks on the object nor the history are updated..

smoia commented 2 weeks ago

See: https://github.com/matplotlib/matplotlib/issues/13302

me-pic commented 2 weeks ago

Update: it works when using %matplotlib qt:

So I would suggest to just add a note in the doc to make it clear