Comments (1)
If self-building Pyodide...
Consider subclassing FigureCanvasWasm
in pyodide/packages/matplotlib/src/wasm_backend.py
and overriding the create_root_element
method to create a custom output element.
It currently reads:
# Around line 100 on Nov. 4, 2019...
def create_root_element(self):
# Designed to be overridden by subclasses for use in contexts other
# than iodide.
try:
from js import iodide
return iodide.output.element('div')
except ImportError:
return document.createElement('div')
If you do create a custom class, be sure to change the initialization code at the end of wasm_backend.py
:
# Around line 580 on 11/4/19
@_Backend.export
class _BackendWasmCoreAgg(_Backend):
FigureCanvas = FigureCanvasWasm # Change this!
FigureManager = FigureManagerWasm
@staticmethod
def show():
from matplotlib import pyplot as plt
plt.gcf().canvas.show()
If unable to modify the source...
Given the section of the source included above, it looks like defining some object, iodide
, in JavaScript that contains another object, output
, with method, element
, returning the desired element should work.
For example,
/**
* Dummy object to act like that used by Iodide.
* Only do this if you need to! Bugs related to
* the successful import of this object might
* appear!
*/
window.iodide =
{
output:
{
// Create a new element with tagName
// and add it to an element with id "root".
element: (tagName) =>
{
let elem = document.createElement(tagName);
document.querySelector("#root").appendChild(elem);
return elem;
}
}
};
from matplotlib-pyodide.
Related Issues (20)
- Custom fonts
- a better method for configuring where matplotlib figures are added to the DOM HOT 3
- Move matplotlib benchmarks to this repo
- Add tests HOT 1
- Use matplotlib figures externally HOT 1
- matplotlab chinese font messy code HOT 1
- Document some pyodide matplotlib suggestions for node and deno HOT 4
- ModuleNotFoundError: No module named 'matplotlib.backends.html5_canvas_backend' in Pyodide v0.22.0 onwards HOT 1
- Add support for plt.pause(...) HOT 3
- Upgrade build dependency to v1.x HOT 3
- AttributeError: 'TimerWasm' object has no attribute '_timer' HOT 3
- setting plt.rcParams['figure.figsize'] does not work. HOT 1
- "module://matplotlib_pyodide.wasm_backend" should auto clear the old pictures instead of generate new pictures HOT 4
- matplotlib always generates double times of output divs HOT 1
- Interactive Slider Issue: 'Figure' object has no attribute 'canvas' HOT 3
- plotting fails with `document.pyodideMplTarget` set HOT 9
- Generating the same graph multiple times with new `document.pyodideMplTarget` objects cause every 2nd graph to disappear. HOT 1
- Attempts to grab fonts from `${origin}/fonts`? HOT 5
- html5_canvas_backend no longer works. HOT 2
- wasm_backend vs. html5_canvas_backend HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matplotlib-pyodide.