jupyterlite / xeus

JupyterLite loader for Xeus kernels
https://jupyterlite-xeus.readthedocs.io
BSD 3-Clause "New" or "Revised" License
22 stars 11 forks source link

Unexpected behavior using `ipympl` called from `sympy_plot_backends`, same code works as expected using `pyodide` kernel #64

Open felixlen opened 9 months ago

felixlen commented 9 months ago

Description

With sympy_plot_backends I create an interactive plot that shows the graph of a parameter dependent function. With a slider it is possible to change the parameter value. After changing the slider value, the plot should be updated. In sympy_plot_backends interactive matplotlib is used.

With pyodide-kernel for jupyterlite this feature is working as expected. With xeus-python there is a glitch: After changing the slider value, the graph is not directly updated. As soon as I click into the drawing pane, the graph gets updated.

Reproduce

Execute the following code in a notebook:

import sympy
%matplotlib widget
import spb

x = sympy.Symbol('x', real=True)
a = sympy.Symbol('a', real=True)

f = sympy.cos(x)/(x**2 + 1)

spb.plot(
    f.subs(x, x-a),
    params = {
        a: (0, -5, 5)
    }
)

Expected behavior

The plot should update without clicking into the plot pane. With pyodide kernel it is working as expected.

Context

Xeus Python Environment file:

name: xeus-python-kernel

channels:
  - https://repo.mamba.pm/emscripten-forge
  - conda-forge

dependencies:
  - ipympl
  - matplotlib
  - numpy
  - sympy
  - sympy_plot_backends