ipympl
ipympl copied to clipboard
RuntimeError: libpng signaled error
Sometimes I am getting this error with the trunk version. Not sure what a MWE would be. Has anyone encountered this? Thanks, Chaffra
RuntimeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/ipympl/backend_nbagg.py in _handle_message(self, object, content, buffers)
178 self.manager.resize(w, h)
179 else:
--> 180 self.manager.handle_json(content)
181
182 def send_json(self, content):
/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_webagg_core.py in handle_json(self, content)
437
438 def handle_json(self, content):
--> 439 self.canvas.handle_event(content)
440
441 def refresh_all(self):
/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_webagg_core.py in handle_event(self, event)
238 handler = getattr(self, 'handle_{0}'.format(e_type),
239 self.handle_unknown_event)
--> 240 return handler(event)
241
242 def handle_unknown_event(self, event):
/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_webagg_core.py in handle_draw(self, event)
254
255 def handle_draw(self, event):
--> 256 self.draw()
257
258 def _handle_mouse(self, event):
/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_webagg_core.py in draw(self)
151 super().draw()
152 finally:
--> 153 self.manager.refresh_all() # Swap the frames.
154
155 def draw_idle(self):
/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_webagg_core.py in refresh_all(self)
441 def refresh_all(self):
442 if self.web_sockets:
--> 443 diff = self.canvas.get_diff_image()
444 if diff is not None:
445 for s in self.web_sockets:
/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_webagg_core.py in get_diff_image(self)
199 buff = _png.write_png(
200 output.view(dtype=np.uint8).reshape(output.shape + (4,)),
--> 201 None, compression=6, filter=_png.PNG_FILTER_NONE)
202
203 # Swap the renderer frames
RuntimeError: libpng signaled error
When are you getting the error? During %matplotlib widget, after a plot call or in a different context?
I am getting it with %matplotlib widget after a plot call when using the latest version 0.3.3. When I switch back to 0.2.1 it works.
I also get this regularly with 0.3.3
This may be a useful screenshot:

it seems when this happens, the canvas' get_width_height() returns (0, 0).
My workaround for now is:
fig_mag = plt.figure()
fig_mag.canvas.layout.min_width = '200px'
fig_mag.canvas.layout.min_height = '200px'
I ran into the same issue with 0.3.3. What I notices as well, is that this happens when going to full screen in my browser (FF68 on win10). When in full screen I can crash the cell that first created the plot by moving the mouse to show the browser toolbar, changing the screen size. The error looks the same as above.
In this case setting a min_height and width does not work unfortunately.
I'll try to take time this week to have a look at this issue, it seems pretty bad.
I have the same error
File "C:\Users\exaud\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 532, in print_png
self.figure.dpi, metadata=metadata)
**RuntimeError: libpng signaled error**
**<Figure size 864x0 with 0 `Axes>**
can anyone help me here?
I also run into this error somewhat frequently. Not sure exactly but it mostly happens when I have a lot of figures open (>20), I do a lot of window (and thereby figure) resizing and then especially if I on top of all that open a second view of the same notebook.
I use python 3.6, jupyter lab 1.2.3, not sure where to find the version of jupyter-matplotlib I'm using.
Full traceback:
--
ValueError Traceback (most recent call last)
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in draw(self)
150 try:
--> 151 super().draw()
152 finally:
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
387 with RendererAgg.lock:
--> 388 self.figure.draw(self.renderer)
389 # A GUI class may be need to update a window using this draw, so
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
37
---> 38 return draw(artist, renderer, *args, **kwargs)
39 finally:
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1708 mimage._draw_list_compositing_images(
-> 1709 renderer, self, artists, self.suppressComposite)
1710
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
134 for a in artists:
--> 135 a.draw(renderer)
136 else:
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
37
---> 38 return draw(artist, renderer, *args, **kwargs)
39 finally:
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2646
-> 2647 mimage._draw_list_compositing_images(renderer, self, artists)
2648
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
134 for a in artists:
--> 135 a.draw(renderer)
136 else:
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
37
---> 38 return draw(artist, renderer, *args, **kwargs)
39 finally:
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\axis.py in draw(self, renderer, *args, **kwargs)
1202
-> 1203 ticks_to_draw = self._update_ticks()
1204 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\axis.py in _update_ticks(self)
1078 """
-> 1079 major_locs = self.get_majorticklocs()
1080 major_labels = self.major.formatter.format_ticks(major_locs)
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\axis.py in get_majorticklocs(self)
1323 """Get the array of major tick locations in data coordinates."""
-> 1324 return self.major.locator()
1325
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\ticker.py in __call__(self)
2077 vmin, vmax = self.axis.get_view_interval()
-> 2078 return self.tick_values(vmin, vmax)
2079
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\ticker.py in tick_values(self, vmin, vmax)
2085 vmin, vmax, expander=1e-13, tiny=1e-14)
-> 2086 locs = self._raw_ticks(vmin, vmax)
2087
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\ticker.py in _raw_ticks(self, vmin, vmax)
2024 if self.axis is not None:
-> 2025 nbins = np.clip(self.axis.get_tick_space(),
2026 max(1, self._min_n_ticks - 1), 9)
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\axis.py in get_tick_space(self)
2186 if size > 0:
-> 2187 return int(np.floor(length / size))
2188 else:
ValueError: cannot convert float NaN to integer
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
~\Miniconda3\envs\py36_main\lib\site-packages\ipympl\backend_nbagg.py in _handle_message(self, object, content, buffers)
178 self.manager.resize(w, h)
179 else:
--> 180 self.manager.handle_json(content)
181
182 def send_json(self, content):
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in handle_json(self, content)
437
438 def handle_json(self, content):
--> 439 self.canvas.handle_event(content)
440
441 def refresh_all(self):
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in handle_event(self, event)
238 handler = getattr(self, 'handle_{0}'.format(e_type),
239 self.handle_unknown_event)
--> 240 return handler(event)
241
242 def handle_unknown_event(self, event):
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in handle_draw(self, event)
254
255 def handle_draw(self, event):
--> 256 self.draw()
257
258 def _handle_mouse(self, event):
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in draw(self)
151 super().draw()
152 finally:
--> 153 self.manager.refresh_all() # Swap the frames.
154
155 def draw_idle(self):
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in refresh_all(self)
441 def refresh_all(self):
442 if self.web_sockets:
--> 443 diff = self.canvas.get_diff_image()
444 if diff is not None:
445 for s in self.web_sockets:
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in get_diff_image(self)
199 buff = _png.write_png(
200 output.view(dtype=np.uint8).reshape(output.shape + (4,)),
--> 201 None, compression=6, filter=_png.PNG_FILTER_NONE)
202
203 # Swap the renderer frames
RuntimeError: libpng signaled error
We have had issues with Matplotlib before when the figure size is pushed to 0 in one or both directions (because that is not a super useful use case it does not get a lot of exercise).
ipympl should probably not be setting the figure size to 0, but the core library should do better about failing a bit more gracefully.
I now found a way to reproduce this error, although different traceback:
In a notebook in Jupyter Lab:
%matplotlib widget
import matplotlib.pyplot as plt
plt.figure()
plt.plot(range(10))
Then, from the file browser panel, open a .png file, zoom out with ctrl + mousewheel, use ctrl + 0 to zoom back in, close the tab to return to the notebook and I get this error:
RuntimeError Traceback (most recent call last)
~\Miniconda3\envs\py36_main\lib\site-packages\ipympl\backend_nbagg.py in _handle_message(self, object, content, buffers)
178 self.manager.resize(w, h)
179 else:
--> 180 self.manager.handle_json(content)
181
182 def send_json(self, content):
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in handle_json(self, content)
437
438 def handle_json(self, content):
--> 439 self.canvas.handle_event(content)
440
441 def refresh_all(self):
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in handle_event(self, event)
238 handler = getattr(self, 'handle_{0}'.format(e_type),
239 self.handle_unknown_event)
--> 240 return handler(event)
241
242 def handle_unknown_event(self, event):
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in handle_draw(self, event)
254
255 def handle_draw(self, event):
--> 256 self.draw()
257
258 def _handle_mouse(self, event):
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in draw(self)
151 super().draw()
152 finally:
--> 153 self.manager.refresh_all() # Swap the frames.
154
155 def draw_idle(self):
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in refresh_all(self)
441 def refresh_all(self):
442 if self.web_sockets:
--> 443 diff = self.canvas.get_diff_image()
444 if diff is not None:
445 for s in self.web_sockets:
~\Miniconda3\envs\py36_main\lib\site-packages\matplotlib\backends\backend_webagg_core.py in get_diff_image(self)
199 buff = _png.write_png(
200 output.view(dtype=np.uint8).reshape(output.shape + (4,)),
--> 201 None, compression=6, filter=_png.PNG_FILTER_NONE)
202
203 # Swap the renderer frames
RuntimeError: libpng signaled error
@martinRenou I think we have to use the same trick as in bqplot, where we return a promise in the render only when attached to the DOM, that will make it have a size right? Although in theory a DOM element could have a size of 0x0 I think, so what @tacaswell says still applies.
I noticed, with conda on win10, this error occurs when viewing a plot in multiple tabs of a tab widget. As long as a hidden/nonselected tab contains a plot, I get the libpng error. However, if I use a virtualenv (no conda) on win10 it works fine, as does conda in docker (scipy-notebook:latest) on win10. Versions of ipykernel, widgets and ipympl are always the same (5.1.3, 7.5.1 and 0.4.0, respectively).
I wouldn't mind looking into this issue, as it is somewhat breaking for me, but I would need some help getting started.
@freethebee The version of Matplotlib in probably the critical difference between the two envs.
In all cases it is 3.1.2, (the conda packages are from conda-forge).
any updates on this?