Open pyfrid opened 2 years ago
After some trial and error, it seems that problem is in the draw method. It should be draw_idle()
Hi @pyfrid,
I don't know if I would consider subclassing the Canvas
in this way to be supported. In general creating your own figures not via the pyplot
interface can be fraught, and more so when you are in an interactive context like ipympl. Instead I would recommend creating your figure via fig, ax = plt.subplots()
and then embedding the fig.canvas
(which is an ipywidget) into the applayout. See here for an example: https://matplotlib.org/ipympl/examples/full-example.html#fixing-the-double-display-with-ioff
Hi @ianhi,
Looking in the source code of the ipympl.backend, I don't see any reason, why it should not be supoorted? What should stop me to define figure instance inside the Canvas Subclass and update it when necessary? The backend class initializes FigureManager instance and Canvas for the given figure and calls display
method with few checks and connections, which I skipped in this example, but in general it is the same way. Interesting is why the draw
method doesn't work anymore?
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: