Skip to content

Saving .png figure failing on OSX backend #9156

Closed

Description

@dstansby

Bug report

Saving .png files is currently failing on the osx backend. I'm guessing this is due to #6603 (see the error message below)

Code for reproduction

import matplotlib
matplotlib.use('MacOSX')
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
fig.savefig('test.png')

Actual outcome

  File "test.py", line 6, in <module>
    fig.savefig('test.png')
  File "/Users/dstansby/github/matplotlib/lib/matplotlib/figure.py", line 1813, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/Users/dstansby/github/matplotlib/lib/matplotlib/backend_bases.py", line 2258, in print_figure
    **kwargs)
  File "/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_agg.py", line 507, in print_png
    FigureCanvasAgg.draw(self)
  File "/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_agg.py", line 429, in draw
    toolbar.set_cursor(cursors.WAIT)
  File "/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_macosx.py", line 188, in set_cursor
    _macosx.set_cursor(cursor)
SystemError: <built-in function set_cursor> returned NULL without setting an error

Expected outcome

Matplotlib version

  • Operating System: OSX
  • Matplotlib Version: Current master branch installed using pip
  • Python Version: 3.6.2

Activity

  1. added
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on Sep 5, 2017
  2. added this to the milestone on Sep 5, 2017
  3. jenshnielsen commented on Sep 5, 2017

    @jenshnielsen
    Member

    I can reproduce this with 2.1rc1 Agreed that this is release critical

  4. anntzer commented on Sep 5, 2017

    @anntzer
    Contributor

    The offending section is in _macosx.m at

    static PyObject*
    set_cursor(PyObject* unused, PyObject* args)
    {
        int i;
        if(!PyArg_ParseTuple(args, "i", &i)) return NULL;
        switch (i)
        { case 0: [[NSCursor pointingHandCursor] set]; break;
          case 1: [[NSCursor arrowCursor] set]; break;
          case 2: [[NSCursor crosshairCursor] set]; break;
          case 3: [[NSCursor openHandCursor] set]; break;
          default: return NULL;
        }
        Py_INCREF(Py_None);
        return Py_None;
    }
    

    which just seems to be poorly written code (indeed you need to set an exception if you're going to return NULL, see https://docs.python.org/3.6/c-api/exceptions.html#c.PyErr_SetString). In any case, cursors.WAIT is equal to 4 (see backend_tools.py) and it would seem to one only needs to add a case to the switch, but...
    https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CursorMgmt/Tasks/ChangingCursors.html

    There is no NSCursor instance for the wait cursor, because the system automatically displays it at the appropriate times.

    I guess if OSX knows better than you then we should just do nothing in that case (case 4: break;).

  5. dstansby commented on Sep 5, 2017

    @dstansby
    MemberAuthor

    Thanks @anntzer !

  6. tacaswell commented on Sep 18, 2017

    @tacaswell
    Member

    closed by #9157

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GUI: MacOSXRelease criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions