-
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
a better method for configuring where matplotlib figures are added to the DOM #19
Comments
Thanks for opening the discussion! I 100% agree that we need some more flexibility on where to place figures.
I think it is a good idea. It would need some test and proper documentation of how to use it. Feel free to open a PR, then we can do some more discussion there. Currently, there are no devs who are actively maintaining matplotlib backend for Pyodide. So I really appreciate if you contribute to this repository. |
Happy to contribute a PR. Give me a week or so and I'll have something. |
Hey there,
I tried already:
But it did not work..... Is this possible at the moment or do we need the above mentioned adaption? - When is it ready?
|
Currently, matplotlib figures are placed in an element returned by
FigureCanvasWasm.create_root_element
. Our options for modifying this behavior are limited, and I'd like to propose something better.Current options
@personalizedrefrigerator, proposed here that we can build pyodide ourselves and subclass
FigureCanvasWasm
to get the behavior we want.@bgailleton demonstrated a monkey-patch-based approach here where he modifies
create_root_element
on aCanvas
instance. (@gzuidhof does something similar here in starboard-notebook)A better approach?
FigureCanvasWasm.create_root_element
can returnjs.document.pyodideMatplotlibPlotTarget
if it refers to a DOM element and fallback on its default behavior of creating an unattacheddiv
if that element isn't present. The code would look something like this:With this in place, clients could control where plots are rendered simply by populating
document.pyodideMatplotlibPlotTarget
. I think this is much easier than doing a custom build of pyodide and much cleaner than monkey-patching instances. If we did this, we also wouldn't need to have subclasses override the method. They could control where plots are rendered in the same way that external clients do. I'm happy to contribute a PR if we think this is a good approach.The text was updated successfully, but these errors were encountered: