-
Notifications
You must be signed in to change notification settings - Fork 10
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
Document some pyodide matplotlib suggestions for node and deno #36
Comments
Ah lol it was right there the whole time matplotlib-pyodide/matplotlib_pyodide/wasm_backend.py Lines 71 to 82 in 6a6d6fb
|
Well I wouldn't necessarily recommend this if you can avoid it. I think the technique here:
Is more efficient than base64 encoding it (though creating a bytes object may still be an unnecessary copy). It depends a bit on what you want to do with the image. Do you want to store it to the file system? |
Ahh. Yea, just trying to get the byte array into the js context. Looks like the following is how to access the buffer with import matplotlib
from matplotlib import pyplot as plt
import numpy as np
matplotlib.use('Agg')
x = np.linspace(0, 2 * np.pi, 200)
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x, y)
fig.canvas.draw()
buff = fig.canvas.get_renderer().buffer_rgba()
# For illustration
import js
js.window.buff = buff
# data is typed array view on wasm memory
# let data = window.buff.getBuffer('u8').data; Seems much better than the data URL (assuming the raw buffer is useful)! Would it be zero copies up to this point? If so that's pretty fancy |
You'll need to use |
The Node and Deno contexts can't use the
matplotlib_pyodide
backends but work fine withAgg
.Takes a second to piece together but one pattern I'm finding useful is to save the output as a
data:
url.Which seems to work! :D
Couldn't think of the right place for it but I think an example like that could be handy (even if just in this issue). Also interested in easier / more efficient patterns for sharing matplotlib figures between the python and JS contexts.
The text was updated successfully, but these errors were encountered: