Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unstable behavior #42

Open
SwaggerNiels opened this issue Apr 4, 2024 · 2 comments
Open

Unstable behavior #42

SwaggerNiels opened this issue Apr 4, 2024 · 2 comments

Comments

@SwaggerNiels
Copy link

Hello,
I have recently discovered spb, and it is truely awesome, but I do not get stable results.
Sometimes my graphs shift when using multiple sliders, and every now and then when I run the my "boilerplate" function (below) in jupyter notebook in VSCode it doesn't even show at all and throws an error (below below)

from sympy import *
from spb import *
import ipywidgets

def make_widget(domain, f, vars, xlim=None, ylim=None, show=True):
    '''Makes a ipython widget with sliders for the indicated ranges'''

    return plot(
        f, domain,
        params=vars,
        xlim=xlim,
        ylim=ylim,
        show = show,
        nb_of_points=100,
        )
File [~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\spb\plot_functions\functions_2d.py:346](https://file+.vscode-resource.vscode-cdn.net/[mypath]~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/spb/plot_functions/functions_2d.py:346), in plot(*args, **kwargs)
...
--> [815](https://file+.vscode-resource.vscode-cdn.net/[mypath]/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/traitlets/traitlets.py:815)     raise TraitError(value, info or self.info(), self)
    [817](https://file+.vscode-resource.vscode-cdn.net/[mypath]~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/traitlets/traitlets.py:817) # this is the root trait
    [818](https://file+.vscode-resource.vscode-cdn.net/[mypath]~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/traitlets/traitlets.py:818) if obj is not None:

TraitError: The 'children' trait of a Box instance contains an Instance of a TypedTuple which expected a Widget, not the FigureCanvasQTAgg at '0x1fc323601f0'.
@Davide-sd
Copy link
Owner

Davide-sd commented Apr 4, 2024

Hello @SwaggerNiels , thanks for your kind words.

I assume you are using Matplotlib. I think I went pretty close to replicate your error. When a parametric-interactive plot is created with ipywidgets, it expects the matplotlib figure to be an interactive one. By running %matplotlib widget at the start of the notebook, it activates an interactive frame (a widget) wrapping a matplotlib figure, which allows interactivity. For me, it solved the problem.

However, it appears to me that the VSCode doesn't load all the necessary javascript files to make the interactive experience as good as the one offered by vanilla Jupyter Lab (or Notebook) run on the browser. For example, it doesn't show Latex labels (note the $y$ on the slider):

image

This is rendered correctly on a Jupyter Lab/Notebook run on the browser:

image

I'll keep this issue open for now, I might find some time to dig deeper into it. For now, just know that the interactive capabilities of this module are fully working on Jupyter Notebook/Lab running on a browser.

@SwaggerNiels
Copy link
Author

Indeed, I see that jupyter notebook gives me perfectly stable results.
I will use that from now on until a solution is found.

Thank you for the fast response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants