<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>

<p dir="auto">Saving a plot to disk on matplotlib 2.1rc errors out on MacOS using the macosx backend.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from matplotlib import pyplot as plt
plt.plot([1, 2], [1, 2])
plt.savefig('test.png')"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</span> <span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-s1">plt</span>.<span class="pl-en">plot</span>([<span class="pl-c1">1</span>, <span class="pl-c1">2</span>], [<span class="pl-c1">1</span>, <span class="pl-c1">2</span>])
<span class="pl-s1">plt</span>.<span class="pl-en">savefig</span>(<span class="pl-s">'test.png'</span>)</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="SystemError                               Traceback (most recent call last)
&lt;ipython-input-1-5eab99386a20&gt; in &lt;module&gt;()
      1 from matplotlib import pyplot as plt
      2 plt.plot([1, 2], [1, 2])
----&gt; 3 plt.savefig('test.png')

/usr/local/lib/python3.5/site-packages/matplotlib/pyplot.py in savefig(*args, **kwargs)
    705 def savefig(*args, **kwargs):
    706     fig = gcf()
--&gt; 707     res = fig.savefig(*args, **kwargs)
    708     fig.canvas.draw_idle()   # need this if 'transparent=True' to reset colors
    709     return res

/usr/local/lib/python3.5/site-packages/matplotlib/figure.py in savefig(self, fname, **kwargs)
   1811             self.set_frameon(frameon)
   1812
-&gt; 1813         self.canvas.print_figure(fname, **kwargs)
   1814
   1815         if frameon:

/usr/local/lib/python3.5/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2256                 orientation=orientation,
   2257                 bbox_inches_restore=_bbox_inches_restore,
-&gt; 2258                 **kwargs)
   2259         finally:
   2260             if bbox_inches and restore_bbox:

/usr/local/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
    505
    506     def print_png(self, filename_or_obj, *args, **kwargs):
--&gt; 507         FigureCanvasAgg.draw(self)
    508         renderer = self.get_renderer()
    509         original_dpi = renderer.dpi

/usr/local/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    427         try:
    428             if toolbar:
--&gt; 429                 toolbar.set_cursor(cursors.WAIT)
    430             self.figure.draw(self.renderer)
    431         finally:

/usr/local/lib/python3.5/site-packages/matplotlib/backends/backend_macosx.py in set_cursor(self, cursor)
    186
    187     def set_cursor(self, cursor):
--&gt; 188         _macosx.set_cursor(cursor)
    189
    190     def save_figure(self, *args):

SystemError: &lt;built-in function set_cursor&gt; returned NULL without setting an error"><pre class="notranslate"><code class="notranslate">SystemError                               Traceback (most recent call last)
&lt;ipython-input-1-5eab99386a20&gt; in &lt;module&gt;()
      1 from matplotlib import pyplot as plt
      2 plt.plot([1, 2], [1, 2])
----&gt; 3 plt.savefig('test.png')

/usr/local/lib/python3.5/site-packages/matplotlib/pyplot.py in savefig(*args, **kwargs)
    705 def savefig(*args, **kwargs):
    706     fig = gcf()
--&gt; 707     res = fig.savefig(*args, **kwargs)
    708     fig.canvas.draw_idle()   # need this if 'transparent=True' to reset colors
    709     return res

/usr/local/lib/python3.5/site-packages/matplotlib/figure.py in savefig(self, fname, **kwargs)
   1811             self.set_frameon(frameon)
   1812
-&gt; 1813         self.canvas.print_figure(fname, **kwargs)
   1814
   1815         if frameon:

/usr/local/lib/python3.5/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2256                 orientation=orientation,
   2257                 bbox_inches_restore=_bbox_inches_restore,
-&gt; 2258                 **kwargs)
   2259         finally:
   2260             if bbox_inches and restore_bbox:

/usr/local/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
    505
    506     def print_png(self, filename_or_obj, *args, **kwargs):
--&gt; 507         FigureCanvasAgg.draw(self)
    508         renderer = self.get_renderer()
    509         original_dpi = renderer.dpi

/usr/local/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in draw(self)
    427         try:
    428             if toolbar:
--&gt; 429                 toolbar.set_cursor(cursors.WAIT)
    430             self.figure.draw(self.renderer)
    431         finally:

/usr/local/lib/python3.5/site-packages/matplotlib/backends/backend_macosx.py in set_cursor(self, cursor)
    186
    187     def set_cursor(self, cursor):
--&gt; 188         _macosx.set_cursor(cursor)
    189
    190     def save_figure(self, *args):

SystemError: &lt;built-in function set_cursor&gt; returned NULL without setting an error
</code></pre></div>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">Plot gets saved to disk without error. No error is triggered on matplotlib 2.0.2.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating System: Mac OS 10.12</li>
<li>Matplotlib Version: 2.12rc, installed using the pre-release Mac wheel on pypi.</li>
<li>Python Version: 3.5.2</li>
<li>Jupyter Version (if applicable):</li>
<li>Other Libraries:</li>
</ul>
<h3 dir="auto">Bug report</h3>
<p dir="auto">Saving <code class="notranslate">.png</code> files is currently failing on the osx backend. I'm guessing this is due to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="161012711" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/6603" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/6603/hovercard" href="https://github.com/matplotlib/matplotlib/pull/6603">#6603</a> (see the error message below)</p>

<p dir="auto"><strong>Code for reproduction</strong></p>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import matplotlib
matplotlib.use('MacOSX')
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
fig.savefig('test.png')"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>
<span class="pl-s1">matplotlib</span>.<span class="pl-en">use</span>(<span class="pl-s">'MacOSX'</span>)
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>

<span class="pl-s1">fig</span>, <span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>()
<span class="pl-s1">fig</span>.<span class="pl-en">savefig</span>(<span class="pl-s">'test.png'</span>)</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  File &quot;test.py&quot;, line 6, in &lt;module&gt;
    fig.savefig('test.png')
  File &quot;/Users/dstansby/github/matplotlib/lib/matplotlib/figure.py&quot;, line 1813, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File &quot;/Users/dstansby/github/matplotlib/lib/matplotlib/backend_bases.py&quot;, line 2258, in print_figure
    **kwargs)
  File &quot;/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_agg.py&quot;, line 507, in print_png
    FigureCanvasAgg.draw(self)
  File &quot;/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_agg.py&quot;, line 429, in draw
    toolbar.set_cursor(cursors.WAIT)
  File &quot;/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_macosx.py&quot;, line 188, in set_cursor
    _macosx.set_cursor(cursor)
SystemError: &lt;built-in function set_cursor&gt; returned NULL without setting an error"><pre class="notranslate">  <span class="pl-v">File</span> <span class="pl-s">"test.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">6</span>, <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>
    <span class="pl-s1">fig</span>.<span class="pl-en">savefig</span>(<span class="pl-s">'test.png'</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/Users/dstansby/github/matplotlib/lib/matplotlib/figure.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1813</span>, <span class="pl-s1">in</span> <span class="pl-s1">savefig</span>
    <span class="pl-s1">self</span>.<span class="pl-s1">canvas</span>.<span class="pl-en">print_figure</span>(<span class="pl-s1">fname</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/Users/dstansby/github/matplotlib/lib/matplotlib/backend_bases.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">2258</span>, <span class="pl-s1">in</span> <span class="pl-s1">print_figure</span>
    <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_agg.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">507</span>, <span class="pl-s1">in</span> <span class="pl-s1">print_png</span>
    <span class="pl-v">FigureCanvasAgg</span>.<span class="pl-en">draw</span>(<span class="pl-s1">self</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_agg.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">429</span>, <span class="pl-s1">in</span> <span class="pl-s1">draw</span>
    <span class="pl-s1">toolbar</span>.<span class="pl-en">set_cursor</span>(<span class="pl-s1">cursors</span>.<span class="pl-v">WAIT</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_macosx.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">188</span>, <span class="pl-s1">in</span> <span class="pl-s1">set_cursor</span>
    <span class="pl-s1">_macosx</span>.<span class="pl-en">set_cursor</span>(<span class="pl-s1">cursor</span>)
<span class="pl-v">SystemError</span>: <span class="pl-c1">&lt;</span><span class="pl-s1">built</span><span class="pl-c1">-</span><span class="pl-s1">in</span> <span class="pl-s1">function</span> <span class="pl-s1">set_cursor</span><span class="pl-c1">&gt;</span> <span class="pl-s1">returned</span> <span class="pl-v">NULL</span> <span class="pl-s1">without</span> <span class="pl-s1">setting</span> <span class="pl-s1">an</span> <span class="pl-s1">error</span></pre></div>
<p dir="auto"><strong>Expected outcome</strong></p>


<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating System: OSX</li>
<li>Matplotlib Version: Current master branch installed using pip</li>
<li>Python Version: 3.6.2</li>
</ul>