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

Use matplotlib figures externally #30

Open
CesMak opened this issue Dec 11, 2022 · 1 comment
Open

Use matplotlib figures externally #30

CesMak opened this issue Dec 11, 2022 · 1 comment

Comments

@CesMak
Copy link

CesMak commented Dec 11, 2022

Hey there,
Is it possible to generate the figures including first and then use them on a static webpage without any python or matplotlib?
Including hovering over the points and zooming in?
I tried it already, I think the problem here is that the data is stored in events:
image

Thanks
Markus

@rajsite
Copy link

rajsite commented May 5, 2023

Interesting question! I don't think matplotlib has that capability built-in.

Maybe you can use a library like https://github.com/mpld3/mpld3?

The following seems to run in the pyodide console:

import matplotlib
from matplotlib import pyplot as plt
import numpy as np

matplotlib.use('Agg')

import micropip
await micropip.install("mpld3")
import mpld3

x = np.linspace(0, 2 * np.pi, 200)
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x, y)
out = mpld3.fig_to_html(fig)
out

The output is truncated in the online pyodide console, but you could save the string output in js to use

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