Skip to content

Exceptions raised in matplotlib mainloop look like crashes #3922

Closed as not planned

Description

@fonnesbeck

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:

screen shot 2013-08-06 at 11 37 03 am

I have a simple example that shows this behavior here.

Activity

  1. Carreau commented on Aug 6, 2013

    @Carreau
    Member

    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.

  2. ghost assigned on Aug 6, 2013
  3. ivanov commented on Aug 6, 2013

    @ivanov
    Member

    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?

  4. minrk commented on Aug 6, 2013

    @minrk
    Member

    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.

  5. fonnesbeck commented on Aug 6, 2013

    @fonnesbeck
    Author

    @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 macosx

  6. minrk commented on Aug 6, 2013

    @minrk
    Member

    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:

    from matplotlib import dates
    import matplotlib.pyplot as plt
    
    plt.plot([0])
    plt.gca().xaxis.set_major_formatter(dates.DateFormatter('%Y/%m/%d'))
    plt.show()

    will raise ValueError: ordinal must be >= 1 on %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.

  7. hmeine commented on Oct 30, 2013

    @hmeine
    Contributor

    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.)

  8. modified the milestones: 3.0, 2.0 on Apr 2, 2014
  9. modified the milestones: 4.0, 3.0 on Nov 14, 2014
  10. modified the milestones: wishlist, 4.0 on Jun 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions