Repository navigation
Closed as not planned
Description
Updated summary: any exception raised in the matplotlib mainloop, rather than during user code execution, gets handed to the default exception handler (the crash handler), and thus looks like a crash in the kernel. Affects multiple matplotlib backends and both terminal and kernel-based IPython.
I am getting a recurring problem when running Matplotlib plots in IPython notebooks in certain circumstances when the plot fails. Specifically, the failure is hidden in the notebooks, whereas it generates error messages in the IPython console. For example, the following failure:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/figure.py", line 1034, in draw
func(*args)
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/axes/_base.py", line 2056, in draw
a.draw(renderer)
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/axis.py", line 1087, in draw
ticks_to_draw = self._update_ticks(renderer)
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/axis.py", line 945, in _update_ticks
tick_tups = [t for t in self.iter_ticks()]
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/axis.py", line 893, in iter_ticks
for i, val in enumerate(majorLocs)]
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/dates.py", line 395, in __call__
dt = num2date(x, self.tz)
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/dates.py", line 329, in num2date
return _from_ordinalf(x, tz)
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg/matplotlib/dates.py", line 218, in _from_ordinalf
dt = datetime.datetime.fromordinal(ix)
ValueError: year is out of range
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@scipy.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True
Ends up looking like this in a notebook:
I have a simple example that shows this behavior here.

Activity
Carreau commentedon Aug 6, 2013
Cannot reproduce reliably the traceback in console, but I definitely saw it. The plots works on os x backend, which is weird. But it is expected not to see the plot on notebook if the png repr fails. I guess this could be problem also coupled with matplotlib.
ivanov commentedon Aug 6, 2013
I'm assigning myself to this one. Chris, is this something that used to work in the notebook and older versions of matplotlib, or new in ipython-1.0 and matplotlib 1.4.x?
minrk commentedon Aug 6, 2013
what backend are you using? I think we aren't perfect about trapping exceptions in matplotlib that may come up at times other than user execution via threads.
fonnesbeck commentedon Aug 6, 2013
@ivanov sorry for omitting that. Yes, it worked in the past, but does not now. I update my IPython every 2-4 weeks, but I'm not exactly sure when it broke.
@minrk my backend in the terminal is always
macosxminrk commentedon Aug 6, 2013
I've tracked it down, and the issue is that an exception is being raised inside the
show.mainloop()call, rather than during the execution of user code. I'm not sure if this is a matplotlib bug or not.I tested, and the behavior is the same in IPython 0.13.2 as 1.0.0, so if anything changed it was probably on matplotlib's side. It is also not restricted to the kernel model, nor the OS X backend. I can reproduce the behavior with terminal IPython and Qt backend.
There is a general question about what we should do with exceptions raised inside matplotlib's eventloop, rather than during user code execution. For instance, this script:
will raise
ValueError: ordinal must be >= 1on%run, but it will raise again inside the eventloop every time you try to resize the figure window.I think we just need a third excepthook, not for user code, that specifically displays as: "exception raised in mpl eventloop: ...", and try to ensure this is the eventloop hooked up when matplotlib is in its eventloop.
hmeine commentedon Oct 30, 2013
Issue #3791 seems to be a duplicate of this one. (Even if that one's older, this one has received more discussion.)
The problem with the notebook is even more serious in my opinion, because one does not get to see any indication of an error at all. (There's just no plot appearing.)