tBuLi / symfit

Symbolic Fitting; fitting as it should be.
http://symfit.readthedocs.org
MIT License
233 stars 17 forks source link

Interactive guess in Jupyter notebook #255

Open egpbos opened 5 years ago

egpbos commented 5 years ago

I'm trying to use interactive guessing inside a Jupyter notebook (on macOS). I got it to work with the notebook backend, i.e. by first running

%matplotlib notebook

With the default (inline) backend it obviously doesn't work, because it isn't interactive. I also had issues with other backends, e.g. using the TkAgg backend (which was activated automatically when I run just %matplotlib without explicit argument) actually crashes the Python kernel.

One suggestion that I would have is to try to implement all this using Jupyter widgets instead of Matplotlib sliders. This would also open the door to using different plotting packages for the preview, for instance ipyvolume for 3D previews.

InteractiveGuess is also a bit poorly documented. One crucial sentence to add I think would be that you have to initialize it with the same parameters as a Fit. Currently, this is not clear.

Sorry for sounding maybe overly critical, let me just make clear that I love that interactive guessing is even available. I'm currently involved in a project where this may be necessary at some point. If that turns out to be the case, I could make a PR to work on the above mentioned issues, if you are open to that.

tBuLi commented 5 years ago

You are right in pointing out that interactive fit probably doesn't play nice with notebooks, it was designed before we really knew or cared about notebooks. Any improvements to it are very welcome, and if you have suggestions on how we could change the design are welcome. Based on what you just pointed out, perhaps InteractiveGuess should just accept a Fit object as an argument, and nothing else, to prevent the problem you mentioned?

pckroon commented 5 years ago

I (original author of the interactive guess thingy) agree with this on most points. The only problem I have with using ipywidgets everywhere is that it will then only in ipy notebooks, while now it only needs matplotlib which is still more commonly available. It would be great if we/you could separate the drawing from the logic, and create a version that works with both sliders and ipy widgets. I unfortunately don't have the time to do that. I have played around with interactive 3D plots in matplotlib, but I don't think they are necessarily easier to interpret (but play around, maybe it works for your problem).

Any way, making InteractiveGuess take a Fit sounds like a great idea by the way. Feel free to open a PR!

egpbos commented 5 years ago

Agreed, it's nice to also have it working without notebooks. Ok, if I get the time within my (quite short) project, I'll check it out, this would be somewhere in the coming month. If not, maybe some other time :) And I agree, making it take a Fit would be nicer.