matplotlib / matplotlib/ipympl
Failed to execute 'drawImage' on 'CanvasRenderingContext2D' when Canvas instance is embedded in the ipywidgets layout
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 1.7k
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
For my project, it is required to embed Canvas from the ipympl backend in the ipywidgets Layout or AppLayout.
It worked perfectly with version 0.7.0, but with all newer versions the plot image is not rendered in the canvas with exception in Crome browser: `Error setting state: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state. `
The minimum example:
```
import numpy as np
from matplotlib.figure import Figure
from ipympl.backend_nbagg import Canvas as Canvas, FigureManager
class PlotWidget(Canvas):
__num__ = 0
def __init__(self, **kwargs):
Canvas.__init__(self, Figure(dpi=100, figsize=(6, 5.5)))
self.resizable = False
self.header_visible=False
fig = self.figure
ax = fig.add_subplot(1, 1, 1)
self.lines, = ax.plot(np.linspace(0, 1, 100), np.linspace(0, 1, 100), 'o-', markersize=2, linewidth=2)
manager = FigureManager(self, self.__num__)
self.__num__+=1
self.draw()
import ipywidgets.widgets as widgets
from ipywidgets import AppLayout, Layout
class Layout(AppLayout):
def __init__(self, **kwargs):
AppLayout.__init__(self, **kwargs)
self.center = PlotWidget(**kwargs)
if "pane_widths" not in kwargs:
self.pane_widths = [1, '650px', '0px']
if "pane_heights" not in kwargs:
self.pane_heights = ['0px', '300px', '0px']
app = Layout()
display(app)
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided minimum example using ipympl's backend_nbagg Canvas inside an ipywidgets AppLayout, and reproduce the broken-image error in Chrome. Compare behavior between version 0.7.0 and newer versions; done means the plot renders in the embedded canvas without the drawImage exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, jupyter-notebook, matplotlib, python
- Domain
- data-visualization, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100