Plotting error with ipympl 0.5 series
See original GitHub issueTrying to do interactive plotting with the hyperspy library, users have recently (the last two weeks) started experiencing the following bug when we try to plot after upgrading ipympl
. The following fails with %matplotlib widget
, but works with %matplotlib notebook
. (This is not testable with lab
, since the notebook backend doesn’t work there.)
Since it only started happening recently (and we didn’t update hyperspy), I believe something has changed in the recent versions of ipympl that broke it for us. If the implemented change is for the better, we would be happy to change our code, but I’m not sure what has changed.
# The following works if we replace widget with notebook
%matplotlib widget
import hyperspy.api as hs
s = hs.signals.Signal1D([1,2,3])
s.plot()
This is the expected plot:
The error is the (long) following:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-3-886abc61b753> in <module>
----> 1 s.plot()
c:\users\thomasaar\documents\github\hyperspy\hyperspy\signal.py in plot(self, navigator, axes_manager, plot_markers, **kwargs)
2158 " \"slider\", None, a Signal instance")
2159
-> 2160 self._plot.plot(**kwargs)
2161 self.events.data_changed.connect(self.update_plot, [])
2162 if self._plot.signal_plot:
c:\users\thomasaar\documents\github\hyperspy\hyperspy\drawing\mpl_he.py in plot(self, **kwargs)
174 self.pointer.connect_navigate()
175 self.plot_navigator(**kwargs.pop('navigator_kwds', {}))
--> 176 self.plot_signal(**kwargs)
177
178 def assign_pointer(self):
c:\users\thomasaar\documents\github\hyperspy\hyperspy\drawing\mpl_hse.py in plot_signal(self, **kwargs)
124
125 self.signal_plot = sf
--> 126 sf.plot(**kwargs)
127 if sf.figure is not None:
128 if self.axes_manager.navigation_axes:
c:\users\thomasaar\documents\github\hyperspy\hyperspy\drawing\signal1d.py in plot(self, data_function_kwargs, **kwargs)
135 # complains
136 pass
--> 137 self.figure.canvas.draw()
138
139 def _on_close(self):
~\.conda\envs\py5\lib\site-packages\matplotlib\backends\backend_webagg_core.py in draw(self)
149 self._png_is_old = True
150 try:
--> 151 super().draw()
152 finally:
153 self.manager.refresh_all() # Swap the frames.
~\.conda\envs\py5\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
388 self.renderer = self.get_renderer(cleared=True)
389 # Acquire a lock on the shared font cache.
--> 390 with RendererAgg.lock, \
391 (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
392 else nullcontext()):
~\.conda\envs\py5\lib\contextlib.py in __enter__(self)
111 del self.args, self.kwds, self.func
112 try:
--> 113 return next(self.gen)
114 except StopIteration:
115 raise RuntimeError("generator didn't yield") from None
~\.conda\envs\py5\lib\site-packages\matplotlib\backend_bases.py in _wait_cursor_for_draw_cm(self)
2771 if self._draw_time - last_draw_time > 1:
2772 try:
-> 2773 self.set_cursor(cursors.WAIT)
2774 yield
2775 finally:
~\.conda\envs\py5\lib\site-packages\matplotlib\backends\backend_webagg_core.py in set_cursor(self, cursor)
379 def set_cursor(self, cursor):
380 if cursor != self.cursor:
--> 381 self.canvas.send_event("cursor", cursor=cursor)
382 self.cursor = cursor
383
~\.conda\envs\py5\lib\site-packages\matplotlib\backends\backend_webagg_core.py in send_event(self, event_type, **kwargs)
344
345 def send_event(self, event_type, **kwargs):
--> 346 self.manager._send_event(event_type, **kwargs)
347
348
~\.conda\envs\py5\lib\site-packages\matplotlib\backends\backend_webagg_core.py in _send_event(self, event_type, **kwargs)
487 payload = {'type': event_type, **kwargs}
488 for s in self.web_sockets:
--> 489 s.send_json(payload)
490
491
~\.conda\envs\py5\lib\site-packages\ipympl\backend_nbagg.py in send_json(self, content)
207 if content['type'] == 'cursor':
208 cursors = ['pointer', 'default', 'crosshair', 'move']
--> 209 self._cursor = cursors[content['cursor']]
210
211 elif content['type'] == 'message':
IndexError: list index out of range
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
matplotlib ipympl does not allow cell "re-plot" ? · Issue #248
On the very first call to plt.plot there are no active figures so you are creating one implicitly, thus the figure will show...
Read more >a simple interactive matplotlib plot is not showed in jupyter ...
I try to plot interactively a simple plot through jupyterlab. ... python: 3.6.7 ipympl: 0.5.3 jupyter-lab: 2.0.1 jupyterlab-extension: 2.0.1 ...
Read more >Matplotlib pane throwing AttributeError when interactive=True
Matplotlib(fig, interactive=True).show(). I have created the conda environment via requirements: matplotlib holoviz ipympl ipywidgets-bokeh.
Read more >Installing — ipympl
ipympl provides both a Frontend (in javascript) which handles displaying the plots and handling interaction events, as well as a backend (in Python)...
Read more >How to make error bars in matplotlib python - YouTube
In this video I show you how to add error bars to a chart using ... xerror = 0.5 yerror = [yerrormin, yerrormax]...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Excellent work! Thanks @martinRenou!
I just released the Python package,
0.5.4
should be available via pip now. Coming soon via conda.