title: Matplotlib "ValueError: width and height must each be below 32768" in IPython Notebook
body: <p>I'm working through some examples out of "Python For Data Analysis", and am attempting to make a simple plot using the following script inline in an IPython notebook:</p>
  
  <pre class="lang-py prettyprint-override"><code>%matplotlib
  %pdb
  from datetime import datetime
  import pandas as pd
  import matplotlib.pyplot as plt
  
  fig = plt.figure()
  ax = fig.add_subplot(1,1,1)
  
  data = pd.read_csv("ch08/spx.csv", index_col=0, parse_dates=True)
  spx = data['SPX']
  ax.plot(spx, 'k-')
  
  crisis_data = [
      (datetime(2007, 10, 11), 'Peak of bull market'),
      (datetime(2008, 3, 12), 'Bear Stearns Fails'),
      (datetime(2008, 9, 15), 'Lehman Bankruptcy')
  ]
  
  for date, label in crisis_data:
      ax.annotate(label, 
                  xy=(date, spx.asof(date) + 50),
                  xytext=(date, spx.asof(date) + 200),
                  arrowprops=dict(facecolor='black'),
                  horizontalalignment='left',
                  verticalalignment='top')
  
  ax.set_title('Important dates in 2008-2009 financial crisis')
  fig
  </code></pre>
  
  <p>Where spx.csv has about 5500 line of data that look like this:</p>
  
  <pre><code>,SPX
  1990-02-01 00:00:00,328.79
  1990-02-02 00:00:00,330.92
  1990-02-05 00:00:00,331.85
  1990-02-06 00:00:00,329.66
  1990-02-07 00:00:00,333.75
  1990-02-08 00:00:00,332.96
  1990-02-09 00:00:00,333.62
  1990-02-12 00:00:00,330.08
  1990-02-13 00:00:00,331.02
  1990-02-14 00:00:00,332.01
  1990-02-15 00:00:00,334.89
  1990-02-16 00:00:00,332.72
  1990-02-20 00:00:00,327.99
  1990-02-21 00:00:00,327.67
  1990-02-22 00:00:00,325.7
  1990-02-23 00:00:00,324.15
  1990-02-26 00:00:00,328.67
  1990-02-27 00:00:00,330.26
  1990-02-28 00:00:00,331.89
  1990-03-01 00:00:00,332.74
  </code></pre>
  
  <p>The <code>ax.plot(spec, 'k-')</code> portion plots without issue, but when I try to plot again after the loop and after setting the title, I get the following error:</p>
  
  <pre class="lang-py prettyprint-override"><code>Using matplotlib backend: MacOSX
  Automatic pdb calling has been turned OFF
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  /Users/B/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
      333                 pass
      334             else:
  --&gt; 335                 return printer(obj)
      336             # Finally look for special method names
      337             method = _safe_get_formatter_method(obj, self.print_method)
  
  /Users/B/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in &lt;lambda&gt;(fig)
      205 
      206     if 'png' in formats:
  --&gt; 207         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
      208     if 'retina' in formats or 'png2x' in formats:
      209         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
  
  /Users/B/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)
      115 
      116     bytes_io = BytesIO()
  --&gt; 117     fig.canvas.print_figure(bytes_io, **kw)
      118     data = bytes_io.getvalue()
      119     if fmt == 'svg':
  
  /Users/B/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
     2192                 orientation=orientation,
     2193                 bbox_inches_restore=_bbox_inches_restore,
  -&gt; 2194                 **kwargs)
     2195         finally:
     2196             if bbox_inches and restore_bbox:
  
  /Users/B/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
      519 
      520     def print_png(self, filename_or_obj, *args, **kwargs):
  --&gt; 521         FigureCanvasAgg.draw(self)
      522         renderer = self.get_renderer()
      523         original_dpi = renderer.dpi
  
  /Users/B/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in draw(self)
      462         if __debug__: verbose.report('FigureCanvasAgg.draw', 'debug-annoying')
      463 
  --&gt; 464         self.renderer = self.get_renderer(cleared=True)
      465         # acquire a lock on the shared font cache
      466         RendererAgg.lock.acquire()
  
  /Users/B/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in get_renderer(self, cleared)
      479 
      480         if need_new_renderer:
  --&gt; 481             self.renderer = RendererAgg(w, h, self.figure.dpi)
      482             self._lastKey = key
      483         elif cleared:
  
  /Users/B/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in __init__(self, width, height, dpi)
       92         self.height = height
       93         if __debug__: verbose.report('RendererAgg.__init__ width=%s, height=%s'%(width, height), 'debug-annoying')
  ---&gt; 94         self._renderer = _RendererAgg(int(width), int(height), dpi, debug=False)
       95         self._filter_renderers = []
       96 
  
  ValueError: width and height must each be below 32768
  </code></pre>
  
  <p>Debugging, it looks like the value of <code>width</code> is 733431.53993055562 for some reason. I've tried manually setting the figure width by initiating the figure with <code>figsize=(3,4)</code>, and with <code>set_size_inches</code> but the result is the same.</p>
  
  <p>I've also found this old bug report of the same issue but it never seems to have been resolved: <a href="https://github.com/ipython/ipython/issues/1740" rel="nofollow">https://github.com/ipython/ipython/issues/1740</a></p>
  
  <p>Any idea how to fix this issue?</p>