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

Plots are not drawn with matplotlib #18

Open
sylee957 opened this issue Apr 7, 2023 · 2 comments
Open

Plots are not drawn with matplotlib #18

sylee957 opened this issue Apr 7, 2023 · 2 comments

Comments

@sylee957
Copy link
Member

sylee957 commented Apr 7, 2023

I see that the matplotlib is not recognized by the default backend in plots.

image

However, pyodide has matplotlib installed, so import matplotlib prepending just works

image

I wonder if this can be appended to the templates, or sympy plot should recognize this to load matplotlib on demand. (if loading matplotlib is heavy)

@asmeurer
Copy link
Member

asmeurer commented Apr 7, 2023

Apparently running import matplotlib installs matplotlib on the fly. But somehow this doesn't happen for the import matplotlib line that happens internally in the plotting module. Ideally any import that happens internally in SymPy should also install the module if it can, because those imports represent optional dependencies which enhance SymPy's capabilities.

NumPy is the same way. If you call lambdify, it will create a function that doesn't use the NumPy backend. But if you import numpy first it uses numpy:

Screen Shot 2023-04-07 at 1 57 47 PM

@asmeurer
Copy link
Member

Another thought: basically all external imports in SymPy go through this import_module() function. So we could potentially add some code in there to automatically import things if we detect we are in SymPy Live (this could either be added directly in SymPy or monkeypatched in SymPy Live).

Although I would like to understand why this is happening first. Maybe the problem is that pyodide intercepts import statements syntatically but import_module is using __import__. If that's the case, it would be better for pyodide to hook into Python's import mechanisms directly.

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